@@ -991,6 +991,7 @@ class TYtPhysicalFinalizingTransformer : public TSyncTransformerBase {
991
991
}
992
992
993
993
bool isFill = false ;
994
+ bool isYtDqProcessWrite = false ;
994
995
int lambdaIdx = -1 ;
995
996
TExprNode::TPtr lambda;
996
997
if (TYtMap::Match (&node)) {
@@ -1000,6 +1001,9 @@ class TYtPhysicalFinalizingTransformer : public TSyncTransformerBase {
1000
1001
} else if (TYtFill::Match (&node)) {
1001
1002
lambdaIdx = TYtFill::idx_Content;
1002
1003
isFill = true ;
1004
+ } else if (TYtDqProcessWrite::Match (&node)) {
1005
+ lambdaIdx = TYtDqProcessWrite::idx_Input;
1006
+ isYtDqProcessWrite = true ;
1003
1007
}
1004
1008
if (-1 != lambdaIdx && !hasOtherSortedOuts) {
1005
1009
if (isFill) {
@@ -1013,20 +1017,46 @@ class TYtPhysicalFinalizingTransformer : public TSyncTransformerBase {
1013
1017
.Build ()
1014
1018
.Done ().Ptr ();
1015
1019
}
1020
+ } else if (isYtDqProcessWrite) {
1021
+ TProcessedNodesSet processedNodes;
1022
+ TNodeOnNodeOwnedMap remaps;
1023
+ VisitExpr (node.ChildPtr (lambdaIdx), [&processedNodes, &remaps, &ctx](const TExprNode::TPtr& n) {
1024
+ if (TYtOutput::Match (n.Get ())) {
1025
+ // Stop traversing dependent operations
1026
+ processedNodes.insert (n->UniqueId ());
1027
+ return false ;
1028
+ }
1029
+ if (TYtDqWrite::Match (n.Get ())) {
1030
+ auto newInput = Build<TCoUnordered>(ctx, n->Pos ())
1031
+ .Input (n->ChildPtr (TYtDqWrite::idx_Input))
1032
+ .Done ();
1033
+ remaps[n.Get ()] = ctx.ChangeChild (*n, TYtDqWrite::idx_Input, newInput.Ptr ());
1034
+ }
1035
+ return true ;
1036
+ });
1037
+ if (!remaps.empty ()) {
1038
+ TOptimizeExprSettings settings{State_->Types };
1039
+ settings.ProcessedNodes = &processedNodes;
1040
+ auto status = RemapExpr (node.ChildPtr (lambdaIdx), lambda, remaps, ctx, settings);
1041
+ if (status.Level == IGraphTransformer::TStatus::Error) {
1042
+ return {};
1043
+ }
1044
+ }
1045
+
1016
1046
} else {
1017
1047
TProcessedNodesSet processedNodes;
1018
1048
TNodeOnNodeOwnedMap remaps;
1019
- VisitExpr (node.ChildPtr (lambdaIdx), [&processedNodes, &remaps, &ctx](const TExprNode::TPtr& node ) {
1020
- if (TYtOutput::Match (node .Get ())) {
1049
+ VisitExpr (node.ChildPtr (lambdaIdx), [&processedNodes, &remaps, &ctx](const TExprNode::TPtr& n ) {
1050
+ if (TYtOutput::Match (n .Get ())) {
1021
1051
// Stop traversing dependent operations
1022
- processedNodes.insert (node ->UniqueId ());
1052
+ processedNodes.insert (n ->UniqueId ());
1023
1053
return false ;
1024
1054
}
1025
- auto name = node ->Content ();
1026
- if (node ->IsCallable () && node ->ChildrenSize () > 0 && name.SkipPrefix (" Ordered" )) {
1027
- const auto inputKind = node ->Child (0 )->GetTypeAnn ()->GetKind ();
1055
+ auto name = n ->Content ();
1056
+ if (n ->IsCallable () && n ->ChildrenSize () > 0 && name.SkipPrefix (" Ordered" )) {
1057
+ const auto inputKind = n ->Child (0 )->GetTypeAnn ()->GetKind ();
1028
1058
if (inputKind == ETypeAnnotationKind::Stream || inputKind == ETypeAnnotationKind::Flow) {
1029
- remaps[node .Get ()] = ctx.RenameNode (*node , name);
1059
+ remaps[n .Get ()] = ctx.RenameNode (*n , name);
1030
1060
}
1031
1061
}
1032
1062
return true ;
@@ -1052,17 +1082,13 @@ class TYtPhysicalFinalizingTransformer : public TSyncTransformerBase {
1052
1082
}
1053
1083
1054
1084
if (lambdaIdx != -1 && AnyOf (filterColumns, [](const TExprNode::TPtr& p) { return !!p; })) {
1055
- if (!lambda) {
1056
- lambda = node.ChildPtr (lambdaIdx);
1057
- }
1085
+
1086
+ TExprNode::TPtr extractLambda;
1058
1087
if (op.Output ().Size () == 1 ) {
1059
- lambda = Build<TCoLambda>(ctx, lambda->Pos ())
1088
+ extractLambda = Build<TCoLambda>(ctx, lambda->Pos ())
1060
1089
.Args ({" stream" })
1061
1090
.Body <TCoExtractMembers>()
1062
- .Input <TExprApplier>()
1063
- .Apply (TCoLambda (lambda))
1064
- .With (0 , " stream" )
1065
- .Build ()
1091
+ .Input (" stream" )
1066
1092
.Members (filterColumns[0 ])
1067
1093
.Build ()
1068
1094
.Done ().Ptr ();
@@ -1103,14 +1129,11 @@ class TYtPhysicalFinalizingTransformer : public TSyncTransformerBase {
1103
1129
}
1104
1130
}
1105
1131
1106
- lambda = Build<TCoLambda>(ctx, lambda->Pos ())
1132
+ extractLambda = Build<TCoLambda>(ctx, lambda->Pos ())
1107
1133
.Args ({" stream" })
1108
1134
.Body <TCoFlatMapBase>()
1109
1135
.CallableName (hasOtherSortedOuts ? TCoOrderedFlatMap::CallableName () : TCoFlatMap::CallableName ())
1110
- .Input <TExprApplier>()
1111
- .Apply (TCoLambda (lambda))
1112
- .With (0 , " stream" )
1113
- .Build ()
1136
+ .Input (" stream" )
1114
1137
.Lambda ()
1115
1138
.Args ({" var" })
1116
1139
.Body <TCoJust>()
@@ -1125,6 +1148,44 @@ class TYtPhysicalFinalizingTransformer : public TSyncTransformerBase {
1125
1148
.Build ()
1126
1149
.Done ().Ptr ();
1127
1150
}
1151
+
1152
+
1153
+ if (!lambda) {
1154
+ lambda = node.ChildPtr (lambdaIdx);
1155
+ }
1156
+ if (isYtDqProcessWrite) {
1157
+ TProcessedNodesSet processedNodes;
1158
+ TNodeOnNodeOwnedMap remaps;
1159
+ VisitExpr (lambda, [&processedNodes, &remaps, extractLambda, &ctx](const TExprNode::TPtr& n) {
1160
+ if (TYtOutput::Match (n.Get ())) {
1161
+ // Stop traversing dependent operations
1162
+ processedNodes.insert (n->UniqueId ());
1163
+ return false ;
1164
+ }
1165
+ if (auto dqWrite = TMaybeNode<TYtDqWrite>(n)) {
1166
+ auto newWrite = Build<TYtDqWrite>(ctx, n->Pos ())
1167
+ .InitFrom (dqWrite.Cast ())
1168
+ .Input <TExprApplier>()
1169
+ .Apply (TCoLambda (extractLambda))
1170
+ .With (0 , dqWrite.Cast ().Input ())
1171
+ .Build ()
1172
+ .Done ();
1173
+ remaps[n.Get ()] = newWrite.Ptr ();
1174
+ }
1175
+ return true ;
1176
+ });
1177
+ if (!remaps.empty ()) {
1178
+ TOptimizeExprSettings settings{State_->Types };
1179
+ settings.ProcessedNodes = &processedNodes;
1180
+ auto status = RemapExpr (lambda, lambda, remaps, ctx, settings);
1181
+ if (status.Level == IGraphTransformer::TStatus::Error) {
1182
+ return {};
1183
+ }
1184
+ }
1185
+
1186
+ } else {
1187
+ lambda = ctx.FuseLambdas (*extractLambda, *lambda);
1188
+ }
1128
1189
}
1129
1190
}
1130
1191
0 commit comments