From 0dd2bc28719f7bc555b8a2fdbd1760d5a8642971 Mon Sep 17 00:00:00 2001 From: feiniaofeiafei Date: Sun, 21 Sep 2025 23:03:50 +0800 Subject: [PATCH 1/5] fix --- .../doris/nereids/rules/rewrite/DistinctAggregateRewriter.java | 2 +- .../suites/nereids_rules_p0/agg_strategy/agg_strategy.groovy | 2 ++ 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/fe/fe-core/src/main/java/org/apache/doris/nereids/rules/rewrite/DistinctAggregateRewriter.java b/fe/fe-core/src/main/java/org/apache/doris/nereids/rules/rewrite/DistinctAggregateRewriter.java index e34d56d383c6da..1f118066d8dce3 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/nereids/rules/rewrite/DistinctAggregateRewriter.java +++ b/fe/fe-core/src/main/java/org/apache/doris/nereids/rules/rewrite/DistinctAggregateRewriter.java @@ -84,7 +84,7 @@ public List buildRules() { .toRule(RuleType.DISTINCT_AGGREGATE_SPLIT), logicalAggregate() .when(agg -> agg.getGroupByExpressions().isEmpty() - && agg.mustUseMultiDistinctAgg()) + && agg.mustUseMultiDistinctAgg() && !AggregateUtils.containsCountDistinctMultiExpr(agg)) .then(this::convertToMultiDistinct) .toRule(RuleType.PROCESS_SCALAR_AGG_MUST_USE_MULTI_DISTINCT) ); diff --git a/regression-test/suites/nereids_rules_p0/agg_strategy/agg_strategy.groovy b/regression-test/suites/nereids_rules_p0/agg_strategy/agg_strategy.groovy index 2c70208e69f1a9..aab08847dff631 100644 --- a/regression-test/suites/nereids_rules_p0/agg_strategy/agg_strategy.groovy +++ b/regression-test/suites/nereids_rules_p0/agg_strategy/agg_strategy.groovy @@ -139,4 +139,6 @@ suite("agg_strategy") { qt_group_concat_distinct_key_is_varchar_and_distribute_key """explain shape plan select group_concat(distinct dst_key1 ,' ') from t_gbykey_10_dstkey_10_1000_dst_key1;""" + + // multi_distinct and count distinct multi expr } \ No newline at end of file From 3e2f62ea041058796df3d630c3918d190081d0a5 Mon Sep 17 00:00:00 2001 From: feiniaofeiafei Date: Mon, 22 Sep 2025 12:23:15 +0800 Subject: [PATCH 2/5] fix --- .../rules/analysis/NormalizeAggregate.java | 7 +- .../functions/agg/MultiDistinctCount.java | 21 +-- .../agg/MultiDistinctGroupConcat.java | 26 +-- .../functions/agg/MultiDistinctSum.java | 26 +-- .../functions/agg/MultiDistinctSum0.java | 23 +-- .../functions/agg/MultiDistinction.java | 1 - .../agg_strategy/agg_strategy.out | 19 ++ .../nereids_rules_p0/agg_strategy/test1.out | 162 ++++++++++++++++++ .../agg_strategy/agg_strategy.groovy | 13 ++ .../nereids_rules_p0/agg_strategy/load.groovy | 2 +- 10 files changed, 209 insertions(+), 91 deletions(-) create mode 100644 regression-test/data/nereids_rules_p0/agg_strategy/test1.out diff --git a/fe/fe-core/src/main/java/org/apache/doris/nereids/rules/analysis/NormalizeAggregate.java b/fe/fe-core/src/main/java/org/apache/doris/nereids/rules/analysis/NormalizeAggregate.java index 80fb39866437bb..fa64f70d53a8cd 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/nereids/rules/analysis/NormalizeAggregate.java +++ b/fe/fe-core/src/main/java/org/apache/doris/nereids/rules/analysis/NormalizeAggregate.java @@ -37,7 +37,6 @@ import org.apache.doris.nereids.trees.expressions.WindowExpression; import org.apache.doris.nereids.trees.expressions.functions.agg.AggregateFunction; import org.apache.doris.nereids.trees.expressions.functions.agg.AnyValue; -import org.apache.doris.nereids.trees.expressions.functions.agg.MultiDistinction; import org.apache.doris.nereids.trees.expressions.literal.Literal; import org.apache.doris.nereids.trees.expressions.literal.TinyIntLiteral; import org.apache.doris.nereids.trees.plans.Plan; @@ -273,11 +272,7 @@ private LogicalPlan normalizeAgg(LogicalAggregate aggregate, Optional aggOutput = normalizedAggOutputBuilder.build(); ImmutableList.Builder newAggOutputBuilder = ImmutableList.builderWithExpectedSize(aggOutput.size()); - for (NamedExpression output : aggOutput) { - Expression rewrittenExpr = output.rewriteDownShortCircuit( - e -> e instanceof MultiDistinction ? ((MultiDistinction) e).withMustUseMultiDistinctAgg(true) : e); - newAggOutputBuilder.add((NamedExpression) rewrittenExpr); - } + newAggOutputBuilder.addAll(aggOutput); ImmutableList normalizedAggOutput = newAggOutputBuilder.build(); // create upper projects by normalize all output exprs in old LogicalAggregate diff --git a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/agg/MultiDistinctCount.java b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/agg/MultiDistinctCount.java index cdafbef9528fb5..bb82b25a635c15 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/agg/MultiDistinctCount.java +++ b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/agg/MultiDistinctCount.java @@ -40,7 +40,6 @@ public class MultiDistinctCount extends NotNullableAggregateFunction public static final List SIGNATURES = ImmutableList.of( FunctionSignature.ret(BigIntType.INSTANCE).varArgs(AnyDataType.INSTANCE_WITHOUT_INDEX) ); - private final boolean mustUseMultiDistinctAgg; // MultiDistinctCount is created in AggregateStrategies phase // can't change getSignatures to use type coercion rule to add a cast expr @@ -50,28 +49,26 @@ public MultiDistinctCount(Expression arg0, Expression... varArgs) { } public MultiDistinctCount(boolean distinct, Expression arg0, Expression... varArgs) { - this(false, false, ExpressionUtils.mergeArguments(arg0, varArgs)); + this(false, ExpressionUtils.mergeArguments(arg0, varArgs)); } - private MultiDistinctCount(boolean mustUseMultiDistinctAgg, boolean distinct, List children) { + private MultiDistinctCount(boolean distinct, List children) { super("multi_distinct_count", false, children .stream() .map(arg -> !(arg instanceof Unbound) && arg.getDataType() instanceof DateLikeType ? new Cast(arg, BigIntType.INSTANCE) : arg) .collect(ImmutableList.toImmutableList())); - this.mustUseMultiDistinctAgg = mustUseMultiDistinctAgg; } /** constructor for withChildren and reuse signature */ - protected MultiDistinctCount(boolean mustUseMultiDistinctAgg, AggregateFunctionParams functionParams) { + protected MultiDistinctCount(AggregateFunctionParams functionParams) { super(functionParams); - this.mustUseMultiDistinctAgg = mustUseMultiDistinctAgg; } @Override public MultiDistinctCount withDistinctAndChildren(boolean distinct, List children) { Preconditions.checkArgument(!children.isEmpty()); - return new MultiDistinctCount(mustUseMultiDistinctAgg, getFunctionParams(false, children)); + return new MultiDistinctCount(getFunctionParams(false, children)); } @Override @@ -84,16 +81,6 @@ public List getSignatures() { return SIGNATURES; } - @Override - public boolean mustUseMultiDistinctAgg() { - return mustUseMultiDistinctAgg; - } - - @Override - public Expression withMustUseMultiDistinctAgg(boolean mustUseMultiDistinctAgg) { - return new MultiDistinctCount(mustUseMultiDistinctAgg, getFunctionParams(children)); - } - @Override public Expression resultForEmptyInput() { return new BigIntLiteral(0); diff --git a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/agg/MultiDistinctGroupConcat.java b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/agg/MultiDistinctGroupConcat.java index f686b7727e1add..5fc78899a72b4b 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/agg/MultiDistinctGroupConcat.java +++ b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/agg/MultiDistinctGroupConcat.java @@ -51,7 +51,6 @@ public class MultiDistinctGroupConcat extends NullableAggregateFunction .varArgs(VarcharType.SYSTEM_DEFAULT, VarcharType.SYSTEM_DEFAULT, AnyDataType.INSTANCE_WITHOUT_INDEX) ); - private final boolean mustUseMultiDistinctAgg; private final int nonOrderArguments; /** @@ -64,26 +63,19 @@ public MultiDistinctGroupConcat(Expression arg, Expression... others) { /** * constructor with argument list. */ - public MultiDistinctGroupConcat(boolean alwaysNullable, List args) { - this(false, alwaysNullable, args); - } - private MultiDistinctGroupConcat(boolean alwaysNullable, Expression arg, Expression... others) { this(alwaysNullable, ExpressionUtils.mergeArguments(arg, others)); } - private MultiDistinctGroupConcat(boolean mustUseMultiDistinctAgg, boolean alwaysNullable, List args) { + public MultiDistinctGroupConcat(boolean alwaysNullable, List args) { super("multi_distinct_group_concat", false, alwaysNullable, args); - this.mustUseMultiDistinctAgg = mustUseMultiDistinctAgg; this.nonOrderArguments = findOrderExprIndex(children); } /** constructor for withChildren and reuse signature */ - protected MultiDistinctGroupConcat( - boolean mustUseMultiDistinctAgg, NullableAggregateFunctionParams functionParams) { + protected MultiDistinctGroupConcat(NullableAggregateFunctionParams functionParams) { super(functionParams); - this.mustUseMultiDistinctAgg = mustUseMultiDistinctAgg; this.nonOrderArguments = findOrderExprIndex(children); } @@ -95,7 +87,7 @@ public boolean nullable() { @Override public MultiDistinctGroupConcat withAlwaysNullable(boolean alwaysNullable) { - return new MultiDistinctGroupConcat(mustUseMultiDistinctAgg, getAlwaysNullableFunctionParams(alwaysNullable)); + return new MultiDistinctGroupConcat(getAlwaysNullableFunctionParams(alwaysNullable)); } /** @@ -103,7 +95,7 @@ public MultiDistinctGroupConcat withAlwaysNullable(boolean alwaysNullable) { */ @Override public MultiDistinctGroupConcat withDistinctAndChildren(boolean distinct, List children) { - return new MultiDistinctGroupConcat(mustUseMultiDistinctAgg, getFunctionParams(false, children)); + return new MultiDistinctGroupConcat(getFunctionParams(false, children)); } @Override @@ -126,16 +118,6 @@ public List getSignatures() { } } - @Override - public boolean mustUseMultiDistinctAgg() { - return mustUseMultiDistinctAgg || children.stream().anyMatch(OrderExpression.class::isInstance); - } - - @Override - public Expression withMustUseMultiDistinctAgg(boolean mustUseMultiDistinctAgg) { - return new MultiDistinctGroupConcat(mustUseMultiDistinctAgg, alwaysNullable, children); - } - private int findOrderExprIndex(List children) { Preconditions.checkArgument(children().size() >= 1, "children's size should >= 1"); boolean foundOrderExpr = false; diff --git a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/agg/MultiDistinctSum.java b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/agg/MultiDistinctSum.java index 954e95a4383df0..ff69f4182d107c 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/agg/MultiDistinctSum.java +++ b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/agg/MultiDistinctSum.java @@ -33,9 +33,6 @@ /** MultiDistinctSum */ public class MultiDistinctSum extends NullableAggregateFunction implements UnaryExpression, ExplicitlyCastableSignature, ComputePrecisionForSum, MultiDistinction { - - private final boolean mustUseMultiDistinctAgg; - public MultiDistinctSum(Expression arg0) { this(false, arg0); } @@ -45,19 +42,12 @@ public MultiDistinctSum(boolean distinct, Expression arg0) { } public MultiDistinctSum(boolean distinct, boolean alwaysNullable, Expression arg0) { - this(false, false, alwaysNullable, arg0); - } - - private MultiDistinctSum(boolean mustUseMultiDistinctAgg, boolean distinct, - boolean alwaysNullable, Expression arg0) { super("multi_distinct_sum", false, alwaysNullable, arg0); - this.mustUseMultiDistinctAgg = mustUseMultiDistinctAgg; } /** constructor for withChildren and reuse signature */ - private MultiDistinctSum(boolean mustUseMultiDistinctAgg, NullableAggregateFunctionParams functionParams) { + private MultiDistinctSum(NullableAggregateFunctionParams functionParams) { super(functionParams); - this.mustUseMultiDistinctAgg = mustUseMultiDistinctAgg; } @Override @@ -81,27 +71,17 @@ public FunctionSignature searchSignature(List signatures) { @Override public NullableAggregateFunction withAlwaysNullable(boolean alwaysNullable) { - return new MultiDistinctSum(mustUseMultiDistinctAgg, getAlwaysNullableFunctionParams(alwaysNullable)); + return new MultiDistinctSum(getAlwaysNullableFunctionParams(alwaysNullable)); } @Override public MultiDistinctSum withDistinctAndChildren(boolean distinct, List children) { Preconditions.checkArgument(children.size() == 1); - return new MultiDistinctSum(mustUseMultiDistinctAgg, getFunctionParams(false, children)); + return new MultiDistinctSum(getFunctionParams(false, children)); } @Override public R accept(ExpressionVisitor visitor, C context) { return visitor.visitMultiDistinctSum(this, context); } - - @Override - public boolean mustUseMultiDistinctAgg() { - return mustUseMultiDistinctAgg; - } - - @Override - public Expression withMustUseMultiDistinctAgg(boolean mustUseMultiDistinctAgg) { - return new MultiDistinctSum(mustUseMultiDistinctAgg, getFunctionParams(children)); - } } diff --git a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/agg/MultiDistinctSum0.java b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/agg/MultiDistinctSum0.java index 68af11bf5320ff..380132dce8d4ed 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/agg/MultiDistinctSum0.java +++ b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/agg/MultiDistinctSum0.java @@ -40,26 +40,17 @@ /** MultiDistinctSum0 */ public class MultiDistinctSum0 extends NotNullableAggregateFunction implements UnaryExpression, ExplicitlyCastableSignature, ComputePrecisionForSum, MultiDistinction { - - private final boolean mustUseMultiDistinctAgg; - public MultiDistinctSum0(Expression arg0) { this(false, arg0); } public MultiDistinctSum0(boolean distinct, Expression arg0) { - this(false, false, arg0); - } - - private MultiDistinctSum0(boolean mustUseMultiDistinctAgg, boolean distinct, Expression arg0) { super("multi_distinct_sum0", false, arg0); - this.mustUseMultiDistinctAgg = mustUseMultiDistinctAgg; } /** constructor for withChildren and reuse signature */ - private MultiDistinctSum0(boolean mustUseMultiDistinctAgg, AggregateFunctionParams functionParams) { + public MultiDistinctSum0(AggregateFunctionParams functionParams) { super(functionParams); - this.mustUseMultiDistinctAgg = mustUseMultiDistinctAgg; } @Override @@ -84,7 +75,7 @@ public FunctionSignature searchSignature(List signatures) { @Override public MultiDistinctSum0 withDistinctAndChildren(boolean distinct, List children) { Preconditions.checkArgument(children.size() == 1); - return new MultiDistinctSum0(mustUseMultiDistinctAgg, getFunctionParams(false, children)); + return new MultiDistinctSum0(getFunctionParams(false, children)); } @Override @@ -92,16 +83,6 @@ public R accept(ExpressionVisitor visitor, C context) { return visitor.visitMultiDistinctSum0(this, context); } - @Override - public boolean mustUseMultiDistinctAgg() { - return mustUseMultiDistinctAgg; - } - - @Override - public Expression withMustUseMultiDistinctAgg(boolean mustUseMultiDistinctAgg) { - return new MultiDistinctSum0(mustUseMultiDistinctAgg, getFunctionParams(children)); - } - @Override public Expression resultForEmptyInput() { DataType dataType = getDataType(); diff --git a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/agg/MultiDistinction.java b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/agg/MultiDistinction.java index 2709c4bcfe906e..ab8842f730112c 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/agg/MultiDistinction.java +++ b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/agg/MultiDistinction.java @@ -24,5 +24,4 @@ * base class of multi-distinct agg function */ public interface MultiDistinction extends TreeNode { - Expression withMustUseMultiDistinctAgg(boolean mustUseMultiDistinctAgg); } diff --git a/regression-test/data/nereids_rules_p0/agg_strategy/agg_strategy.out b/regression-test/data/nereids_rules_p0/agg_strategy/agg_strategy.out index a405272b3d3ccf..5ae951aea3dca2 100644 --- a/regression-test/data/nereids_rules_p0/agg_strategy/agg_strategy.out +++ b/regression-test/data/nereids_rules_p0/agg_strategy/agg_strategy.out @@ -897,3 +897,22 @@ PhysicalResultSink --------hashAgg[GLOBAL] ----------PhysicalOlapScan[t_gbykey_10_dstkey_10_1000_dst_key1] +-- !multi_distinct_count_and_count_distinct_multi_expr -- +2 20 + +-- !multi_distinct_sum_and_count_distinct_multi_expr -- +1 20 + +-- !multi_distinct_sum0_and_count_distinct_multi_expr -- +1 20 + +-- !multi_distinct_group_concat_and_count_distinct_multi_expr -- +PhysicalResultSink +--hashAgg[DISTINCT_GLOBAL] +----PhysicalDistribute[DistributionSpecGather] +------hashAgg[DISTINCT_LOCAL] +--------hashAgg[GLOBAL] +----------PhysicalDistribute[DistributionSpecHash] +------------hashAgg[LOCAL] +--------------PhysicalOlapScan[t_gbykey_10_dstkey_10_1000_id] + diff --git a/regression-test/data/nereids_rules_p0/agg_strategy/test1.out b/regression-test/data/nereids_rules_p0/agg_strategy/test1.out new file mode 100644 index 00000000000000..e55ca46b19b35b --- /dev/null +++ b/regression-test/data/nereids_rules_p0/agg_strategy/test1.out @@ -0,0 +1,162 @@ +-- This file is automatically generated. You should know what you did if you want to edit this +-- !test -- +$& 445 151 310 20 36 0 118 22 48 0.3393258426966292 70 0.08089887640449438 0.0 0.2651685393258427 +2019-05-04 3 0 3 \N 0 0 0 0 0 0.0 0 0.0 0.0 0.0 +2019-05-05 3 0 3 \N 0 0 0 0 0 0.0 0 0.0 0.0 0.0 +2019-05-10 1 0 1 \N 0 0 0 0 0 0.0 0 0.0 0.0 0.0 +2019-05-22 1 0 1 \N 0 0 0 0 0 0.0 0 0.0 0.0 0.0 +2019-05-25 2 0 2 \N 0 0 0 0 0 0.0 0 0.0 0.0 0.0 +2019-05-26 1 1 1 \N 1 0 0 0 0 1.0 0 1.0 0.0 0.0 +2019-05-27 1 0 1 \N 0 0 0 0 0 0.0 0 0.0 0.0 0.0 +2019-05-29 1 0 1 \N 0 0 0 0 0 0.0 0 0.0 0.0 0.0 +2019-05-31 1 0 1 \N 0 0 0 0 1 0.0 1 0.0 0.0 0.0 +2019-06-02 1 0 1 \N 0 0 0 0 0 0.0 0 0.0 0.0 0.0 +2019-06-22 1 0 1 \N 0 0 0 0 0 0.0 0 0.0 0.0 0.0 +2019-06-24 2 0 2 \N 0 0 0 0 1 0.0 1 0.0 0.0 0.0 +2019-06-25 3 0 3 \N 0 0 0 0 1 0.0 1 0.0 0.0 0.0 +2019-06-26 1 1 1 \N 1 0 0 0 0 1.0 0 1.0 0.0 0.0 +2019-07-07 2 2 2 \N 2 0 0 0 0 1.0 0 1.0 0.0 0.0 +2019-07-09 1 0 1 \N 0 0 0 0 0 0.0 0 0.0 0.0 0.0 +2019-07-28 2 0 2 \N 0 0 0 0 1 0.0 1 0.0 0.0 0.0 +2019-07-29 1 0 1 \N 0 0 0 0 1 0.0 1 0.0 0.0 0.0 +2019-07-30 2 0 2 \N 0 0 0 0 0 0.0 0 0.0 0.0 0.0 +2019-07-31 1 0 1 \N 0 0 0 0 0 0.0 0 0.0 0.0 0.0 +2019-08-02 1 0 1 \N 0 0 0 0 1 0.0 1 0.0 0.0 0.0 +2019-08-03 2 0 2 \N 0 0 0 0 1 0.0 1 0.0 0.0 0.0 +2019-08-17 2 0 2 \N 0 0 0 0 0 0.0 0 0.0 0.0 0.0 +2019-08-20 1 0 1 \N 0 0 0 0 0 0.0 0 0.0 0.0 0.0 +2019-08-21 1 0 1 \N 0 0 0 0 0 0.0 0 0.0 0.0 0.0 +2019-08-23 1 0 1 \N 0 0 0 0 0 0.0 0 0.0 0.0 0.0 +2019-08-26 2 0 2 \N 0 0 0 0 0 0.0 0 0.0 0.0 0.0 +2019-09-06 1 0 1 \N 0 0 0 0 0 0.0 0 0.0 0.0 0.0 +2019-09-08 1 0 1 \N 0 0 0 0 0 0.0 0 0.0 0.0 0.0 +2019-09-09 3 1 3 \N 0 0 1 0 0 0.3333333333333333 0 0.0 0.0 0.3333333333333333 +2019-09-10 2 2 2 \N 2 0 0 0 0 1.0 0 1.0 0.0 0.0 +2019-09-19 3 1 3 \N 1 0 0 0 1 0.3333333333333333 1 0.3333333333333333 0.0 0.0 +2019-09-20 1 0 1 \N 0 0 0 0 1 0.0 1 0.0 0.0 0.0 +2019-09-23 2 0 2 \N 0 0 0 0 1 0.0 1 0.0 0.0 0.0 +2019-09-27 1 0 1 \N 0 0 0 0 1 0.0 1 0.0 0.0 0.0 +2019-10-27 1 1 1 \N 1 0 0 0 0 1.0 0 1.0 0.0 0.0 +2019-10-28 2 0 2 \N 0 0 0 0 0 0.0 0 0.0 0.0 0.0 +2019-10-29 2 1 2 \N 0 0 1 0 0 0.5 0 0.0 0.0 0.5 +2019-10-30 2 0 2 \N 0 0 0 0 0 0.0 0 0.0 0.0 0.0 +2019-10-31 3 0 3 \N 0 0 0 0 0 0.0 0 0.0 0.0 0.0 +2019-11-02 2 0 2 \N 0 0 0 0 0 0.0 0 0.0 0.0 0.0 +2019-11-04 2 1 2 \N 1 0 0 0 0 0.5 0 0.5 0.0 0.0 +2019-11-11 1 1 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0 0.0 0.0 +2020-09-17 1 1 1 \N 1 0 0 0 0 1.0 0 1.0 0.0 0.0 +2020-09-18 1 1 1 \N 0 0 1 0 0 1.0 0 0.0 0.0 1.0 +2020-09-29 1 0 1 \N 0 0 0 0 0 0.0 0 0.0 0.0 0.0 +2020-10-07 1 1 1 \N 1 0 0 0 0 1.0 0 1.0 0.0 0.0 +2020-10-13 1 0 1 \N 0 0 0 0 0 0.0 0 0.0 0.0 0.0 +2020-10-19 1 0 1 \N 0 0 0 0 0 0.0 0 0.0 0.0 0.0 +2020-11-03 1 0 1 \N 0 0 0 0 0 0.0 0 0.0 0.0 0.0 +2020-11-07 1 0 1 \N 0 0 0 0 0 0.0 0 0.0 0.0 0.0 +2020-11-23 1 0 1 \N 0 0 0 0 0 0.0 0 0.0 0.0 0.0 +2020-11-29 1 1 1 \N 1 0 0 0 0 1.0 0 1.0 0.0 0.0 +2020-12-04 1 0 1 \N 0 0 0 0 0 0.0 0 0.0 0.0 0.0 +2020-12-06 1 0 1 \N 0 0 0 0 0 0.0 0 0.0 0.0 0.0 +2020-12-25 1 0 1 \N 0 0 0 0 0 0.0 0 0.0 0.0 0.0 +2020-12-27 1 0 1 \N 0 0 0 0 0 0.0 0 0.0 0.0 0.0 +2021-01-01 6 3 6 \N 0 0 3 0 0 0.5 0 0.0 0.0 0.5 +2021-01-02 2 0 2 \N 0 0 0 0 1 0.0 1 0.0 0.0 0.0 +2021-01-03 4 3 4 \N 1 0 2 0 1 0.75 1 0.25 0.0 0.5 +2021-01-04 5 4 5 \N 1 0 3 1 1 0.8 2 0.2 0.0 0.6 +2021-01-05 7 4 7 \N 1 0 3 2 0 0.5714285714285714 2 0.14285714285714285 0.0 0.42857142857142855 +2021-01-06 6 3 6 \N 0 0 3 0 0 0.5 0 0.0 0.0 0.5 +2021-01-07 6 4 6 \N 0 0 4 1 1 0.6666666666666666 2 0.0 0.0 0.6666666666666666 +2021-01-08 4 0 4 \N 0 0 0 0 1 0.0 1 0.0 0.0 0.0 +2021-01-09 4 2 4 \N 0 0 2 0 0 0.5 0 0.0 0.0 0.5 +2021-01-10 2 1 2 \N 1 0 0 0 0 0.5 0 0.5 0.0 0.0 +2021-01-11 4 2 4 \N 0 0 2 0 0 0.5 0 0.0 0.0 0.5 +2021-01-12 6 3 6 \N 0 0 3 0 0 0.5 0 0.0 0.0 0.5 +2021-01-13 6 2 6 \N 0 0 2 2 1 0.3333333333333333 3 0.0 0.0 0.3333333333333333 +2021-01-14 5 1 5 \N 0 0 1 2 0 0.2 2 0.0 0.0 0.2 +2021-01-15 4 3 4 \N 0 0 3 0 2 0.75 2 0.0 0.0 0.75 +2021-01-16 4 2 4 \N 1 0 1 0 1 0.5 1 0.25 0.0 0.25 +2021-01-17 3 0 3 \N 0 0 0 0 1 0.0 1 0.0 0.0 0.0 +2021-01-18 5 4 5 \N 0 0 4 1 0 0.8 1 0.0 0.0 0.8 +2021-01-19 6 2 6 \N 1 0 1 0 3 0.3333333333333333 3 0.16666666666666666 0.0 0.16666666666666666 +2021-01-20 4 1 4 \N 0 0 1 0 0 0.25 0 0.0 0.0 0.25 +2021-01-21 2 0 2 \N 0 0 0 0 0 0.0 0 0.0 0.0 0.0 +2021-01-22 12 4 12 \N 0 0 4 0 2 0.3333333333333333 2 0.0 0.0 0.3333333333333333 +2021-01-23 4 2 4 \N 0 0 2 0 0 0.5 0 0.0 0.0 0.5 +2021-01-24 5 1 5 \N 0 0 1 0 2 0.2 2 0.0 0.0 0.2 +2021-01-25 5 3 5 \N 0 0 3 1 1 0.6 2 0.0 0.0 0.6 +2021-01-26 6 3 6 \N 1 0 3 1 1 0.5 2 0.16666666666666666 0.0 0.5 +2021-01-27 8 2 8 \N 0 0 2 0 0 0.25 0 0.0 0.0 0.25 +2021-01-28 9 2 9 \N 0 0 2 1 0 0.2222222222222222 1 0.0 0.0 0.2222222222222222 +2021-01-29 5 2 5 \N 0 0 2 0 1 0.4 1 0.0 0.0 0.4 +2021-01-30 7 3 7 \N 1 0 2 0 1 0.42857142857142855 1 0.14285714285714285 0.0 0.2857142857142857 +2021-01-31 2 1 2 \N 0 0 1 0 1 0.5 1 0.0 0.0 0.5 +2021-02-01 11 4 11 \N 2 0 2 0 1 0.36363636363636365 1 0.18181818181818182 0.0 0.18181818181818182 +2021-02-02 9 4 9 \N 1 0 3 0 0 0.4444444444444444 0 0.1111111111111111 0.0 0.3333333333333333 +2021-02-03 10 3 9 \N 0 0 3 2 1 0.3 3 0.0 0.0 0.3 +2021-02-04 5 1 5 \N 0 0 1 0 0 0.2 0 0.0 0.0 0.2 +2021-02-05 6 2 6 \N 0 0 2 0 0 0.3333333333333333 0 0.0 0.0 0.3333333333333333 +2021-02-06 7 5 6 \N 1 0 4 1 1 0.7142857142857143 2 0.14285714285714285 0.0 0.5714285714285714 +2021-02-07 3 0 3 \N 0 0 0 0 1 0.0 1 0.0 0.0 0.0 +2021-02-08 10 3 10 \N 0 0 3 0 0 0.3 0 0.0 0.0 0.3 +2021-02-09 7 2 7 \N 0 0 2 0 0 0.2857142857142857 0 0.0 0.0 0.2857142857142857 +2021-02-10 7 4 7 \N 1 0 4 1 1 0.5714285714285714 2 0.14285714285714285 0.0 0.5714285714285714 +2021-02-11 7 3 7 \N 0 0 3 0 0 0.42857142857142855 0 0.0 0.0 0.42857142857142855 +2021-02-12 5 1 5 \N 0 0 1 0 0 0.2 0 0.0 0.0 0.2 +2021-02-13 5 3 5 \N 1 0 2 0 0 0.6 0 0.2 0.0 0.4 +2021-02-14 6 1 6 \N 0 0 1 0 0 0.16666666666666666 0 0.0 0.0 0.16666666666666666 +2021-02-15 2 2 2 \N 0 0 2 0 0 1.0 0 0.0 0.0 1.0 +2021-02-16 4 1 4 \N 1 0 0 0 0 0.25 0 0.25 0.0 0.0 +2021-02-17 4 2 4 \N 0 0 2 0 1 0.5 1 0.0 0.0 0.5 +2021-02-18 7 3 7 \N 1 0 2 0 0 0.42857142857142855 0 0.14285714285714285 0.0 0.2857142857142857 +2021-02-19 7 2 7 \N 0 0 2 2 1 0.2857142857142857 3 0.0 0.0 0.2857142857142857 +2021-02-20 6 1 6 \N 1 0 0 0 0 0.16666666666666666 0 0.16666666666666666 0.0 0.0 +2021-02-21 6 2 6 \N 1 0 1 0 0 0.3333333333333333 0 0.16666666666666666 0.0 0.16666666666666666 +2021-02-22 8 4 8 \N 0 0 4 1 1 0.5 2 0.0 0.0 0.5 +2021-02-23 6 2 6 \N 1 0 1 1 0 0.3333333333333333 1 0.16666666666666666 0.0 0.16666666666666666 +2021-02-24 5 2 5 \N 0 0 2 1 1 0.4 2 0.0 0.0 0.4 +2021-02-25 3 0 3 \N 0 0 0 0 0 0.0 0 0.0 0.0 0.0 + diff --git a/regression-test/suites/nereids_rules_p0/agg_strategy/agg_strategy.groovy b/regression-test/suites/nereids_rules_p0/agg_strategy/agg_strategy.groovy index aab08847dff631..ac6ea9d37324b9 100644 --- a/regression-test/suites/nereids_rules_p0/agg_strategy/agg_strategy.groovy +++ b/regression-test/suites/nereids_rules_p0/agg_strategy/agg_strategy.groovy @@ -141,4 +141,17 @@ suite("agg_strategy") { select group_concat(distinct dst_key1 ,' ') from t_gbykey_10_dstkey_10_1000_dst_key1;""" // multi_distinct and count distinct multi expr + qt_multi_distinct_count_and_count_distinct_multi_expr """ + select multi_distinct_count(dst_key1), count(distinct dst_key1,dst_key2) from t_gbykey_2_dstkey_10_30_id; + """ + qt_multi_distinct_sum_and_count_distinct_multi_expr """ + select multi_distinct_sum(dst_key1), count(distinct dst_key1,dst_key2) from t_gbykey_2_dstkey_10_30_id; + """ + qt_multi_distinct_sum0_and_count_distinct_multi_expr """ + select multi_distinct_sum0(dst_key1), count(distinct dst_key1,dst_key2) from t_gbykey_2_dstkey_10_30_id; + """ + qt_multi_distinct_group_concat_and_count_distinct_multi_expr """ + explain shape plan + select multi_distinct_group_concat(dst_key1 order by dst_key2), count(distinct dst_key1,dst_key2) from t_gbykey_10_dstkey_10_1000_id; + """ } \ No newline at end of file diff --git a/regression-test/suites/nereids_rules_p0/agg_strategy/load.groovy b/regression-test/suites/nereids_rules_p0/agg_strategy/load.groovy index f953cec1bfb6cd..f17f64ab5a4cd9 100644 --- a/regression-test/suites/nereids_rules_p0/agg_strategy/load.groovy +++ b/regression-test/suites/nereids_rules_p0/agg_strategy/load.groovy @@ -15,7 +15,7 @@ // specific language governing permissions and limitations // under the License. -suite("agg_strategy") { +suite("load") { sql "set global enable_auto_analyze=false" // ndv is high sql "drop table if exists t_gbykey_10_dstkey_10_1000_id" From 5f877d1e381f25affcee867197fe46498a1253f2 Mon Sep 17 00:00:00 2001 From: feiniaofeiafei Date: Mon, 22 Sep 2025 12:43:41 +0800 Subject: [PATCH 3/5] fix --- .../nereids_rules_p0/agg_strategy/test1.out | 162 ------------------ 1 file changed, 162 deletions(-) delete mode 100644 regression-test/data/nereids_rules_p0/agg_strategy/test1.out diff --git a/regression-test/data/nereids_rules_p0/agg_strategy/test1.out b/regression-test/data/nereids_rules_p0/agg_strategy/test1.out deleted file mode 100644 index e55ca46b19b35b..00000000000000 --- a/regression-test/data/nereids_rules_p0/agg_strategy/test1.out +++ /dev/null @@ -1,162 +0,0 @@ --- This file is automatically generated. You should know what you did if you want to edit this --- !test -- -$& 445 151 310 20 36 0 118 22 48 0.3393258426966292 70 0.08089887640449438 0.0 0.2651685393258427 -2019-05-04 3 0 3 \N 0 0 0 0 0 0.0 0 0.0 0.0 0.0 -2019-05-05 3 0 3 \N 0 0 0 0 0 0.0 0 0.0 0.0 0.0 -2019-05-10 1 0 1 \N 0 0 0 0 0 0.0 0 0.0 0.0 0.0 -2019-05-22 1 0 1 \N 0 0 0 0 0 0.0 0 0.0 0.0 0.0 -2019-05-25 2 0 2 \N 0 0 0 0 0 0.0 0 0.0 0.0 0.0 -2019-05-26 1 1 1 \N 1 0 0 0 0 1.0 0 1.0 0.0 0.0 -2019-05-27 1 0 1 \N 0 0 0 0 0 0.0 0 0.0 0.0 0.0 -2019-05-29 1 0 1 \N 0 0 0 0 0 0.0 0 0.0 0.0 0.0 -2019-05-31 1 0 1 \N 0 0 0 0 1 0.0 1 0.0 0.0 0.0 -2019-06-02 1 0 1 \N 0 0 0 0 0 0.0 0 0.0 0.0 0.0 -2019-06-22 1 0 1 \N 0 0 0 0 0 0.0 0 0.0 0.0 0.0 -2019-06-24 2 0 2 \N 0 0 0 0 1 0.0 1 0.0 0.0 0.0 -2019-06-25 3 0 3 \N 0 0 0 0 1 0.0 1 0.0 0.0 0.0 -2019-06-26 1 1 1 \N 1 0 0 0 0 1.0 0 1.0 0.0 0.0 -2019-07-07 2 2 2 \N 2 0 0 0 0 1.0 0 1.0 0.0 0.0 -2019-07-09 1 0 1 \N 0 0 0 0 0 0.0 0 0.0 0.0 0.0 -2019-07-28 2 0 2 \N 0 0 0 0 1 0.0 1 0.0 0.0 0.0 -2019-07-29 1 0 1 \N 0 0 0 0 1 0.0 1 0.0 0.0 0.0 -2019-07-30 2 0 2 \N 0 0 0 0 0 0.0 0 0.0 0.0 0.0 -2019-07-31 1 0 1 \N 0 0 0 0 0 0.0 0 0.0 0.0 0.0 -2019-08-02 1 0 1 \N 0 0 0 0 1 0.0 1 0.0 0.0 0.0 -2019-08-03 2 0 2 \N 0 0 0 0 1 0.0 1 0.0 0.0 0.0 -2019-08-17 2 0 2 \N 0 0 0 0 0 0.0 0 0.0 0.0 0.0 -2019-08-20 1 0 1 \N 0 0 0 0 0 0.0 0 0.0 0.0 0.0 -2019-08-21 1 0 1 \N 0 0 0 0 0 0.0 0 0.0 0.0 0.0 -2019-08-23 1 0 1 \N 0 0 0 0 0 0.0 0 0.0 0.0 0.0 -2019-08-26 2 0 2 \N 0 0 0 0 0 0.0 0 0.0 0.0 0.0 -2019-09-06 1 0 1 \N 0 0 0 0 0 0.0 0 0.0 0.0 0.0 -2019-09-08 1 0 1 \N 0 0 0 0 0 0.0 0 0.0 0.0 0.0 -2019-09-09 3 1 3 \N 0 0 1 0 0 0.3333333333333333 0 0.0 0.0 0.3333333333333333 -2019-09-10 2 2 2 \N 2 0 0 0 0 1.0 0 1.0 0.0 0.0 -2019-09-19 3 1 3 \N 1 0 0 0 1 0.3333333333333333 1 0.3333333333333333 0.0 0.0 -2019-09-20 1 0 1 \N 0 0 0 0 1 0.0 1 0.0 0.0 0.0 -2019-09-23 2 0 2 \N 0 0 0 0 1 0.0 1 0.0 0.0 0.0 -2019-09-27 1 0 1 \N 0 0 0 0 1 0.0 1 0.0 0.0 0.0 -2019-10-27 1 1 1 \N 1 0 0 0 0 1.0 0 1.0 0.0 0.0 -2019-10-28 2 0 2 \N 0 0 0 0 0 0.0 0 0.0 0.0 0.0 -2019-10-29 2 1 2 \N 0 0 1 0 0 0.5 0 0.0 0.0 0.5 -2019-10-30 2 0 2 \N 0 0 0 0 0 0.0 0 0.0 0.0 0.0 -2019-10-31 3 0 3 \N 0 0 0 0 0 0.0 0 0.0 0.0 0.0 -2019-11-02 2 0 2 \N 0 0 0 0 0 0.0 0 0.0 0.0 0.0 -2019-11-04 2 1 2 \N 1 0 0 0 0 0.5 0 0.5 0.0 0.0 -2019-11-11 1 1 1 \N 1 0 0 0 0 1.0 0 1.0 0.0 0.0 -2019-11-19 1 1 1 \N 0 0 1 0 0 1.0 0 0.0 0.0 1.0 -2019-11-22 1 0 1 \N 0 0 0 0 0 0.0 0 0.0 0.0 0.0 -2019-12-04 1 0 1 \N 0 0 0 0 0 0.0 0 0.0 0.0 0.0 -2019-12-07 1 0 1 \N 0 0 0 0 0 0.0 0 0.0 0.0 0.0 -2019-12-08 1 0 1 \N 0 0 0 0 0 0.0 0 0.0 0.0 0.0 -2019-12-12 1 0 1 \N 0 0 0 0 0 0.0 0 0.0 0.0 0.0 -2019-12-13 1 0 1 \N 0 0 0 0 0 0.0 0 0.0 0.0 0.0 -2019-12-16 2 0 2 \N 0 0 0 0 0 0.0 0 0.0 0.0 0.0 -2019-12-30 1 0 1 \N 0 0 0 0 0 0.0 0 0.0 0.0 0.0 -2019-12-31 1 0 1 \N 0 0 0 0 0 0.0 0 0.0 0.0 0.0 -2020-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0.0 0 0.0 0.0 0.0 -2020-12-06 1 0 1 \N 0 0 0 0 0 0.0 0 0.0 0.0 0.0 -2020-12-25 1 0 1 \N 0 0 0 0 0 0.0 0 0.0 0.0 0.0 -2020-12-27 1 0 1 \N 0 0 0 0 0 0.0 0 0.0 0.0 0.0 -2021-01-01 6 3 6 \N 0 0 3 0 0 0.5 0 0.0 0.0 0.5 -2021-01-02 2 0 2 \N 0 0 0 0 1 0.0 1 0.0 0.0 0.0 -2021-01-03 4 3 4 \N 1 0 2 0 1 0.75 1 0.25 0.0 0.5 -2021-01-04 5 4 5 \N 1 0 3 1 1 0.8 2 0.2 0.0 0.6 -2021-01-05 7 4 7 \N 1 0 3 2 0 0.5714285714285714 2 0.14285714285714285 0.0 0.42857142857142855 -2021-01-06 6 3 6 \N 0 0 3 0 0 0.5 0 0.0 0.0 0.5 -2021-01-07 6 4 6 \N 0 0 4 1 1 0.6666666666666666 2 0.0 0.0 0.6666666666666666 -2021-01-08 4 0 4 \N 0 0 0 0 1 0.0 1 0.0 0.0 0.0 -2021-01-09 4 2 4 \N 0 0 2 0 0 0.5 0 0.0 0.0 0.5 -2021-01-10 2 1 2 \N 1 0 0 0 0 0.5 0 0.5 0.0 0.0 -2021-01-11 4 2 4 \N 0 0 2 0 0 0.5 0 0.0 0.0 0.5 -2021-01-12 6 3 6 \N 0 0 3 0 0 0.5 0 0.0 0.0 0.5 -2021-01-13 6 2 6 \N 0 0 2 2 1 0.3333333333333333 3 0.0 0.0 0.3333333333333333 -2021-01-14 5 1 5 \N 0 0 1 2 0 0.2 2 0.0 0.0 0.2 -2021-01-15 4 3 4 \N 0 0 3 0 2 0.75 2 0.0 0.0 0.75 -2021-01-16 4 2 4 \N 1 0 1 0 1 0.5 1 0.25 0.0 0.25 -2021-01-17 3 0 3 \N 0 0 0 0 1 0.0 1 0.0 0.0 0.0 -2021-01-18 5 4 5 \N 0 0 4 1 0 0.8 1 0.0 0.0 0.8 -2021-01-19 6 2 6 \N 1 0 1 0 3 0.3333333333333333 3 0.16666666666666666 0.0 0.16666666666666666 -2021-01-20 4 1 4 \N 0 0 1 0 0 0.25 0 0.0 0.0 0.25 -2021-01-21 2 0 2 \N 0 0 0 0 0 0.0 0 0.0 0.0 0.0 -2021-01-22 12 4 12 \N 0 0 4 0 2 0.3333333333333333 2 0.0 0.0 0.3333333333333333 -2021-01-23 4 2 4 \N 0 0 2 0 0 0.5 0 0.0 0.0 0.5 -2021-01-24 5 1 5 \N 0 0 1 0 2 0.2 2 0.0 0.0 0.2 -2021-01-25 5 3 5 \N 0 0 3 1 1 0.6 2 0.0 0.0 0.6 -2021-01-26 6 3 6 \N 1 0 3 1 1 0.5 2 0.16666666666666666 0.0 0.5 -2021-01-27 8 2 8 \N 0 0 2 0 0 0.25 0 0.0 0.0 0.25 -2021-01-28 9 2 9 \N 0 0 2 1 0 0.2222222222222222 1 0.0 0.0 0.2222222222222222 -2021-01-29 5 2 5 \N 0 0 2 0 1 0.4 1 0.0 0.0 0.4 -2021-01-30 7 3 7 \N 1 0 2 0 1 0.42857142857142855 1 0.14285714285714285 0.0 0.2857142857142857 -2021-01-31 2 1 2 \N 0 0 1 0 1 0.5 1 0.0 0.0 0.5 -2021-02-01 11 4 11 \N 2 0 2 0 1 0.36363636363636365 1 0.18181818181818182 0.0 0.18181818181818182 -2021-02-02 9 4 9 \N 1 0 3 0 0 0.4444444444444444 0 0.1111111111111111 0.0 0.3333333333333333 -2021-02-03 10 3 9 \N 0 0 3 2 1 0.3 3 0.0 0.0 0.3 -2021-02-04 5 1 5 \N 0 0 1 0 0 0.2 0 0.0 0.0 0.2 -2021-02-05 6 2 6 \N 0 0 2 0 0 0.3333333333333333 0 0.0 0.0 0.3333333333333333 -2021-02-06 7 5 6 \N 1 0 4 1 1 0.7142857142857143 2 0.14285714285714285 0.0 0.5714285714285714 -2021-02-07 3 0 3 \N 0 0 0 0 1 0.0 1 0.0 0.0 0.0 -2021-02-08 10 3 10 \N 0 0 3 0 0 0.3 0 0.0 0.0 0.3 -2021-02-09 7 2 7 \N 0 0 2 0 0 0.2857142857142857 0 0.0 0.0 0.2857142857142857 -2021-02-10 7 4 7 \N 1 0 4 1 1 0.5714285714285714 2 0.14285714285714285 0.0 0.5714285714285714 -2021-02-11 7 3 7 \N 0 0 3 0 0 0.42857142857142855 0 0.0 0.0 0.42857142857142855 -2021-02-12 5 1 5 \N 0 0 1 0 0 0.2 0 0.0 0.0 0.2 -2021-02-13 5 3 5 \N 1 0 2 0 0 0.6 0 0.2 0.0 0.4 -2021-02-14 6 1 6 \N 0 0 1 0 0 0.16666666666666666 0 0.0 0.0 0.16666666666666666 -2021-02-15 2 2 2 \N 0 0 2 0 0 1.0 0 0.0 0.0 1.0 -2021-02-16 4 1 4 \N 1 0 0 0 0 0.25 0 0.25 0.0 0.0 -2021-02-17 4 2 4 \N 0 0 2 0 1 0.5 1 0.0 0.0 0.5 -2021-02-18 7 3 7 \N 1 0 2 0 0 0.42857142857142855 0 0.14285714285714285 0.0 0.2857142857142857 -2021-02-19 7 2 7 \N 0 0 2 2 1 0.2857142857142857 3 0.0 0.0 0.2857142857142857 -2021-02-20 6 1 6 \N 1 0 0 0 0 0.16666666666666666 0 0.16666666666666666 0.0 0.0 -2021-02-21 6 2 6 \N 1 0 1 0 0 0.3333333333333333 0 0.16666666666666666 0.0 0.16666666666666666 -2021-02-22 8 4 8 \N 0 0 4 1 1 0.5 2 0.0 0.0 0.5 -2021-02-23 6 2 6 \N 1 0 1 1 0 0.3333333333333333 1 0.16666666666666666 0.0 0.16666666666666666 -2021-02-24 5 2 5 \N 0 0 2 1 1 0.4 2 0.0 0.0 0.4 -2021-02-25 3 0 3 \N 0 0 0 0 0 0.0 0 0.0 0.0 0.0 - From c210d3288b292b0c8fffbb0df9ac268fb478705a Mon Sep 17 00:00:00 2001 From: feiniaofeiafei Date: Mon, 22 Sep 2025 15:30:42 +0800 Subject: [PATCH 4/5] fix --- .../nereids/rules/analysis/NormalizeAggregate.java | 14 +++++--------- 1 file changed, 5 insertions(+), 9 deletions(-) diff --git a/fe/fe-core/src/main/java/org/apache/doris/nereids/rules/analysis/NormalizeAggregate.java b/fe/fe-core/src/main/java/org/apache/doris/nereids/rules/analysis/NormalizeAggregate.java index fa64f70d53a8cd..fd5ae6931d96bf 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/nereids/rules/analysis/NormalizeAggregate.java +++ b/fe/fe-core/src/main/java/org/apache/doris/nereids/rules/analysis/NormalizeAggregate.java @@ -269,11 +269,7 @@ private LogicalPlan normalizeAgg(LogicalAggregate aggregate, Optional aggOutput = normalizedAggOutputBuilder.build(); - ImmutableList.Builder newAggOutputBuilder - = ImmutableList.builderWithExpectedSize(aggOutput.size()); - newAggOutputBuilder.addAll(aggOutput); - ImmutableList normalizedAggOutput = newAggOutputBuilder.build(); + ImmutableList normalizedAggOutput = normalizedAggOutputBuilder.build(); // create upper projects by normalize all output exprs in old LogicalAggregate // In aggregateOutput, the expressions inside the agg function can be rewritten @@ -308,7 +304,7 @@ private LogicalPlan normalizeAgg(LogicalAggregate aggregate, Optional (NamedExpression) ExpressionUtils.replace(e, replaceMap)) @@ -323,10 +319,10 @@ private LogicalPlan normalizeAgg(LogicalAggregate aggregate, Optional newAggregate = - aggregate.withNormalized(normalizedGroupExprs, newAggOutputBuilder.build(), bottomPlan); + aggregate.withNormalized(normalizedGroupExprs, normalizedAggOutputBuilder.build(), bottomPlan); ExpressionRewriteContext rewriteContext = new ExpressionRewriteContext(ctx); LogicalProject project = eliminateGroupByConstant(groupByExprContext, rewriteContext, normalizedGroupExprs, normalizedAggOutput, bottomProjects, aggregate, upperProjects, newAggregate); From 8810b98ab0b872b1f335b8b0fc58b2c73a4732c8 Mon Sep 17 00:00:00 2001 From: feiniaofeiafei Date: Mon, 22 Sep 2025 16:50:53 +0800 Subject: [PATCH 5/5] fix --- .../expressions/functions/agg/MultiDistinctCount.java | 9 +++++++-- .../data/nereids_rules_p0/agg_strategy/agg_strategy.out | 3 +++ .../nereids_rules_p0/agg_strategy/agg_strategy.groovy | 8 ++++++++ 3 files changed, 18 insertions(+), 2 deletions(-) diff --git a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/agg/MultiDistinctCount.java b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/agg/MultiDistinctCount.java index bb82b25a635c15..1dadd80d6dabab 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/agg/MultiDistinctCount.java +++ b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/agg/MultiDistinctCount.java @@ -19,6 +19,7 @@ import org.apache.doris.catalog.FunctionSignature; import org.apache.doris.nereids.analyzer.Unbound; +import org.apache.doris.nereids.exceptions.AnalysisException; import org.apache.doris.nereids.trees.expressions.Cast; import org.apache.doris.nereids.trees.expressions.Expression; import org.apache.doris.nereids.trees.expressions.functions.ExplicitlyCastableSignature; @@ -32,6 +33,7 @@ import com.google.common.base.Preconditions; import com.google.common.collect.ImmutableList; +import java.util.LinkedHashSet; import java.util.List; /** MultiDistinctCount */ @@ -53,11 +55,14 @@ public MultiDistinctCount(boolean distinct, Expression arg0, Expression... varAr } private MultiDistinctCount(boolean distinct, List children) { - super("multi_distinct_count", false, children + super("multi_distinct_count", false, new LinkedHashSet<>(children) .stream() .map(arg -> !(arg instanceof Unbound) && arg.getDataType() instanceof DateLikeType ? new Cast(arg, BigIntType.INSTANCE) : arg) .collect(ImmutableList.toImmutableList())); + if (super.children().size() > 1) { + throw new AnalysisException("MultiDistinctCount's children size must be 1"); + } } /** constructor for withChildren and reuse signature */ @@ -67,7 +72,7 @@ protected MultiDistinctCount(AggregateFunctionParams functionParams) { @Override public MultiDistinctCount withDistinctAndChildren(boolean distinct, List children) { - Preconditions.checkArgument(!children.isEmpty()); + Preconditions.checkArgument(children.size() == 1, "MultiDistinctCount's children size must be 1"); return new MultiDistinctCount(getFunctionParams(false, children)); } diff --git a/regression-test/data/nereids_rules_p0/agg_strategy/agg_strategy.out b/regression-test/data/nereids_rules_p0/agg_strategy/agg_strategy.out index 5ae951aea3dca2..ba448a756a2c6d 100644 --- a/regression-test/data/nereids_rules_p0/agg_strategy/agg_strategy.out +++ b/regression-test/data/nereids_rules_p0/agg_strategy/agg_strategy.out @@ -916,3 +916,6 @@ PhysicalResultSink ------------hashAgg[LOCAL] --------------PhysicalOlapScan[t_gbykey_10_dstkey_10_1000_id] +-- !multi_distinct_count_2_same_args -- +10 + diff --git a/regression-test/suites/nereids_rules_p0/agg_strategy/agg_strategy.groovy b/regression-test/suites/nereids_rules_p0/agg_strategy/agg_strategy.groovy index ac6ea9d37324b9..72ee1b92efb415 100644 --- a/regression-test/suites/nereids_rules_p0/agg_strategy/agg_strategy.groovy +++ b/regression-test/suites/nereids_rules_p0/agg_strategy/agg_strategy.groovy @@ -154,4 +154,12 @@ suite("agg_strategy") { explain shape plan select multi_distinct_group_concat(dst_key1 order by dst_key2), count(distinct dst_key1,dst_key2) from t_gbykey_10_dstkey_10_1000_id; """ + + // multi_distinct_count only accept one arg + test { + sql "select multi_distinct_count(dst_key1,dst_key2) from t_gbykey_2_dstkey_10_30_id;" + exception "multi_distinct_count(dst_key1, dst_key2), MultiDistinctCount's children size must be 1" + } + // multi_distinct_count only accept 2 same args + qt_multi_distinct_count_2_same_args "select multi_distinct_count(dst_key2,dst_key2) from t_gbykey_2_dstkey_10_30_id;" } \ No newline at end of file