Skip to content

[YQL-17453] Fix pushing LMap/HasItems to stage. More strict DqReplicate type ann #1057

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jan 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 8 additions & 3 deletions ydb/library/yql/core/type_ann/type_ann_core.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3445,16 +3445,21 @@ namespace NTypeAnnImpl {
return IGraphTransformer::TStatus::Ok;
}

IGraphTransformer::TStatus FromFlowWrapper(const TExprNode::TPtr& input, TExprNode::TPtr&, TContext& ctx) {
IGraphTransformer::TStatus FromFlowWrapper(const TExprNode::TPtr& input, TExprNode::TPtr& output, TContext& ctx) {
if (!EnsureArgsCount(*input, 1, ctx.Expr)) {
return IGraphTransformer::TStatus::Error;
}

if (!EnsureFlowType(input->Head(), ctx.Expr)) {
const TTypeAnnotationNode* itemType = nullptr;
if (!EnsureNewSeqType<false, false>(input->Head(), ctx.Expr, &itemType)) {
return IGraphTransformer::TStatus::Error;
}
const auto kind = input->Head().GetTypeAnn()->GetKind();
if (ETypeAnnotationKind::Stream == kind) {
output = input->HeadPtr();
return IGraphTransformer::TStatus::Repeat;
}

const auto itemType = input->Head().GetTypeAnn()->Cast<TFlowExprType>()->GetItemType();
input->SetTypeAnn(ctx.Expr.MakeType<TStreamExprType>(itemType));
return IGraphTransformer::TStatus::Ok;
}
Expand Down
21 changes: 1 addition & 20 deletions ydb/library/yql/dq/opt/dq_opt_peephole.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -607,29 +607,10 @@ NNodes::TExprBase DqPeepholeRewriteReplicate(const NNodes::TExprBase& node, TExp

TVector<TExprBase> branches;
branches.reserve(dqReplicate.Args().Count() - 1);
const auto inputKind = dqReplicate.Arg(0).Ref().GetTypeAnn()->GetKind();
YQL_ENSURE(inputKind == ETypeAnnotationKind::Stream || inputKind == ETypeAnnotationKind::Flow);

auto inputIndex = NDq::BuildAtomList("0", dqReplicate.Pos(), ctx);
for (size_t i = 1; i < dqReplicate.Args().Count(); ++i) {
branches.emplace_back(inputIndex);
const auto lambdaOutputKind = dqReplicate.Arg(i).Ref().GetTypeAnn()->GetKind();
YQL_ENSURE(lambdaOutputKind == ETypeAnnotationKind::Stream || lambdaOutputKind == ETypeAnnotationKind::Flow);
if (lambdaOutputKind != inputKind) {
branches.emplace_back(ctx.Builder(dqReplicate.Arg(i).Pos())
.Lambda()
.Param("arg")
.Callable(lambdaOutputKind == ETypeAnnotationKind::Stream ? "ToFlow" : "FromFlow")
.Apply(0, dqReplicate.Arg(i).Ptr())
.With(0, "arg")
.Seal()
.Seal()
.Seal()
.Build()
);
} else {
branches.emplace_back(ctx.DeepCopyLambda(dqReplicate.Arg(i).Ref()));
}
branches.emplace_back(ctx.DeepCopyLambda(dqReplicate.Arg(i).Ref()));
}

return Build<TCoSwitch>(ctx, dqReplicate.Pos())
Expand Down
19 changes: 9 additions & 10 deletions ydb/library/yql/dq/opt/dq_opt_phy.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -835,13 +835,15 @@ TExprBase DqPushBaseLMapToStage(TExprBase node, TExprContext& ctx, IOptimization
}

auto lambda = Build<TCoLambda>(ctx, lmap.Lambda().Pos())
.Args({"stream"})
.template Body<TCoToStream>()
.Args({"arg"})
.template Body<TCoToFlow>()
.template Input<TExprApplier>()
.Apply(lmap.Lambda())
.With(lmap.Lambda().Args().Arg(0), "stream")
.template With<TCoFromFlow>(0)
.Input("arg")
.Build()
.Build()
.Build()
.Done();

auto result = DqPushLambdaToStageUnionAll(dqUnion, lambda, {}, ctx, optCtx);
Expand Down Expand Up @@ -2253,13 +2255,10 @@ TExprBase DqBuildHasItems(TExprBase node, TExprContext& ctx, IOptimizationContex
// Add LIMIT 1 via Take
auto takeProgram = Build<TCoLambda>(ctx, node.Pos())
.Args({"take_arg"})
// DqOutput expects stream as input, thus form stream with one element
.Body<TCoToStream>()
.Input<TCoTake>()
.Input({"take_arg"})
.Count<TCoUint64>()
.Literal().Build("1")
.Build()
.Body<TCoTake>()
.Input({"take_arg"})
.Count<TCoUint64>()
.Literal().Build("1")
.Build()
.Build()
.Done();
Expand Down
4 changes: 2 additions & 2 deletions ydb/library/yql/dq/type_ann/dq_type_ann.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -772,10 +772,10 @@ TStatus AnnotateDqReplicate(const TExprNode::TPtr& input, TExprContext& ctx) {
if (!lambda->GetTypeAnn()) {
return TStatus::Repeat;
}
const TTypeAnnotationNode* lambdaItemType = nullptr;
if (!EnsureNewSeqType<false, false>(*lambda, ctx, &lambdaItemType)) {
if (!EnsureFlowType(*lambda, ctx)) {
return TStatus::Error;
}
const TTypeAnnotationNode* lambdaItemType = lambda->GetTypeAnn()->Cast<TFlowExprType>()->GetItemType();
if (!EnsurePersistableType(lambda->Pos(), *lambdaItemType, ctx)) {
return TStatus::Error;
}
Expand Down
72 changes: 36 additions & 36 deletions ydb/library/yql/tests/sql/dq_file/part0/canondata/result.json
Original file line number Diff line number Diff line change
Expand Up @@ -445,45 +445,45 @@
],
"test.test[blocks-combine_all_pg_filter--Analyze]": [
{
"checksum": "4656668d4e2f733a00211fcb65bce80e",
"size": 6308,
"uri": "https://{canondata_backend}/1777230/2492c292c3dcbe5dcfc10230e1b6f79478cb2008/resource.tar.gz#test.test_blocks-combine_all_pg_filter--Analyze_/plan.txt"
"checksum": "cb30717cca1cf1bf0c11f384cef516ff",
"size": 6207,
"uri": "https://{canondata_backend}/1923547/63814b1113aa44b294fe28fd8a7c507858e712bd/resource.tar.gz#test.test_blocks-combine_all_pg_filter--Analyze_/plan.txt"
}
],
"test.test[blocks-combine_all_pg_filter--Debug]": [
{
"checksum": "4ccfadbb9b2ef8f8a147f634eb24fdb8",
"size": 5951,
"uri": "https://{canondata_backend}/1889210/f053f10d689490bf5100a7fbf8cc00cf1b09e227/resource.tar.gz#test.test_blocks-combine_all_pg_filter--Debug_/opt.yql_patched"
"checksum": "0175c2b71c1bee6c8898ad3e45f4fbf2",
"size": 5940,
"uri": "https://{canondata_backend}/1923547/63814b1113aa44b294fe28fd8a7c507858e712bd/resource.tar.gz#test.test_blocks-combine_all_pg_filter--Debug_/opt.yql_patched"
}
],
"test.test[blocks-combine_all_pg_filter--Plan]": [
{
"checksum": "4656668d4e2f733a00211fcb65bce80e",
"size": 6308,
"uri": "https://{canondata_backend}/1937001/6a56dcab007ee7dae62350ff55c93dfb66c55be9/resource.tar.gz#test.test_blocks-combine_all_pg_filter--Plan_/plan.txt"
"checksum": "cb30717cca1cf1bf0c11f384cef516ff",
"size": 6207,
"uri": "https://{canondata_backend}/1923547/63814b1113aa44b294fe28fd8a7c507858e712bd/resource.tar.gz#test.test_blocks-combine_all_pg_filter--Plan_/plan.txt"
}
],
"test.test[blocks-combine_all_pg_filter--Results]": [],
"test.test[blocks-minmax_strings--Analyze]": [
{
"checksum": "37a57735794a77d894fa5a6b0abd3eb6",
"size": 10519,
"uri": "https://{canondata_backend}/1937367/e7bed33e6b4b2768362711c9af0c33aa77d7c6be/resource.tar.gz#test.test_blocks-minmax_strings--Analyze_/plan.txt"
"checksum": "8a75fbb5e579f9a872fefea76b24e45a",
"size": 10317,
"uri": "https://{canondata_backend}/1923547/63814b1113aa44b294fe28fd8a7c507858e712bd/resource.tar.gz#test.test_blocks-minmax_strings--Analyze_/plan.txt"
}
],
"test.test[blocks-minmax_strings--Debug]": [
{
"checksum": "3f2580c331318e495301e26412dddbe2",
"size": 7676,
"uri": "https://{canondata_backend}/1781765/8e0613d3790a082da800eb9686a3a395b3b84a69/resource.tar.gz#test.test_blocks-minmax_strings--Debug_/opt.yql_patched"
"checksum": "228cb9ea9ac90b76c19456f64f953232",
"size": 7621,
"uri": "https://{canondata_backend}/1923547/63814b1113aa44b294fe28fd8a7c507858e712bd/resource.tar.gz#test.test_blocks-minmax_strings--Debug_/opt.yql_patched"
}
],
"test.test[blocks-minmax_strings--Plan]": [
{
"checksum": "37a57735794a77d894fa5a6b0abd3eb6",
"size": 10519,
"uri": "https://{canondata_backend}/1924537/e1fc580fe9de3ebf40555bc861809490fa6c934d/resource.tar.gz#test.test_blocks-minmax_strings--Plan_/plan.txt"
"checksum": "8a75fbb5e579f9a872fefea76b24e45a",
"size": 10317,
"uri": "https://{canondata_backend}/1923547/63814b1113aa44b294fe28fd8a7c507858e712bd/resource.tar.gz#test.test_blocks-minmax_strings--Plan_/plan.txt"
}
],
"test.test[blocks-minmax_strings--Results]": [],
Expand Down Expand Up @@ -2505,23 +2505,23 @@
"test.test[pg_catalog-pg_stat_gssapi-default.txt-Results]": [],
"test.test[produce-discard_process_with_lambda-default.txt-Analyze]": [
{
"checksum": "3bffa2a18b9b81cc1f89280482f926dc",
"size": 3833,
"uri": "https://{canondata_backend}/937458/ca874ae4a90e1527826d17c1da5f3d3dad325887/resource.tar.gz#test.test_produce-discard_process_with_lambda-default.txt-Analyze_/plan.txt"
"checksum": "ebe34f5d2b86ce7954a161dc02a783aa",
"size": 3732,
"uri": "https://{canondata_backend}/1942415/eb3b960b9379ed168e3265e38f52b5ecd2264129/resource.tar.gz#test.test_produce-discard_process_with_lambda-default.txt-Analyze_/plan.txt"
}
],
"test.test[produce-discard_process_with_lambda-default.txt-Debug]": [
{
"checksum": "59db4a11e71c8c2545cf3b98a80f8791",
"size": 1376,
"uri": "https://{canondata_backend}/1777230/54900ab79add880940d8cd79f2a56fc8179d5364/resource.tar.gz#test.test_produce-discard_process_with_lambda-default.txt-Debug_/opt.yql_patched"
"checksum": "749ba4a052203d4896c672f6580262bc",
"size": 1365,
"uri": "https://{canondata_backend}/1942415/eb3b960b9379ed168e3265e38f52b5ecd2264129/resource.tar.gz#test.test_produce-discard_process_with_lambda-default.txt-Debug_/opt.yql_patched"
}
],
"test.test[produce-discard_process_with_lambda-default.txt-Plan]": [
{
"checksum": "3bffa2a18b9b81cc1f89280482f926dc",
"size": 3833,
"uri": "https://{canondata_backend}/1130705/1ce6c7c35a3d1f6575dcd3f9fb981d727082535c/resource.tar.gz#test.test_produce-discard_process_with_lambda-default.txt-Plan_/plan.txt"
"checksum": "ebe34f5d2b86ce7954a161dc02a783aa",
"size": 3732,
"uri": "https://{canondata_backend}/1942415/eb3b960b9379ed168e3265e38f52b5ecd2264129/resource.tar.gz#test.test_produce-discard_process_with_lambda-default.txt-Plan_/plan.txt"
}
],
"test.test[produce-discard_process_with_lambda-default.txt-Results]": [],
Expand Down Expand Up @@ -2989,26 +2989,26 @@
],
"test.test[type_v3-replace_diff_layout--Analyze]": [
{
"checksum": "d863f77ffae8e99c471b0cce2bbef8d4",
"size": 11581,
"uri": "https://{canondata_backend}/1809005/3e0dcc957dfc0708964adef6897d1196bc2dea9e/resource.tar.gz#test.test_type_v3-replace_diff_layout--Analyze_/plan.txt"
"checksum": "70c2ec8274c52f1a38ece9ded7ced484",
"size": 11480,
"uri": "https://{canondata_backend}/1942415/eb3b960b9379ed168e3265e38f52b5ecd2264129/resource.tar.gz#test.test_type_v3-replace_diff_layout--Analyze_/plan.txt"
},
{
"uri": "file://test.test_type_v3-replace_diff_layout--Analyze_/extracted"
}
],
"test.test[type_v3-replace_diff_layout--Debug]": [
{
"checksum": "39269bdb2fb00936857832bbc988fd88",
"size": 4373,
"uri": "https://{canondata_backend}/1777230/54900ab79add880940d8cd79f2a56fc8179d5364/resource.tar.gz#test.test_type_v3-replace_diff_layout--Debug_/opt.yql_patched"
"checksum": "674c9808638ed8a52743648beab333db",
"size": 4362,
"uri": "https://{canondata_backend}/1942415/eb3b960b9379ed168e3265e38f52b5ecd2264129/resource.tar.gz#test.test_type_v3-replace_diff_layout--Debug_/opt.yql_patched"
}
],
"test.test[type_v3-replace_diff_layout--Plan]": [
{
"checksum": "d863f77ffae8e99c471b0cce2bbef8d4",
"size": 11581,
"uri": "https://{canondata_backend}/1936842/022ff014d0af26bc1aae8870d28654d93e3348a0/resource.tar.gz#test.test_type_v3-replace_diff_layout--Plan_/plan.txt"
"checksum": "70c2ec8274c52f1a38ece9ded7ced484",
"size": 11480,
"uri": "https://{canondata_backend}/1942415/eb3b960b9379ed168e3265e38f52b5ecd2264129/resource.tar.gz#test.test_type_v3-replace_diff_layout--Plan_/plan.txt"
}
],
"test.test[type_v3-replace_diff_layout--Results]": [
Expand Down
54 changes: 27 additions & 27 deletions ydb/library/yql/tests/sql/dq_file/part1/canondata/result.json
Original file line number Diff line number Diff line change
Expand Up @@ -555,67 +555,67 @@
"test.test[binding-table_concat_strict_binding-default.txt-Results]": [],
"test.test[blocks-combine_hashed_min--Analyze]": [
{
"checksum": "522ef6289aa4d54583c701d52584242e",
"size": 6285,
"uri": "https://{canondata_backend}/995452/4303db57e47a09cae11e8629ebf6e39558f3f239/resource.tar.gz#test.test_blocks-combine_hashed_min--Analyze_/plan.txt"
"checksum": "ed96fce91ec9eed1bda8c4428f6e0f2a",
"size": 6184,
"uri": "https://{canondata_backend}/1923547/eb397e7e75a7ff316191f787f130964fedc0010a/resource.tar.gz#test.test_blocks-combine_hashed_min--Analyze_/plan.txt"
}
],
"test.test[blocks-combine_hashed_min--Debug]": [
{
"checksum": "cf94ec3c4de2778ce8d83f21142747dc",
"size": 3140,
"uri": "https://{canondata_backend}/1871182/3b561e37ea20fe792066c7eeac8cad978b139090/resource.tar.gz#test.test_blocks-combine_hashed_min--Debug_/opt.yql_patched"
"checksum": "398f18ef6a29c6f822997d596000ea27",
"size": 3129,
"uri": "https://{canondata_backend}/1923547/eb397e7e75a7ff316191f787f130964fedc0010a/resource.tar.gz#test.test_blocks-combine_hashed_min--Debug_/opt.yql_patched"
}
],
"test.test[blocks-combine_hashed_min--Plan]": [
{
"checksum": "522ef6289aa4d54583c701d52584242e",
"size": 6285,
"uri": "https://{canondata_backend}/995452/4303db57e47a09cae11e8629ebf6e39558f3f239/resource.tar.gz#test.test_blocks-combine_hashed_min--Plan_/plan.txt"
"checksum": "ed96fce91ec9eed1bda8c4428f6e0f2a",
"size": 6184,
"uri": "https://{canondata_backend}/1923547/eb397e7e75a7ff316191f787f130964fedc0010a/resource.tar.gz#test.test_blocks-combine_hashed_min--Plan_/plan.txt"
}
],
"test.test[blocks-combine_hashed_min--Results]": [],
"test.test[blocks-combine_hashed_minmax_double--Analyze]": [
{
"checksum": "522ef6289aa4d54583c701d52584242e",
"size": 6285,
"uri": "https://{canondata_backend}/937458/31b672b035d50dcb1b5f28743bbedc3d6401e486/resource.tar.gz#test.test_blocks-combine_hashed_minmax_double--Analyze_/plan.txt"
"checksum": "ed96fce91ec9eed1bda8c4428f6e0f2a",
"size": 6184,
"uri": "https://{canondata_backend}/1923547/eb397e7e75a7ff316191f787f130964fedc0010a/resource.tar.gz#test.test_blocks-combine_hashed_minmax_double--Analyze_/plan.txt"
}
],
"test.test[blocks-combine_hashed_minmax_double--Debug]": [
{
"checksum": "fea32346f8badeb913295879181f10de",
"size": 2662,
"uri": "https://{canondata_backend}/1942525/e82383a0853340bf9ac348d8e641aeedc7c24e1b/resource.tar.gz#test.test_blocks-combine_hashed_minmax_double--Debug_/opt.yql_patched"
"checksum": "e01e88e1444c41c1f8d21d1a5237e551",
"size": 2651,
"uri": "https://{canondata_backend}/1923547/eb397e7e75a7ff316191f787f130964fedc0010a/resource.tar.gz#test.test_blocks-combine_hashed_minmax_double--Debug_/opt.yql_patched"
}
],
"test.test[blocks-combine_hashed_minmax_double--Plan]": [
{
"checksum": "522ef6289aa4d54583c701d52584242e",
"size": 6285,
"uri": "https://{canondata_backend}/937458/31b672b035d50dcb1b5f28743bbedc3d6401e486/resource.tar.gz#test.test_blocks-combine_hashed_minmax_double--Plan_/plan.txt"
"checksum": "ed96fce91ec9eed1bda8c4428f6e0f2a",
"size": 6184,
"uri": "https://{canondata_backend}/1923547/eb397e7e75a7ff316191f787f130964fedc0010a/resource.tar.gz#test.test_blocks-combine_hashed_minmax_double--Plan_/plan.txt"
}
],
"test.test[blocks-combine_hashed_minmax_double--Results]": [],
"test.test[blocks-combine_hashed_set--Analyze]": [
{
"checksum": "741472e80da23a7b1e6c0c31ff42683f",
"size": 5955,
"uri": "https://{canondata_backend}/995452/4303db57e47a09cae11e8629ebf6e39558f3f239/resource.tar.gz#test.test_blocks-combine_hashed_set--Analyze_/plan.txt"
"checksum": "8e37a495395d396b51f75e9400f208cf",
"size": 5854,
"uri": "https://{canondata_backend}/1923547/eb397e7e75a7ff316191f787f130964fedc0010a/resource.tar.gz#test.test_blocks-combine_hashed_set--Analyze_/plan.txt"
}
],
"test.test[blocks-combine_hashed_set--Debug]": [
{
"checksum": "596c73b71938d8f69128fdb263ad2b91",
"size": 1885,
"uri": "https://{canondata_backend}/1784826/5dc930cd4ecffd67bdc527c9ec277464e97c3194/resource.tar.gz#test.test_blocks-combine_hashed_set--Debug_/opt.yql_patched"
"checksum": "e3f5652dd919c7ae5e35c6463089fd3f",
"size": 1874,
"uri": "https://{canondata_backend}/1923547/eb397e7e75a7ff316191f787f130964fedc0010a/resource.tar.gz#test.test_blocks-combine_hashed_set--Debug_/opt.yql_patched"
}
],
"test.test[blocks-combine_hashed_set--Plan]": [
{
"checksum": "741472e80da23a7b1e6c0c31ff42683f",
"size": 5955,
"uri": "https://{canondata_backend}/995452/4303db57e47a09cae11e8629ebf6e39558f3f239/resource.tar.gz#test.test_blocks-combine_hashed_set--Plan_/plan.txt"
"checksum": "8e37a495395d396b51f75e9400f208cf",
"size": 5854,
"uri": "https://{canondata_backend}/1923547/eb397e7e75a7ff316191f787f130964fedc0010a/resource.tar.gz#test.test_blocks-combine_hashed_set--Plan_/plan.txt"
}
],
"test.test[blocks-combine_hashed_set--Results]": [],
Expand Down
18 changes: 9 additions & 9 deletions ydb/library/yql/tests/sql/dq_file/part10/canondata/result.json
Original file line number Diff line number Diff line change
Expand Up @@ -442,23 +442,23 @@
],
"test.test[blocks-combine_all_avg_filter--Analyze]": [
{
"checksum": "3b810917db78e02e7b143f91a28a9c11",
"size": 5976,
"uri": "https://{canondata_backend}/1600758/32cfdeb8c6377a2e7e62c6c4adbb95f25af7669b/resource.tar.gz#test.test_blocks-combine_all_avg_filter--Analyze_/plan.txt"
"checksum": "f465fa6073c392ef44e4307515033931",
"size": 5875,
"uri": "https://{canondata_backend}/1936947/7492087a2990a4ea8139b91b9e07d28aa0e09aa4/resource.tar.gz#test.test_blocks-combine_all_avg_filter--Analyze_/plan.txt"
}
],
"test.test[blocks-combine_all_avg_filter--Debug]": [
{
"checksum": "02f87404f60fa06d179254415f3d0f3d",
"size": 2662,
"uri": "https://{canondata_backend}/1600758/32cfdeb8c6377a2e7e62c6c4adbb95f25af7669b/resource.tar.gz#test.test_blocks-combine_all_avg_filter--Debug_/opt.yql_patched"
"checksum": "b3d477dfe3808c59dba6540b4c4d0524",
"size": 2651,
"uri": "https://{canondata_backend}/1936947/7492087a2990a4ea8139b91b9e07d28aa0e09aa4/resource.tar.gz#test.test_blocks-combine_all_avg_filter--Debug_/opt.yql_patched"
}
],
"test.test[blocks-combine_all_avg_filter--Plan]": [
{
"checksum": "3b810917db78e02e7b143f91a28a9c11",
"size": 5976,
"uri": "https://{canondata_backend}/1600758/32cfdeb8c6377a2e7e62c6c4adbb95f25af7669b/resource.tar.gz#test.test_blocks-combine_all_avg_filter--Plan_/plan.txt"
"checksum": "f465fa6073c392ef44e4307515033931",
"size": 5875,
"uri": "https://{canondata_backend}/1936947/7492087a2990a4ea8139b91b9e07d28aa0e09aa4/resource.tar.gz#test.test_blocks-combine_all_avg_filter--Plan_/plan.txt"
}
],
"test.test[blocks-combine_all_avg_filter--Results]": [],
Expand Down
Loading