aboutsummaryrefslogtreecommitdiffstats
path: root/yql/essentials/core/yql_opt_utils.cpp
diff options
context:
space:
mode:
authorAlexander Smirnov <alex@ydb.tech>2025-03-12 10:37:13 +0000
committerAlexander Smirnov <alex@ydb.tech>2025-03-12 10:37:13 +0000
commitb27c447af8bffc727382c0dc75272e261cbb4ac4 (patch)
treee0f6199fec84ae26bb5ea26566fa1daa12693e3b /yql/essentials/core/yql_opt_utils.cpp
parentcb56e1cde2824ff3b64be1de4794bff3cab0db61 (diff)
parentd06e9749bd6f0a561ee4fe296cdb3e03a24d1f82 (diff)
downloadydb-b27c447af8bffc727382c0dc75272e261cbb4ac4.tar.gz
Merge pull request #15611 from ydb-platform/merge-libs-250312-0708
Diffstat (limited to 'yql/essentials/core/yql_opt_utils.cpp')
-rw-r--r--yql/essentials/core/yql_opt_utils.cpp61
1 files changed, 61 insertions, 0 deletions
diff --git a/yql/essentials/core/yql_opt_utils.cpp b/yql/essentials/core/yql_opt_utils.cpp
index 618105e08d..300679a82c 100644
--- a/yql/essentials/core/yql_opt_utils.cpp
+++ b/yql/essentials/core/yql_opt_utils.cpp
@@ -15,6 +15,8 @@
namespace NYql {
+const char KeepWorldOptName[] = "KeepWorld";
+
using namespace NNodes;
namespace {
@@ -2332,4 +2334,63 @@ bool CheckSupportedTypes(
return true;
}
+TExprNode::TPtr KeepWorld(TExprNode::TPtr node, const TExprNode& src, TExprContext& ctx, TTypeAnnotationContext& types) {
+ const bool optEnabled = IsOptimizerEnabled<KeepWorldOptName>(types) && !IsOptimizerDisabled<KeepWorldOptName>(types);
+ if (!optEnabled) {
+ return node;
+ }
+
+ const auto& worldLinks = src.GetWorldLinks();
+ if (!worldLinks) {
+ return node;
+ }
+
+ TExprNode::TListType missingLinks;
+ for (const auto& link : *worldLinks) {
+ if (!IsDepended(*node, *link)) {
+ missingLinks.push_back(link);
+ }
+ }
+
+ if (missingLinks.empty()) {
+ return node;
+ }
+
+ for (auto& link : missingLinks) {
+ if (link->GetTypeAnn()->GetKind() != ETypeAnnotationKind::World) {
+ link = ctx.NewCallable(node->Pos(), LeftName, { link });
+ }
+ }
+
+ TExprNode::TPtr syncLink;
+ if (missingLinks.size() == 1) {
+ syncLink = missingLinks[0];
+ } else {
+ syncLink = ctx.NewCallable(node->Pos(), SyncName, std::move(missingLinks));
+ }
+
+ YQL_CLOG(DEBUG, Core) << "KeepWorld over " << node->Content();
+ if (src.GetTypeAnn()->ReturnsWorld()) {
+ if (src.GetTypeAnn()->GetKind() == ETypeAnnotationKind::World) {
+ return ctx.NewCallable(src.Pos(), SyncName, { syncLink, node});
+ } else {
+ return ctx.Builder(src.Pos())
+ .Callable("WithWorld")
+ .Callable(0, RightName)
+ .Add(0, node)
+ .Seal()
+ .Callable(1, SyncName)
+ .Add(0, syncLink)
+ .Callable(1, LeftName)
+ .Add(0, node)
+ .Seal()
+ .Seal()
+ .Seal()
+ .Build();
+ }
+ } else {
+ return ctx.NewCallable(src.Pos(), "WithWorld", { node, syncLink});
+ }
+}
+
}