seawinde commented on code in PR #34274: URL: https://github.com/apache/doris/pull/34274#discussion_r1595171169
########## fe/fe-core/src/main/java/org/apache/doris/nereids/rules/exploration/mv/AbstractMaterializedViewAggregateRule.java: ########## @@ -284,6 +285,26 @@ protected Plan rewriteQueryByView(MatchMode matchMode, } // add project to guarantee group by column ref is slot reference, // this is necessary because physical createHash will need slotReference later + for (Expression expression : queryChildrenGroupBySet) { + Expression queryGroupShuttledExpr = ExpressionUtils.shuttleExpressionWithLineage( + expression, queryTopPlan, queryStructInfo.getTableBitSet()); + AggregateExpressionRewriteContext context = new AggregateExpressionRewriteContext(true, + mvExprToMvScanExprQueryBased, queryTopPlan, queryStructInfo.getTableBitSet()); + // group by expression maybe group by a + b, so we need expression rewriter + Expression rewrittenGroupByExpression = queryGroupShuttledExpr.accept(AGGREGATE_EXPRESSION_REWRITER, + context); + if (!context.isValid()) { + // group expr can not rewrite by view + materializationContext.recordFailReason(queryStructInfo, + "View dimensions doesn't not cover the query dimensions in bottom agg ", + () -> String.format("mvExprToMvScanExprQueryBased is %s,\n queryGroupShuttledExpr is %s", + mvExprToMvScanExprQueryBased, queryGroupShuttledExpr)); + return null; + } + NamedExpression groupByExpression = rewrittenGroupByExpression instanceof NamedExpression + ? (NamedExpression) rewrittenGroupByExpression : new Alias(rewrittenGroupByExpression); + finalGroupExpressions.add(groupByExpression); Review Comment: After add the test case to [aggregate_with_roll_up.groovy](https://github.com/apache/doris/blob/master/regression-test/suites/nereids_rules_p0/mv/agg_with_roll_up/aggregate_with_roll_up.groovy) you can run the command as following to re generate aggregate_with_roll_up.out: `./run-regression-test.sh --run -d nereids_rules_p0/mv/agg_with_roll_up -s aggregate_with_roll_up -forceGenOut ` see regresson-test detail in [https://doris.apache.org/community/developer-guide/regression-testing](https://doris.apache.org/community/developer-guide/regression-testing) -- 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