Skip to content

YQ-4114 fixed pragmas for CTAS #14604

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Feb 17, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions ydb/core/kqp/host/kqp_statement_rewrite.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -278,7 +278,9 @@ namespace {
create = exprCtx.ReplaceNode(std::move(create), *tableNameNode, exprCtx.NewAtom(pos, tmpTableName));
}

const auto topLevelRead = NYql::FindTopLevelRead(insertData.Ptr());
NYql::TNodeOnNodeOwnedMap deepClones;
auto insertDataCopy = exprCtx.DeepCopy(insertData.Ref(), exprCtx, deepClones, false, false);
const auto topLevelRead = NYql::FindTopLevelRead(insertDataCopy);

NYql::TExprNode::TListType insertSettings;
insertSettings.push_back(
Expand All @@ -305,7 +307,7 @@ namespace {
}),
}),
}),
insertData.Ptr(),
insertDataCopy,
exprCtx.NewList(pos, std::move(insertSettings)),
});

Expand Down
63 changes: 63 additions & 0 deletions ydb/core/kqp/ut/federated_query/s3/kqp_s3_plan_ut.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,69 @@ Y_UNIT_TEST_SUITE(KqpS3PlanTest) {
UNIT_ASSERT_VALUES_EQUAL(sourceOp["ReadColumns"].GetArraySafe()[0].GetStringSafe(), "key");
UNIT_ASSERT_VALUES_EQUAL(sourceOp["ReadColumns"].GetArraySafe()[1].GetStringSafe(), "value");
}

Y_UNIT_TEST(S3CreateTableAsSelect) {
{
Aws::S3::S3Client s3Client = MakeS3Client();
CreateBucketWithObject("test_ctas_read", "test_ctas_read1", TEST_CONTENT, s3Client);
UploadObject("test_ctas_read", "test_ctas_read2", TEST_CONTENT, s3Client);
}

auto kikimr = NTestUtils::MakeKikimrRunner();

auto tc = kikimr->GetTableClient();
auto session = tc.CreateSession().GetValueSync().GetSession();
const TString query = fmt::format(R"sql(
CREATE EXTERNAL DATA SOURCE read_data_source WITH (
SOURCE_TYPE="ObjectStorage",
LOCATION="{read_location}",
AUTH_METHOD="NONE"
);
CREATE EXTERNAL TABLE read_table (
key Utf8 NOT NULL,
value Utf8 NOT NULL
) WITH (
DATA_SOURCE="read_data_source",
LOCATION="/",
FORMAT="json_each_row"
);
)sql",
"read_location"_a = GetBucketLocation("test_ctas_read")
);
auto result = session.ExecuteSchemeQuery(query).GetValueSync();
UNIT_ASSERT_VALUES_EQUAL_C(result.GetStatus(), NYdb::EStatus::SUCCESS, result.GetIssues().ToString());

const TString sql = R"sql(
PRAGMA ydb.MaxTasksPerStage = "1";
CREATE TABLE result_table (
PRIMARY KEY (key)
)
WITH (STORE = COLUMN)
AS SELECT * FROM read_table
)sql";

auto queryClient = kikimr->GetQueryClient();
TExecuteQueryResult queryResult = queryClient.ExecuteQuery(
sql,
TTxControl::NoTx(),
TExecuteQuerySettings().StatsMode(EStatsMode::Full)).GetValueSync();

UNIT_ASSERT_VALUES_EQUAL_C(queryResult.GetStatus(), NYdb::EStatus::SUCCESS, queryResult.GetIssues().ToString());
UNIT_ASSERT(queryResult.GetStats());
UNIT_ASSERT(queryResult.GetStats()->GetPlan());
Cerr << "Plan: " << *queryResult.GetStats()->GetPlan() << Endl;
NJson::TJsonValue plan;
UNIT_ASSERT(NJson::ReadJsonTree(*queryResult.GetStats()->GetPlan(), &plan));

const auto& writeStagePlan = plan["Plan"]["Plans"][0]["Plans"][0];
UNIT_ASSERT_VALUES_EQUAL(writeStagePlan["Node Type"].GetStringSafe(), "Stage-Sink");
UNIT_ASSERT_VALUES_EQUAL(writeStagePlan["Stats"]["Tasks"], 1);

const auto& readStagePlan = plan["Plan"]["Plans"][0]["Plans"][0]["Plans"][0]["Plans"][0];
UNIT_ASSERT_VALUES_EQUAL(readStagePlan["Node Type"].GetStringSafe(), "Stage");
UNIT_ASSERT_VALUES_EQUAL(readStagePlan["Stats"]["Tasks"], 1);
}
}

} // namespace NKikimr::NKqp
Loading