diff options
author | qrort <31865255+qrort@users.noreply.github.com> | 2024-08-09 16:08:14 +0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-08-09 16:08:14 +0300 |
commit | 633ff575647118017b3e38bfc7e58d1fb350cf34 (patch) | |
tree | 6468c14fa469ab5080f284ca4ba460db97a0d44d | |
parent | c59279a94a9b07124f7cdd2a414dcc0205e4778f (diff) | |
download | ydb-633ff575647118017b3e38bfc7e58d1fb350cf34.tar.gz |
ExtractMembers from pg_tables read. Resolves #7286 (#7595)
-rw-r--r-- | ydb/core/kqp/provider/yql_kikimr_opt_build.cpp | 23 | ||||
-rw-r--r-- | ydb/core/kqp/ut/pg/pg_catalog_ut.cpp | 13 |
2 files changed, 29 insertions, 7 deletions
diff --git a/ydb/core/kqp/provider/yql_kikimr_opt_build.cpp b/ydb/core/kqp/provider/yql_kikimr_opt_build.cpp index f3261eef27..b919c03047 100644 --- a/ydb/core/kqp/provider/yql_kikimr_opt_build.cpp +++ b/ydb/core/kqp/provider/yql_kikimr_opt_build.cpp @@ -887,23 +887,23 @@ TExprNode::TPtr KiBuildQuery(TExprBase node, TExprContext& ctx, TStringBuf datab TNodeOnNodeOwnedMap replaces; std::unordered_set<std::string> pgDynTables = {"pg_tables", "tables", "pg_class"}; - std::unordered_map<const NYql::TExprNode*, TString> tableNames; - VisitExpr(node.Ptr(), [&replaces, &tableNames, &pgDynTables](const TExprNode::TPtr& input) -> bool { + VisitExpr(node.Ptr(), [&replaces, &pgDynTables](const TExprNode::TPtr& input) -> bool { if (input->IsCallable("PgTableContent")) { TPgTableContent content(input); if (pgDynTables.contains(content.Table().StringValue())) { replaces[input.Get()] = nullptr; - tableNames[input.Get()] = content.Table().StringValue(); } } return true; }); if (!replaces.empty()) { - for (auto& [key, _] : replaces) { + for (auto& [input, _] : replaces) { + TPgTableContent content(input); + TExprNode::TPtr path = ctx.NewCallable( node.Pos(), "String", - { ctx.NewAtom(node.Pos(), TStringBuilder() << "/" << database << "/.sys/" << tableNames[key]) } + { ctx.NewAtom(node.Pos(), TStringBuilder() << "/" << database << "/.sys/" << content.Table().StringValue()) } ); auto table = ctx.NewList(node.Pos(), {ctx.NewAtom(node.Pos(), "table"), path}); auto newKey = ctx.NewCallable(node.Pos(), "Key", {table}); @@ -923,10 +923,21 @@ TExprNode::TPtr KiBuildQuery(TExprBase node, TExprContext& ctx, TStringBuf datab .Build() .Done().Ptr(); + auto readData = Build<TCoRight>(ctx, node.Pos()) .Input(ydbSysTableRead) .Done().Ptr(); - replaces[key] = readData; + + if (auto v = content.Columns().Maybe<TCoVoid>()) { + replaces[input] = readData; + } else { + auto extractMembers = Build<TCoExtractMembers>(ctx, node.Pos()) + .Input(readData) + .Members(content.Columns().Ptr()) + .Done().Ptr(); + + replaces[input] = extractMembers; + } } ctx.Step .Repeat(TExprStep::ExprEval) diff --git a/ydb/core/kqp/ut/pg/pg_catalog_ut.cpp b/ydb/core/kqp/ut/pg/pg_catalog_ut.cpp index 4bdffb115f..e562a77669 100644 --- a/ydb/core/kqp/ut/pg/pg_catalog_ut.cpp +++ b/ydb/core/kqp/ut/pg/pg_catalog_ut.cpp @@ -416,7 +416,8 @@ Y_UNIT_TEST_SUITE(PgCatalog) { { auto result = db.ExecuteQuery(R"( CREATE TABLE table1 ( - id int4 primary key + id int4 primary key, + value int4 ); CREATE TABLE table2 ( id varchar primary key @@ -486,6 +487,16 @@ Y_UNIT_TEST_SUITE(PgCatalog) { ["table1"];["table2"] ])", FormatResultSetYson(result.GetResultSet(0))); } + { //https://github.com/ydb-platform/ydb/issues/7286 + auto result = db.ExecuteQuery(R"( + select tablename from pg_catalog.pg_tables where tablename='pg_proc' + )", NYdb::NQuery::TTxControl::BeginTx().CommitTx(), settings).ExtractValueSync(); + UNIT_ASSERT_C(result.IsSuccess(), result.GetIssues().ToString()); + UNIT_ASSERT_C(!result.GetResultSets().empty(), "no result sets"); + CompareYson(R"([ + ["pg_proc"] + ])", FormatResultSetYson(result.GetResultSet(0))); + } } } |