From e863cfe5c7615619eab34c4f6a893a85b80c1a1b Mon Sep 17 00:00:00 2001 From: xzj7019 <131111794+xzj7019@users.noreply.github.com> Date: Thu, 28 Sep 2023 14:33:00 +0800 Subject: [PATCH] [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 --- .../translator/PhysicalPlanTranslator.java | 29 +++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/fe/fe-core/src/main/java/org/apache/doris/nereids/glue/translator/PhysicalPlanTranslator.java b/fe/fe-core/src/main/java/org/apache/doris/nereids/glue/translator/PhysicalPlanTranslator.java index 13ba9ef10f..b2f59fdb55 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/nereids/glue/translator/PhysicalPlanTranslator.java +++ b/fe/fe-core/src/main/java/org/apache/doris/nereids/glue/translator/PhysicalPlanTranslator.java @@ -287,6 +287,23 @@ public class PhysicalPlanTranslator extends DefaultPlanVisitor projectionExprs = new ArrayList<>(); + PhysicalCTEConsumer consumer = getCTEConsumerChild(distribute); + Preconditions.checkState(consumer != null, "consumer not found"); + for (Slot slot : distribute.getOutput()) { + projectionExprs.add(ExpressionTranslator.translate(consumer.getProducerSlot(slot), context)); + } + TupleDescriptor projectionTuple = generateTupleDesc(distribute.getOutput(), null, context); + dataStreamSink.setProjections(projectionExprs); + dataStreamSink.setOutputTupleDesc(projectionTuple); + } + } DataPartition dataPartition = toDataPartition(distribute.getDistributionSpec(), validOutputIds, context); PlanFragment parentFragment = new PlanFragment(context.nextFragmentId(), exchangeNode, dataPartition); exchangeNode.setNumInstances(inputFragment.getPlanRoot().getNumInstances()); @@ -2332,4 +2349,16 @@ public class PhysicalPlanTranslator extends DefaultPlanVisitor