@@ -128,32 +128,22 @@ TExprNode::TPtr RebuildArgumentsOnlyLambdaForBlocks(const TExprNode& lambda, TEx
128
128
129
129
TExprNode::TPtr OptimizeWideToBlocks (const TExprNode::TPtr& node, TExprContext& ctx, TTypeAnnotationContext& types) {
130
130
Y_UNUSED (types);
131
-
132
- // Static assert to ensure backward compatible change: if the
133
- // constant below is true, both input and output types of
134
- // WideToBlocks callable have to be WideStream; otherwise,
135
- // both input and output types have to be WideFlow.
136
- // FIXME: When all spots using WideToBlocks are adjusted
137
- // to work with WideStream, drop the assertion below.
138
- static_assert (!NYql::NBlockStreamIO::WideToBlocks);
139
-
140
131
const auto & input = node->Head ();
141
- if (input.IsCallable (" ToFlow" ) && input.Head ().IsCallable (" WideFromBlocks" )) {
142
- const auto & wideFromBlocks = input.Head ();
143
- // Technically, the code below rewrites the following sequence
144
- // (WideToBlocks (ToFlow (WideFromBlocks (<input>)))))
145
- // into (ReplicateScalars (<input>)), but ToFlow/FromFlow
146
- // wrappers will be removed when all other nodes in block
147
- // pipeline start using WideStream instead of the WideFlow.
148
- // Hence, the logging is left intact.
149
- YQL_CLOG (DEBUG, CorePeepHole) << " Drop " << node->Content () << " over " << wideFromBlocks.Content ();
132
+ if (input.IsCallable (" WideFromBlocks" )) {
133
+ YQL_CLOG (DEBUG, CorePeepHole) << " Drop " << node->Content () << " over " << input.Content ();
150
134
// If tail is FromFlow, its input is WideFlow and can be
151
135
// used intact; Otherwise the input is WideStream, so the
152
136
// new input should be converted to WideFlow.
153
- const auto tail = wideFromBlocks .HeadPtr ();
137
+ const auto tail = input .HeadPtr ();
154
138
const auto flowInput = tail->IsCallable (" FromFlow" ) ? tail->HeadPtr ()
155
139
: ctx.NewCallable (tail->Pos (), " ToFlow" , { tail });
156
- return ctx.NewCallable (node->Pos (), " ReplicateScalars" , { flowInput });
140
+ return ctx.Builder (node->Pos ())
141
+ .Callable (" FromFlow" )
142
+ .Callable (0 , " ReplicateScalars" )
143
+ .Add (0 , flowInput)
144
+ .Seal ()
145
+ .Seal ()
146
+ .Build ();
157
147
}
158
148
159
149
if (input.IsCallable ({" Extend" , " OrderedExtend" })) {
@@ -171,26 +161,10 @@ TExprNode::TPtr OptimizeWideToBlocks(const TExprNode::TPtr& node, TExprContext&
171
161
172
162
TExprNode::TPtr OptimizeWideFromBlocks (const TExprNode::TPtr& node, TExprContext& ctx, TTypeAnnotationContext& types) {
173
163
Y_UNUSED (types);
174
-
175
- // Static assert to ensure backward compatible change: if the
176
- // constant below is true, both input and output types of
177
- // WideToBlocks callable have to be WideStream; otherwise,
178
- // both input and output types have to be WideFlow.
179
- // FIXME: When all spots using WideToBlocks are adjusted
180
- // to work with WideStream, drop the assertion below.
181
- static_assert (!NYql::NBlockStreamIO::WideToBlocks);
182
-
183
164
const auto & input = node->Head ();
184
- if (input.IsCallable (" FromFlow" ) && input.Head ().IsCallable (" WideToBlocks" )) {
185
- const auto & wideToBlocks = input.Head ();
186
- // Technically, the code below rewrites the following sequence
187
- // (WideFromBlocks (FromFlow (WideToBlocks (<input>))))
188
- // into (FromFlow (<input>)) (to match the ToFlow parent),
189
- // but ToFlow/FromFlow wrappers will be removed when all
190
- // other nodes in block pipeline start using WideStream
191
- // instead of the WideFlow. Hence, the logging is left intact.
192
- YQL_CLOG (DEBUG, CorePeepHole) << " Drop " << node->Content () << " over " << wideToBlocks.Content ();
193
- return ctx.NewCallable (node->Pos (), " FromFlow" , {wideToBlocks.HeadPtr ()});
165
+ if (input.IsCallable (" WideToBlocks" )) {
166
+ YQL_CLOG (DEBUG, CorePeepHole) << " Drop " << node->Content () << " over " << input.Content ();
167
+ return input.HeadPtr ();
194
168
}
195
169
196
170
if (input.IsCallable (" FromFlow" ) && input.Head ().IsCallable (" ReplicateScalars" )) {
@@ -6268,22 +6242,17 @@ TExprNode::TPtr OptimizeWideMapBlocks(const TExprNode::TPtr& node, TExprContext&
6268
6242
6269
6243
YQL_CLOG (DEBUG, CorePeepHole) << " Convert " << node->Content () << " to blocks, extra nodes: " << newNodes
6270
6244
<< " , extra columns: " << rewritePositions.size ();
6271
-
6272
- // Static assert to ensure backward compatible change: if the
6273
- // constant below is true, both input and output types of
6274
- // WideToBlocks callable have to be WideStream; otherwise,
6275
- // both input and output types have to be WideFlow.
6276
- // FIXME: When all spots using WideToBlocks are adjusted
6277
- // to work with WideStream, drop the assertion below.
6278
- static_assert (!NYql::NBlockStreamIO::WideToBlocks);
6279
-
6280
6245
auto ret = ctx.Builder (node->Pos ())
6281
6246
.Callable (" ToFlow" )
6282
6247
.Callable (0 , " WideFromBlocks" )
6283
6248
.Callable (0 , " FromFlow" )
6284
6249
.Callable (0 , " WideMap" )
6285
- .Callable (0 , " WideToBlocks" )
6286
- .Add (0 , node->HeadPtr ())
6250
+ .Callable (0 , " ToFlow" )
6251
+ .Callable (0 , " WideToBlocks" )
6252
+ .Callable (0 , " FromFlow" )
6253
+ .Add (0 , node->HeadPtr ())
6254
+ .Seal ()
6255
+ .Seal ()
6287
6256
.Seal ()
6288
6257
.Add (1 , blockLambda)
6289
6258
.Seal ()
@@ -6318,18 +6287,14 @@ TExprNode::TPtr OptimizeWideFilterBlocks(const TExprNode::TPtr& node, TExprConte
6318
6287
return node;
6319
6288
}
6320
6289
6321
- // Static assert to ensure backward compatible change: if the
6322
- // constant below is true, both input and output types of
6323
- // WideToBlocks callable have to be WideStream; otherwise,
6324
- // both input and output types have to be WideFlow.
6325
- // FIXME: When all spots using WideToBlocks are adjusted
6326
- // to work with WideStream, drop the assertion below.
6327
- static_assert (!NYql::NBlockStreamIO::WideToBlocks);
6328
-
6329
6290
auto blockMapped = ctx.Builder (node->Pos ())
6330
6291
.Callable (" WideMap" )
6331
- .Callable (0 , " WideToBlocks" )
6332
- .Add (0 , node->HeadPtr ())
6292
+ .Callable (0 , " ToFlow" )
6293
+ .Callable (0 , " WideToBlocks" )
6294
+ .Callable (0 , " FromFlow" )
6295
+ .Add (0 , node->HeadPtr ())
6296
+ .Seal ()
6297
+ .Seal ()
6333
6298
.Seal ()
6334
6299
.Add (1 , blockLambda)
6335
6300
.Seal ()
@@ -6446,22 +6411,17 @@ TExprNode::TPtr OptimizeSkipTakeToBlocks(const TExprNode::TPtr& node, TExprConte
6446
6411
6447
6412
TStringBuf newName = node->Content () == " Skip" ? " WideSkipBlocks" : " WideTakeBlocks" ;
6448
6413
YQL_CLOG (DEBUG, CorePeepHole) << " Convert " << node->Content () << " to " << newName;
6449
-
6450
- // Static assert to ensure backward compatible change: if the
6451
- // constant below is true, both input and output types of
6452
- // WideToBlocks callable have to be WideStream; otherwise,
6453
- // both input and output types have to be WideFlow.
6454
- // FIXME: When all spots using WideToBlocks are adjusted
6455
- // to work with WideStream, drop the assertion below.
6456
- static_assert (!NYql::NBlockStreamIO::WideToBlocks);
6457
-
6458
6414
return ctx.Builder (node->Pos ())
6459
6415
.Callable (" ToFlow" )
6460
6416
.Callable (0 , " WideFromBlocks" )
6461
6417
.Callable (0 , " FromFlow" )
6462
6418
.Callable (0 , newName)
6463
- .Callable (0 , " WideToBlocks" )
6464
- .Add (0 , node->HeadPtr ())
6419
+ .Callable (0 , " ToFlow" )
6420
+ .Callable (0 , " WideToBlocks" )
6421
+ .Callable (0 , " FromFlow" )
6422
+ .Add (0 , node->HeadPtr ())
6423
+ .Seal ()
6424
+ .Seal ()
6465
6425
.Seal ()
6466
6426
.Add (1 , node->ChildPtr (1 ))
6467
6427
.Seal ()
@@ -6504,16 +6464,15 @@ TExprNode::TPtr OptimizeTopOrSortBlocks(const TExprNode::TPtr& node, TExprContex
6504
6464
TString newName = node->Content () + TString (" Blocks" );
6505
6465
YQL_CLOG (DEBUG, CorePeepHole) << " Convert " << node->Content () << " to " << newName;
6506
6466
auto children = node->ChildrenList ();
6507
-
6508
- // Static assert to ensure backward compatible change: if the
6509
- // constant below is true, both input and output types of
6510
- // WideToBlocks callable have to be WideStream; otherwise,
6511
- // both input and output types have to be WideFlow.
6512
- // FIXME: When all spots using WideToBlocks are adjusted
6513
- // to work with WideStream, drop the assertion below.
6514
- static_assert (!NYql::NBlockStreamIO::WideToBlocks);
6515
-
6516
- children[0 ] = ctx.NewCallable (node->Pos (), " WideToBlocks" , { children[0 ] });
6467
+ children[0 ] = ctx.Builder (node->Pos ())
6468
+ .Callable (" ToFlow" )
6469
+ .Callable (0 , " WideToBlocks" )
6470
+ .Callable (0 , " FromFlow" )
6471
+ .Add (0 , children[0 ])
6472
+ .Seal ()
6473
+ .Seal ()
6474
+ .Seal ()
6475
+ .Build ();
6517
6476
return ctx.Builder (node->Pos ())
6518
6477
.Callable (" ToFlow" )
6519
6478
.Callable (0 , " WideFromBlocks" )
@@ -6726,27 +6685,46 @@ TExprNode::TPtr OptimizeWideMaps(const TExprNode::TPtr& node, TExprContext& ctx)
6726
6685
.Seal ()
6727
6686
.Add (1 , DropUnusedArgs (node->Tail (), unused, ctx))
6728
6687
.Seal ().Build ();
6729
- } else if (input.IsCallable (" WideToBlocks" )) {
6730
- // Static assert to ensure backward compatible change: if the
6731
- // constant below is true, both input and output types of
6732
- // WideToBlocks callable have to be WideStream; otherwise,
6733
- // both input and output types have to be WideFlow.
6734
- // FIXME: When all spots using WideToBlocks are adjusted
6735
- // to work with WideStream, drop the assertion below.
6736
- static_assert (!NYql::NBlockStreamIO::WideToBlocks);
6737
-
6688
+ } else if (input.IsCallable (" ToFlow" ) && input.Head ().IsCallable (" WideToBlocks" )) {
6738
6689
auto actualUnused = unused;
6739
6690
if (actualUnused.back () + 1U == node->Tail ().Head ().ChildrenSize ())
6740
6691
actualUnused.pop_back ();
6741
6692
if (!actualUnused.empty ()) {
6742
- YQL_CLOG (DEBUG, CorePeepHole) << node->Content () << " over " << input.Content () << " with " << actualUnused.size () << " unused fields." ;
6693
+ const auto & wideToBlocks = input.Head ();
6694
+ // WideToBlocks uses WideStream instead of WideFlow,
6695
+ // so it's wrapped with ToFlow/FromFlow. Hence, to drop
6696
+ // unused fields for particular WideToBlocks node,
6697
+ // the optimizer has to rewrite FromFlow child, but
6698
+ // logging is left intact.
6699
+ YQL_CLOG (DEBUG, CorePeepHole) << node->Content () << " over " << wideToBlocks.Content () << " with " << actualUnused.size () << " unused fields." ;
6700
+ const auto tail = wideToBlocks.HeadPtr ();
6701
+ const auto width = tail->GetTypeAnn ()->Cast <TStreamExprType>()->GetItemType ()->Cast <TMultiExprType>()->GetSize ();
6702
+ const auto flowInput = tail->IsCallable (" FromFlow" ) ? tail->HeadPtr ()
6703
+ : ctx.NewCallable (tail->Pos (), " ToFlow" , { tail });
6743
6704
return ctx.Builder (node->Pos ())
6744
6705
.Callable (node->Content ())
6745
- .Callable (0 , input.Content ())
6746
- .Add (0 , MakeWideMapForDropUnused (input.HeadPtr (), actualUnused, ctx))
6706
+ .Callable (0 , " ToFlow" )
6707
+ .Callable (0 , " WideToBlocks" )
6708
+ .Callable (0 , " FromFlow" )
6709
+ .Callable (0 , " WideMap" )
6710
+ .Add (0 , flowInput)
6711
+ .Lambda (1 )
6712
+ .Params (" items" , width)
6713
+ .Do ([&](TExprNodeBuilder& parent) -> TExprNodeBuilder& {
6714
+ for (auto i = 0U , j = 0U ; i < width; ++i) {
6715
+ if (unused.cend () == std::find (unused.cbegin (), unused.cend (), i))
6716
+ parent.Arg (j++, " items" , i);
6717
+ }
6718
+ return parent;
6719
+ })
6720
+ .Seal ()
6721
+ .Seal ()
6722
+ .Seal ()
6723
+ .Seal ()
6747
6724
.Seal ()
6748
6725
.Add (1 , DropUnusedArgs (node->Tail (), actualUnused, ctx))
6749
- .Seal ().Build ();
6726
+ .Seal ()
6727
+ .Build ();
6750
6728
}
6751
6729
} else if (input.IsCallable (" ToFlow" ) && input.Head ().IsCallable (" WideFromBlocks" )) {
6752
6730
const auto & wideFromBlocks = input.Head ();
0 commit comments