diff options
author | vvvv <vvvv@yandex-team.com> | 2025-01-30 22:03:34 +0300 |
---|---|---|
committer | vvvv <vvvv@yandex-team.com> | 2025-01-30 22:32:04 +0300 |
commit | 5677d72d8eb0324ca964ec09319d086857a01003 (patch) | |
tree | aeeb09220f5086ca84c926a3d784e53be7b0e426 | |
parent | b1baee0265758e960be4693baa75a1c6f60dce82 (diff) | |
download | ydb-5677d72d8eb0324ca964ec09319d086857a01003.tar.gz |
YQL-19496 fixed INode clone
commit_hash:3433b67a9455f9f7388eb5079f752d4a745bc2bc
-rw-r--r-- | yql/essentials/sql/v1/select.cpp | 24 | ||||
-rw-r--r-- | yql/essentials/sql/v1/source.h | 2 | ||||
-rw-r--r-- | yql/essentials/sql/v1/sql_expression.cpp | 16 | ||||
-rw-r--r-- | yt/yql/tests/sql/suites/select/exists_with_table.sql | 2 |
4 files changed, 23 insertions, 21 deletions
diff --git a/yql/essentials/sql/v1/select.cpp b/yql/essentials/sql/v1/select.cpp index a916517d88..f44e328ba2 100644 --- a/yql/essentials/sql/v1/select.cpp +++ b/yql/essentials/sql/v1/select.cpp @@ -95,10 +95,11 @@ TNodePtr BuildSubquery(TSourcePtr source, const TString& alias, bool inSubquery, class TSourceNode: public INode { public: - TSourceNode(TPosition pos, TSourcePtr&& source, bool checkExist) + TSourceNode(TPosition pos, TSourcePtr&& source, bool checkExist, bool withTables) : INode(pos) , Source(std::move(source)) , CheckExist(checkExist) + , WithTables(withTables) {} ISource* GetSource() override { @@ -133,6 +134,20 @@ public: } src->AddDependentSource(Source.Get()); } + if (Node && WithTables) { + TTableList tableList; + Source->GetInputTables(tableList); + + TNodePtr inputTables(BuildInputTables(ctx.Pos(), tableList, IsSubquery(), ctx.Scoped)); + if (!inputTables->Init(ctx, Source.Get())) { + return false; + } + + auto blockContent = inputTables; + blockContent = L(blockContent, Y("return", Node)); + Node = Y("block", Q(blockContent)); + } + return true; } @@ -150,16 +165,17 @@ public: } TPtr DoClone() const final { - return new TSourceNode(Pos, Source->CloneSource(), CheckExist); + return new TSourceNode(Pos, Source->CloneSource(), CheckExist, WithTables); } protected: TSourcePtr Source; TNodePtr Node; bool CheckExist; + bool WithTables; }; -TNodePtr BuildSourceNode(TPosition pos, TSourcePtr source, bool checkExist) { - return new TSourceNode(pos, std::move(source), checkExist); +TNodePtr BuildSourceNode(TPosition pos, TSourcePtr source, bool checkExist, bool withTables) { + return new TSourceNode(pos, std::move(source), checkExist, withTables); } class TFakeSource: public ISource { diff --git a/yql/essentials/sql/v1/source.h b/yql/essentials/sql/v1/source.h index bd311567d3..991657ed15 100644 --- a/yql/essentials/sql/v1/source.h +++ b/yql/essentials/sql/v1/source.h @@ -239,7 +239,7 @@ namespace NSQLTranslationV1 { TNodePtr BuildSubquery(TSourcePtr source, const TString& alias, bool inSubquery, int ensureTupleSize, TScopedStatePtr scoped); TNodePtr BuildSubqueryRef(TNodePtr subquery, const TString& alias, int tupleIndex = -1); TNodePtr BuildInvalidSubqueryRef(TPosition subqueryPos); - TNodePtr BuildSourceNode(TPosition pos, TSourcePtr source, bool checkExist = false); + TNodePtr BuildSourceNode(TPosition pos, TSourcePtr source, bool checkExist = false, bool withTables = false); TSourcePtr BuildMuxSource(TPosition pos, TVector<TSourcePtr>&& sources); TSourcePtr BuildFakeSource(TPosition pos, bool missingFrom = false, bool inSubquery = false); TSourcePtr BuildNodeSource(TPosition pos, const TNodePtr& node, bool wrapToList = false, bool wrapByTableSource = false); diff --git a/yql/essentials/sql/v1/sql_expression.cpp b/yql/essentials/sql/v1/sql_expression.cpp index be401949c7..5316737b94 100644 --- a/yql/essentials/sql/v1/sql_expression.cpp +++ b/yql/essentials/sql/v1/sql_expression.cpp @@ -1287,21 +1287,7 @@ TNodePtr TSqlExpression::ExistsRule(const TRule_exists_expr& rule) { return nullptr; } const bool checkExist = true; - auto select = BuildSourceNode(Ctx.Pos(), source, checkExist); - if (Ctx.Settings.EmitReadsForExists) { - TTableList tableList; - source->GetInputTables(tableList); - - TNodePtr inputTables(BuildInputTables(Ctx.Pos(), tableList, false, Ctx.Scoped)); - if (!inputTables->Init(Ctx, source.Get())) { - return nullptr; - } - - auto node = inputTables; - node = node->L(node, node->Y("return", select)); - select = node->Y("block", node->Q(node)); - } - + auto select = BuildSourceNode(Ctx.Pos(), source, checkExist, Ctx.Settings.EmitReadsForExists); return BuildBuiltinFunc(Ctx, Ctx.Pos(), "ListHasItems", {select}); } diff --git a/yt/yql/tests/sql/suites/select/exists_with_table.sql b/yt/yql/tests/sql/suites/select/exists_with_table.sql index 990ff664d4..5aeef98d9a 100644 --- a/yt/yql/tests/sql/suites/select/exists_with_table.sql +++ b/yt/yql/tests/sql/suites/select/exists_with_table.sql @@ -1,6 +1,6 @@ use plato; -$ex = EXISTS ( +$ex = NOT EXISTS ( SELECT TRUE FROM Input |