github-actions[bot] commented on code in PR #65368:
URL: https://github.com/apache/doris/pull/65368#discussion_r3567728925


##########
fe/fe-core/src/main/java/org/apache/doris/nereids/rules/rewrite/CheckMultiDistinct.java:
##########
@@ -42,43 +34,9 @@ public Rule build() {
     }
 
     private LogicalAggregate checkDistinct(LogicalAggregate<? extends Plan> 
aggregate) {
-        if (aggregate.getDistinctArguments().size() > 1) {
-
-            for (AggregateFunction func : aggregate.getAggregateFunctions()) {
-                if (func.isDistinct() && !(func instanceof 
SupportMultiDistinct)) {
-                    throw new AnalysisException(func.toString() + " can't 
support multi distinct.");
-                }
-            }
-        }
-
-        boolean distinctMultiColumns = false;
-        for (AggregateFunction func : aggregate.getAggregateFunctions()) {
-            if (!func.isDistinct()) {
-                continue;
-            }
-            if (func.arity() <= 1) {
-                continue;
-            }
-            for (int i = 1; i < func.arity(); i++) {
-                if (!func.child(i).getInputSlots().isEmpty() && 
!(func.child(i) instanceof OrderExpression)) {
-                    // think about group_concat(distinct col_1, ',')
-                    distinctMultiColumns = true;
-                    break;
-                }
-            }
-            if (distinctMultiColumns) {
-                break;
-            }
-        }
-
-        long distinctFunctionNum = 0;
-        for (AggregateFunction aggregateFunction : 
aggregate.getAggregateFunctions()) {
-            distinctFunctionNum += aggregateFunction.isDistinct() ? 1 : 0;
-        }
-
-        if (distinctMultiColumns && distinctFunctionNum > 1) {

Review Comment:
   This check now only counts distinct argument groups, but it no longer 
preserves the old guard for DISTINCT aggregates that have extra non-order input 
slots. For example, `group_concat(distinct a, sep_col)` reports only `a` from 
`GroupConcat.getDistinctArguments()`, so combining it with `count(distinct a)` 
now looks like a single group and passes this check. The split path then builds 
the lower dedup aggregate from `AggregateUtils.getDistinctNamedExpr()`, which 
uses `aggFunc.getArguments()` and therefore groups by both `a` and `sep_col`, 
and the upper aggregate strips DISTINCT. Rows with the same `a` but different 
`sep_col` survive deduplication, so `group_concat(distinct a, sep_col), 
count(distinct a)` can produce a non-distinct concat result. Please restore the 
old extra-input-slot rejection for multiple DISTINCT functions, or make the 
split use each function's real distinct key instead of all of its arguments.



##########
fe/fe-core/src/main/java/org/apache/doris/nereids/rules/rewrite/CheckMultiDistinct.java:
##########
@@ -42,43 +34,9 @@ public Rule build() {
     }
 
     private LogicalAggregate checkDistinct(LogicalAggregate<? extends Plan> 
aggregate) {
-        if (aggregate.getDistinctArguments().size() > 1) {
-
-            for (AggregateFunction func : aggregate.getAggregateFunctions()) {
-                if (func.isDistinct() && !(func instanceof 
SupportMultiDistinct)) {
-                    throw new AnalysisException(func.toString() + " can't 
support multi distinct.");
-                }
-            }
-        }
-
-        boolean distinctMultiColumns = false;
-        for (AggregateFunction func : aggregate.getAggregateFunctions()) {
-            if (!func.isDistinct()) {
-                continue;
-            }
-            if (func.arity() <= 1) {
-                continue;
-            }
-            for (int i = 1; i < func.arity(); i++) {
-                if (!func.child(i).getInputSlots().isEmpty() && 
!(func.child(i) instanceof OrderExpression)) {
-                    // think about group_concat(distinct col_1, ',')
-                    distinctMultiColumns = true;
-                    break;
-                }
-            }
-            if (distinctMultiColumns) {
-                break;
-            }
-        }
-
-        long distinctFunctionNum = 0;
-        for (AggregateFunction aggregateFunction : 
aggregate.getAggregateFunctions()) {
-            distinctFunctionNum += aggregateFunction.isDistinct() ? 1 : 0;
-        }
-
-        if (distinctMultiColumns && distinctFunctionNum > 1) {
+        if (AggregateUtils.distinctArgumentGroupCountUpToTwo(aggregate) > 1) {

Review Comment:
   This check now only counts distinct argument groups, but it no longer 
preserves the old guard for DISTINCT aggregates that have extra non-order input 
slots. For example, `group_concat(distinct a, sep_col)` reports only `a` from 
`GroupConcat.getDistinctArguments()`, so combining it with `count(distinct a)` 
now looks like a single group and passes this check. The split path then builds 
the lower dedup aggregate from `AggregateUtils.getDistinctNamedExpr()`, which 
uses `aggFunc.getArguments()` and therefore groups by both `a` and `sep_col`, 
and the upper aggregate strips DISTINCT. Rows with the same `a` but different 
`sep_col` survive deduplication, so `group_concat(distinct a, sep_col), 
count(distinct a)` can produce a non-distinct concat result. Please restore the 
old extra-input-slot rejection for multiple DISTINCT functions, or make the 
split use each function's real distinct key instead of all of its arguments.



-- 
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