seawinde commented on code in PR #28596:
URL: https://github.com/apache/doris/pull/28596#discussion_r1430933402


##########
fe/fe-core/src/main/java/org/apache/doris/nereids/rules/exploration/mv/AbstractMaterializedViewAggregateRule.java:
##########
@@ -226,14 +255,44 @@ protected Plan rewriteQueryByView(MatchMode matchMode,
     }
 
     // only support sum roll up, support other agg functions later.
-    private AggregateFunction rollup(AggregateFunction originFunction,
-            Expression mappedExpression) {
-        Class<? extends AggregateFunction> rollupAggregateFunction = 
originFunction.getRollup();
+    private Function rollup(AggregateFunction queryFunction,
+            Expression queryFunctionShuttled,
+            Map<Expression, Expression> mvExprToMvScanExprQueryBased) {
+        Expression rollupParam = null;
+        if (mvExprToMvScanExprQueryBased.containsKey(queryFunctionShuttled)) {
+            // function can not rewrite by view
+            rollupParam = 
mvExprToMvScanExprQueryBased.get(queryFunctionShuttled);
+        } else {
+            // try to use complex roll up param
+            // eg: query is count(distinct param), mv sql is 
bitmap_union(to_bitmap(param))
+            for (Expression mvExprShuttled : 
mvExprToMvScanExprQueryBased.keySet()) {
+                if (!(mvExprShuttled instanceof Function)) {
+                    continue;
+                }
+                if (isAggregateFunctionEquivalent(queryFunction, (Function) 
mvExprShuttled)) {
+                    rollupParam = 
mvExprToMvScanExprQueryBased.get(mvExprShuttled);
+                }
+            }
+        }
+        if (rollupParam == null) {
+            return null;
+        }
+        // do roll up
+        Class<? extends Function> rollupAggregateFunction = 
queryFunction.getRollup();
         if (rollupAggregateFunction == null) {
             return null;
         }
         if (Sum.class.isAssignableFrom(rollupAggregateFunction)) {
-            return new Sum(originFunction.isDistinct(), mappedExpression);
+            return new Sum(queryFunction.isDistinct(), rollupParam);
+        }
+        if (Max.class.isAssignableFrom(rollupAggregateFunction)) {
+            return new Max(queryFunction.isDistinct(), rollupParam);
+        }
+        if (Min.class.isAssignableFrom(rollupAggregateFunction)) {
+            return new Min(queryFunction.isDistinct(), rollupParam);
+        }
+        if (BitmapUnionCount.class.isAssignableFrom(rollupAggregateFunction)) {
+            return new BitmapUnionCount(rollupParam);

Review Comment:
   it's reasonable, i will fix it



-- 
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: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to