Skip to content

Commit 0ea5271

Browse files
loochekblinkov
authored andcommitted
Drop aux columns that are not expected after row spec rebuild in AssumeConstraints
commit_hash:2326ce8e0746c8c27bc555fc4cb552116a6da32d
1 parent b7405d4 commit 0ea5271

File tree

5 files changed

+118
-0
lines changed

5 files changed

+118
-0
lines changed

yt/yql/providers/yt/provider/phy_opt/yql_yt_phy_opt_sort.cpp

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -667,11 +667,60 @@ TMaybeNode<TExprBase> TYtPhysicalOptProposalTransformer::AssumeConstraints(TExpr
667667
const size_t index = FromString(input.Cast<TYtOutput>().OutIndex().Value());
668668
TYtOutTableInfo outTable(op.Output().Item(index));
669669
if (builder) {
670+
YQL_ENSURE(!builder->NeedMap());
670671
builder->FillRowSpecSort(*outTable.RowSpec);
671672
}
672673
outTable.RowSpec->SetConstraints(assume.Ref().GetConstraintSet());
673674
outTable.SetUnique(assume.Ref().GetConstraint<TDistinctConstraintNode>(), assume.Pos(), ctx);
674675

676+
if (op.Maybe<TYtMap>() || op.Maybe<TYtReduce>()) {
677+
TExprNode::TPtr lambda;
678+
size_t childToReplace = 0;
679+
if (auto map = op.Maybe<TYtMap>()) {
680+
lambda = map.Cast().Mapper().Ptr();
681+
childToReplace = TYtMap::idx_Mapper;
682+
} else if (auto reduce = op.Maybe<TYtReduce>()) {
683+
lambda = reduce.Cast().Reducer().Ptr();
684+
childToReplace = TYtReduce::idx_Reducer;
685+
} else {
686+
YQL_ENSURE(false, "unexpected operation");
687+
}
688+
689+
auto actualLambdaOutputType = TCoLambda(lambda).Body().Ref().GetTypeAnn();
690+
auto expectedLambdaOutputType = outTable.RowSpec->GetExtendedType(ctx);
691+
if (!IsSameAnnotation(*actualLambdaOutputType, *expectedLambdaOutputType)) {
692+
// Drop aux columns that are not expected after row spec rebuild
693+
694+
auto excludeLambda = Build<TCoLambda>(ctx, lambda->Pos())
695+
.Args({"stream"})
696+
.Body<TCoOrderedMap>()
697+
.Input("stream")
698+
.Lambda<TCoLambda>()
699+
.Args({"struct"})
700+
.Body<TCoCastStruct>()
701+
.Struct("struct")
702+
.Type(ExpandType(lambda->Pos(), *expectedLambdaOutputType, ctx))
703+
.Build()
704+
.Build()
705+
.Build()
706+
.Done();
707+
708+
lambda = Build<TCoLambda>(ctx, lambda->Pos())
709+
.Args({"stream"})
710+
.Body<TExprApplier>()
711+
.Apply(excludeLambda)
712+
.With<TExprApplier>(0)
713+
.Apply(TCoLambda(lambda))
714+
.With(0, "stream")
715+
.Build()
716+
.Build()
717+
.Done()
718+
.Ptr();
719+
720+
newOp = ctx.ChangeChild(*newOp, childToReplace, std::move(lambda));
721+
}
722+
}
723+
675724
TVector<TYtOutTable> outputs;
676725
for (size_t i = 0; i < op.Output().Size(); ++i) {
677726
if (index == i) {
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{"_yql_column_0"="\xE0\xCC\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFE";"key2"=3;"key1"=3;};
2+
{"_yql_column_0"="\xE0\xCD\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFE";"key2"=2;"key1"=2;};
3+
{"_yql_column_0"="\xE0\xCE\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFE";"key2"=1;"key1"=1;};
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
{
2+
"_yql_row_spec" = {
3+
"Constraints" = {
4+
"Sorted" = [
5+
[
6+
[
7+
"key1";
8+
];
9+
%false;
10+
];
11+
[
12+
[
13+
"key2";
14+
];
15+
%true;
16+
];
17+
];
18+
};
19+
"SortDirections" = [
20+
0;
21+
1;
22+
];
23+
"SortMembers" = [
24+
"key1";
25+
"key2";
26+
];
27+
"SortedBy" = [
28+
"_yql_column_0";
29+
"key2";
30+
];
31+
"SortedByTypes" = [
32+
[
33+
"DataType";
34+
"String";
35+
];
36+
[
37+
"DataType";
38+
"Int32";
39+
];
40+
];
41+
"Type" = [
42+
"StructType";
43+
[
44+
[
45+
"key1";
46+
[
47+
"DataType";
48+
"Int32";
49+
];
50+
];
51+
[
52+
"key2";
53+
[
54+
"DataType";
55+
"Int32";
56+
];
57+
];
58+
];
59+
];
60+
};
61+
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
in Input input_sorted_desc.txt
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
/* postgres can not */
2+
USE plato;
3+
4+
SELECT * FROM Input WHERE key2 = 2 ASSUME ORDER BY key2;

0 commit comments

Comments
 (0)