diff options
author | imunkin <imunkin@yandex-team.com> | 2025-02-13 22:42:35 +0300 |
---|---|---|
committer | imunkin <imunkin@yandex-team.com> | 2025-02-13 23:06:20 +0300 |
commit | 1f4d6dae736f8313b8ddcad0a72d336cd2901d90 (patch) | |
tree | 91a36e00a18435ec23f0b4c30ccf4ac475c58d08 | |
parent | dcc9572fc76d9c740c97de127bdee1e0b71273b0 (diff) | |
download | ydb-1f4d6dae736f8313b8ddcad0a72d336cd2901d90.tar.gz |
YQL-19597: Fix swap of WideToBlocks with Extend in peephole optimizer
Follows up d56f1cbae00a964056a5a5216fe91918cbf73463
commit_hash:2436c8f5e305aa6961b3bad54fdebdbf908cdafa
-rw-r--r-- | yql/essentials/core/peephole_opt/yql_opt_peephole_physical.cpp | 35 | ||||
-rw-r--r-- | yql/essentials/tests/sql/minirun/part5/canondata/result.json | 6 |
2 files changed, 32 insertions, 9 deletions
diff --git a/yql/essentials/core/peephole_opt/yql_opt_peephole_physical.cpp b/yql/essentials/core/peephole_opt/yql_opt_peephole_physical.cpp index 94754fb67d..c6973d7acb 100644 --- a/yql/essentials/core/peephole_opt/yql_opt_peephole_physical.cpp +++ b/yql/essentials/core/peephole_opt/yql_opt_peephole_physical.cpp @@ -146,14 +146,37 @@ TExprNode::TPtr OptimizeWideToBlocks(const TExprNode::TPtr& node, TExprContext& .Build(); } - if (input.IsCallable({"Extend", "OrderedExtend"})) { - YQL_CLOG(DEBUG, CorePeepHole) << "Swap " << node->Content() << " with " << input.Content(); + if (input.IsCallable("FromFlow") && input.Head().IsCallable({"Extend", "OrderedExtend"})) { + const auto& extend = input.Head(); + // Technically, the code below rewrites the following sequence + // (WideToBlocks (FromFlow (Extend (<input>)))) + // into (Extend (WideToBlocks (FromFlow (<input>))), but + // the logging is left intact, omitting the FromFlow barrier. + YQL_CLOG(DEBUG, CorePeepHole) << "Swap " << node->Content() << " with " << extend.Content(); TExprNodeList newChildren; - newChildren.reserve(input.ChildrenSize()); - for (auto& child : input.ChildrenList()) { - newChildren.emplace_back(ctx.ChangeChild(*node, 0, std::move(child))); + newChildren.reserve(extend.ChildrenSize()); + for (const auto& child : extend.ChildrenList()) { + // Extend callable can handle any sequential type, so + // just wrap all its children with (ToStream (...)). + // However, its *block* overload works only with WideFlow, + // so the new child is wrapped with ToFlow callable. + const auto newChild = ctx.Builder(node->Pos()) + .Callable("ToFlow") + .Callable(0, "WideToBlocks") + .Callable(0, "ToStream") + .Add(0, child) + .Seal() + .Seal() + .Seal() + .Build(); + newChildren.emplace_back(newChild); } - return ctx.NewCallable(input.Pos(), input.IsCallable("Extend") ? "BlockExtend" : "BlockOrderedExtend", std::move(newChildren)); + const auto newName = extend.IsCallable("Extend") ? "BlockExtend" : "BlockOrderedExtend"; + return ctx.Builder(node->Pos()) + .Callable("FromFlow") + .Add(0, ctx.NewCallable(input.Pos(), newName, std::move(newChildren))) + .Seal() + .Build(); } return node; diff --git a/yql/essentials/tests/sql/minirun/part5/canondata/result.json b/yql/essentials/tests/sql/minirun/part5/canondata/result.json index 64e4208d97..c15133e45f 100644 --- a/yql/essentials/tests/sql/minirun/part5/canondata/result.json +++ b/yql/essentials/tests/sql/minirun/part5/canondata/result.json @@ -375,9 +375,9 @@ ], "test.test[blocks-extend-default.txt-Peephole]": [ { - "checksum": "2bec63a1689cb0b100f82fec2b89cd3c", - "size": 629, - "uri": "https://{canondata_backend}/1809005/02f459fce1f16d89b3444e6e8728b9747bb52b53/resource.tar.gz#test.test_blocks-extend-default.txt-Peephole_/opt.yql" + "checksum": "9d73defb3c7ec979ad15c0d105f3211e", + "size": 664, + "uri": "https://{canondata_backend}/1775059/85273762ecc854fd58fe1daec09cca032c02ccb1/resource.tar.gz#test.test_blocks-extend-default.txt-Peephole_/opt.yql" } ], "test.test[blocks-extend-default.txt-Results]": [ |