diff options
author | Vitaly Stoyan <vitstn@gmail.com> | 2022-06-29 23:49:12 +0300 |
---|---|---|
committer | Vitaly Stoyan <vitstn@gmail.com> | 2022-06-29 23:49:12 +0300 |
commit | 4663401fcbd66b2db83f0e5ee6171eef7bbda40f (patch) | |
tree | ea42d8ae1926bfeb57191444c5539fc2d43a9994 | |
parent | cce3e253f5356f010631e1fb64d4e91414ad94db (diff) | |
download | ydb-4663401fcbd66b2db83f0e5ee6171eef7bbda40f.tar.gz |
YQL-14728 fixed any/all scalar sublinks
ref:65c25f3b6178264b5d67d82a6dfc89ae1b7ec9b8
-rw-r--r-- | ydb/library/yql/core/common_opt/yql_co_pgselect.cpp | 57 |
1 files changed, 21 insertions, 36 deletions
diff --git a/ydb/library/yql/core/common_opt/yql_co_pgselect.cpp b/ydb/library/yql/core/common_opt/yql_co_pgselect.cpp index 4595d7cf7c..d959a951f1 100644 --- a/ydb/library/yql/core/common_opt/yql_co_pgselect.cpp +++ b/ydb/library/yql/core/common_opt/yql_co_pgselect.cpp @@ -273,60 +273,45 @@ std::pair<TExprNode::TPtr, TExprNode::TPtr> RewriteSubLinks(TPositionHandle pos, .Seal() .Build(); } else if (linkType == "any" || linkType == "all") { - auto filterArg = ctx.NewArgument(node->Pos(), "linkRow"); + auto foldArg = ctx.NewArgument(node->Pos(), "linkRow"); + auto stateArg = ctx.NewArgument(node->Pos(), "state"); + auto foldArgs = ctx.NewArguments(node->Pos(), { foldArg, stateArg }); auto value = ctx.Builder(node->Pos()) .Callable("SingleMember") - .Add(0, filterArg) + .Add(0, foldArg) .Seal() .Build(); - auto filterArgs = ctx.NewArguments(node->Pos(), { filterArg }); - auto filterExpr = ctx.ReplaceNodes(testLambda->TailPtr(), { + auto foldExpr = ctx.ReplaceNodes(testLambda->TailPtr(), { {testLambda->Head().Child(0), originalRow}, {testLambda->Head().Child(1), value}, }); - if (linkType == "all") { - filterExpr = ctx.Builder(node->Pos()) - .Callable("PgNot") - .Add(0, filterExpr) - .Seal() - .Build(); - } + foldExpr = ctx.Builder(node->Pos()) + .Callable((linkType == "all") ? "PgAnd" : "PgOr") + .Add(0, foldExpr) + .Add(1, stateArg) + .Seal() + .Build(); - filterExpr = AsFilterPredicate(node->Pos(), filterExpr, ctx); - auto filterLambda = ctx.NewLambda(node->Pos(), std::move(filterArgs), std::move(filterExpr)); + auto foldLambda = ctx.NewLambda(node->Pos(), std::move(foldArgs), std::move(foldExpr)); - auto filtered = ctx.Builder(node->Pos()) - .Callable("Filter") + auto result = ctx.Builder(node->Pos()) + .Callable("Fold") .Callable(0, "Collect") .Add(0, select) .Seal() - .Add(1, filterLambda) - .Seal() - .Build(); - - auto take1 = ctx.Builder(node->Pos()) - .Callable("Take") - .Add(0, filtered) - .Callable(1, "Uint64") - .Atom(0, "1") - .Seal() - .Seal() - .Build(); - - return ctx.Builder(node->Pos()) - .Callable("ToPg") - .Callable(0, "==") - .Callable(0, "Length") - .Add(0, take1) - .Seal() - .Callable(1, "Uint64") - .Atom(0, (linkType == "any") ? "1" : "0") + .Callable(1, "PgConst") + .Atom(0, (linkType == "all") ? "true" : "false") + .Callable(1, "PgType") + .Atom(0, "bool") .Seal() .Seal() + .Add(2, foldLambda) .Seal() .Build(); + + return result; } } else { auto fullColList = ctx.Builder(node->Pos()) |