Skip to content

Commit e863cfe

Browse files
authored
[fix](nereids) fix multi window projection issue temporarily (#24912)
Current multi-window plan generation has problem on the project sequence, for example: +--LogicalWindow ( windowExpressions=[avg(sum_sales#115) WindowSpec(...) AS `avg_monthly_sales`#116, rank() WindowSpec(...) AS `rn`#117], ...) and correspond physical plan is: +--PhysicalWindow[6572]@16 ( windowFrameGroup=(Funcs=[avg(sum_sales#115) WindowSpec(...) AS `avg_monthly_sales`#116], ... ) +--PhysicalWindow[6568]@29 ( windowFrameGroup=(Funcs=[rank() WindowSpec(...) AS `rn`#117], ...] ) If the final plan is generated as following: MultiCastDataSinks STREAM DATA SINK EXCHANGE ID: 20 HASH_PARTITIONED: rn[#208], i_brand[#202], cc_name[#203], i_category[#201] Before we eventually resolve the multi-window issue, we add a projection as following and force a mapping but this will not cover all potential problems. MultiCastDataSinks STREAM DATA SINK EXCHANGE ID: 20 HASH_PARTITIONED: rn[#219], i_brand[#213], cc_name[#214], i_category[#212] PROJECTIONS: i_category[#184], i_brand[#185], cc_name[#186], d_year[#187], d_moy[#188], sum_sales[#189], avg_monthly_sales[#191], rn[#190] PROJECTION TUPLE: 20
1 parent f5c38b2 commit e863cfe

1 file changed

Lines changed: 29 additions & 0 deletions

File tree

‎fe/fe-core/src/main/java/org/apache/doris/nereids/glue/translator/PhysicalPlanTranslator.java‎

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -287,6 +287,23 @@ public PlanFragment visitPhysicalDistribute(PhysicalDistribute<? extends Plan> d
287287
keys.addAll(validOutputIds);
288288
validOutputIds = keys;
289289
}
290+
if (inputFragment instanceof MultiCastPlanFragment) {
291+
// TODO: remove this logic when we split to multi-window in logical window to physical window conversion
292+
MultiCastDataSink multiCastDataSink = (MultiCastDataSink) inputFragment.getSink();
293+
DataStreamSink dataStreamSink = multiCastDataSink.getDataStreamSinks().get(
294+
multiCastDataSink.getDataStreamSinks().size() - 1);
295+
if (!(distribute.child() instanceof PhysicalProject)) {
296+
List<Expr> projectionExprs = new ArrayList<>();
297+
PhysicalCTEConsumer consumer = getCTEConsumerChild(distribute);
298+
Preconditions.checkState(consumer != null, "consumer not found");
299+
for (Slot slot : distribute.getOutput()) {
300+
projectionExprs.add(ExpressionTranslator.translate(consumer.getProducerSlot(slot), context));
301+
}
302+
TupleDescriptor projectionTuple = generateTupleDesc(distribute.getOutput(), null, context);
303+
dataStreamSink.setProjections(projectionExprs);
304+
dataStreamSink.setOutputTupleDesc(projectionTuple);
305+
}
306+
}
290307
DataPartition dataPartition = toDataPartition(distribute.getDistributionSpec(), validOutputIds, context);
291308
PlanFragment parentFragment = new PlanFragment(context.nextFragmentId(), exchangeNode, dataPartition);
292309
exchangeNode.setNumInstances(inputFragment.getPlanRoot().getNumInstances());
@@ -2332,4 +2349,16 @@ private boolean isComplexDataType(DataType dataType) {
23322349
return dataType instanceof ArrayType || dataType instanceof MapType || dataType instanceof JsonType
23332350
|| dataType instanceof StructType;
23342351
}
2352+
2353+
private PhysicalCTEConsumer getCTEConsumerChild(PhysicalPlan root) {
2354+
if (root == null) {
2355+
return null;
2356+
} else if (root instanceof PhysicalCTEConsumer) {
2357+
return (PhysicalCTEConsumer) root;
2358+
} else if (root.children().size() != 1) {
2359+
return null;
2360+
} else {
2361+
return getCTEConsumerChild((PhysicalPlan) root.child(0));
2362+
}
2363+
}
23352364
}

0 commit comments

Comments
 (0)