morrySnow commented on code in PR #31870:
URL: https://github.com/apache/doris/pull/31870#discussion_r1517079205


##########
fe/fe-core/src/main/java/org/apache/doris/nereids/rules/exploration/mv/AbstractMaterializedViewRule.java:
##########
@@ -259,27 +261,32 @@ protected List<Plan> doRewrite(StructInfo 
queryStructInfo, CascadesContext casca
      * Rewrite by rules and try to make output is the same after optimize by 
rules
      */
     protected Plan rewriteByRules(CascadesContext cascadesContext, Plan 
rewrittenPlan, Plan originPlan) {
+        List<Slot> originOutputs = originPlan.getOutput();
+        if (originOutputs.size() != rewrittenPlan.getOutput().size()) {
+            return null;
+        }
+        Map<Slot, ExprId> originSlotToRewrittenExprId = Maps.newHashMap();
+        for (int i = 0; i < originOutputs.size(); i++) {
+            originSlotToRewrittenExprId.put(originOutputs.get(i), 
rewrittenPlan.getOutput().get(i).getExprId());
+        }
         // run rbo job on mv rewritten plan
         CascadesContext rewrittenPlanContext = CascadesContext.initContext(
                 cascadesContext.getStatementContext(), rewrittenPlan,
                 
cascadesContext.getCurrentJobContext().getRequiredProperties());
         Rewriter.getWholeTreeRewriter(rewrittenPlanContext).execute();
         rewrittenPlan = rewrittenPlanContext.getRewritePlan();
-        List<Slot> originPlanOutput = originPlan.getOutput();
-        List<Slot> rewrittenPlanOutput = rewrittenPlan.getOutput();
-        if (originPlanOutput.size() != rewrittenPlanOutput.size()) {
-            return null;
-        }
-        List<NamedExpression> expressions = new ArrayList<>();
-        // should add project above rewritten plan if top plan is not project, 
if aggregate above will nu
-        if (!isOutputValid(originPlan, rewrittenPlan)) {
-            for (int i = 0; i < originPlanOutput.size(); i++) {
-                expressions.add(((NamedExpression) 
normalizeExpression(originPlanOutput.get(i),
-                        rewrittenPlanOutput.get(i))));
-            }
-            return new LogicalProject<>(expressions, rewrittenPlan, false);
+
+        // for get right nullable after rewritten, we need this map
+        Map<ExprId, Slot> exprIdToNewRewrittenSlot = Maps.newHashMap();
+        for (Slot slot : rewrittenPlan.getOutput()) {
+            exprIdToNewRewrittenSlot.put(slot.getExprId(), slot);

Review Comment:
   same



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscr...@doris.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscr...@doris.apache.org
For additional commands, e-mail: commits-h...@doris.apache.org

Reply via email to