This is an automated email from the ASF dual-hosted git repository.

Mryange pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/doris.git


The following commit(s) were added to refs/heads/master by this push:
     new eb50752c021 [fix](function) Share DISTINCT keys for 
percentile_approx_array (#68489)
eb50752c021 is described below

commit eb50752c0216732ba69f0c04fdabd9b79ac7dda7
Author: linrrarity <[email protected]>
AuthorDate: Mon Sep 28 14:30:27 2026 +0800

    [fix](function) Share DISTINCT keys for percentile_approx_array (#68489)
    
    ### What problem does this PR solve?
    
    Issue Number: close #xxx
    
    Related PR: #xxx
    
    Problem Summary:
    
    `percentile_approx_array` included the quantile array and optional
    compression value in its DISTINCT arguments. Calls over the same value
    column could therefore be classified as separate DISTINCT argument
    groups.
    
    The fix makes only the value expression a DISTINCT argument, allowing
    these calls to share one DISTINCT argument group. The unit test also
    verifies that different value expressions remain in separate groups.
    
    
    ### Release note
    
    Multiple DISTINCT `percentile_approx_array` calls over the same value
    expression can share one DISTINCT argument group.
---
 .../functions/agg/PercentileApproxArray.java       |  5 ++++
 .../rewrite/DistinctAggregateRewriterTest.java     | 29 ++++++++++++++++++++++
 2 files changed, 34 insertions(+)

diff --git 
a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/agg/PercentileApproxArray.java
 
b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/agg/PercentileApproxArray.java
index 72ffeb20594..72822200337 100644
--- 
a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/agg/PercentileApproxArray.java
+++ 
b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/agg/PercentileApproxArray.java
@@ -124,4 +124,9 @@ public class PercentileApproxArray extends 
NotNullableAggregateFunction
     public Expression resultForEmptyInput() {
         return new ArrayLiteral(new ArrayList<>(), this.getDataType());
     }
+
+    @Override
+    public List<Expression> getDistinctArguments() {
+        return distinct ? ImmutableList.of(getArgument(0)) : 
ImmutableList.of();
+    }
 }
diff --git 
a/fe/fe-core/src/test/java/org/apache/doris/nereids/rules/rewrite/DistinctAggregateRewriterTest.java
 
b/fe/fe-core/src/test/java/org/apache/doris/nereids/rules/rewrite/DistinctAggregateRewriterTest.java
index 0b30a45104f..fd952184b70 100644
--- 
a/fe/fe-core/src/test/java/org/apache/doris/nereids/rules/rewrite/DistinctAggregateRewriterTest.java
+++ 
b/fe/fe-core/src/test/java/org/apache/doris/nereids/rules/rewrite/DistinctAggregateRewriterTest.java
@@ -21,16 +21,24 @@ import org.apache.doris.catalog.DistributionInfo;
 import org.apache.doris.catalog.HashDistributionInfo;
 import 
org.apache.doris.nereids.rules.analysis.LogicalSubQueryAliasToLogicalProject;
 import 
org.apache.doris.nereids.rules.rewrite.DistinctAggregateRewriter.Strategy;
+import org.apache.doris.nereids.trees.expressions.Alias;
 import org.apache.doris.nereids.trees.expressions.SlotReference;
 import 
org.apache.doris.nereids.trees.expressions.functions.agg.AggregateFunction;
 import org.apache.doris.nereids.trees.expressions.functions.agg.Count;
 import 
org.apache.doris.nereids.trees.expressions.functions.agg.MultiDistinctCount;
 import 
org.apache.doris.nereids.trees.expressions.functions.agg.MultiDistinctGroupConcat;
+import 
org.apache.doris.nereids.trees.expressions.functions.agg.PercentileApproxArray;
 import org.apache.doris.nereids.trees.expressions.functions.agg.Sum0;
 import org.apache.doris.nereids.trees.expressions.functions.scalar.If;
+import org.apache.doris.nereids.trees.expressions.literal.ArrayLiteral;
+import org.apache.doris.nereids.trees.expressions.literal.DoubleLiteral;
 import org.apache.doris.nereids.trees.plans.AbstractPlan;
 import org.apache.doris.nereids.trees.plans.Plan;
+import org.apache.doris.nereids.trees.plans.RelationId;
 import org.apache.doris.nereids.trees.plans.logical.LogicalAggregate;
+import org.apache.doris.nereids.trees.plans.logical.LogicalOneRowRelation;
+import org.apache.doris.nereids.types.DoubleType;
+import org.apache.doris.nereids.util.AggregateUtils;
 import org.apache.doris.nereids.util.MemoPatternMatchSupported;
 import org.apache.doris.nereids.util.PlanChecker;
 import org.apache.doris.qe.SessionVariable;
@@ -245,6 +253,27 @@ public class DistinctAggregateRewriterTest extends 
TestWithFeService implements
         connectContext.getSessionVariable().setAggPhase(0);
     }
 
+    @Test
+    void testPercentileApproxArrayDistinctArgumentGroups() {
+        SlotReference value = SlotReference.of("value", DoubleType.INSTANCE);
+        SlotReference other = SlotReference.of("other", DoubleType.INSTANCE);
+        LogicalOneRowRelation relation = new LogicalOneRowRelation(
+                new RelationId(1), ImmutableList.of(value, other));
+        PercentileApproxArray first = new PercentileApproxArray(true, value,
+                new ArrayLiteral(ImmutableList.of(new DoubleLiteral(0.25))));
+        PercentileApproxArray sameValueOtherParameters = new 
PercentileApproxArray(true, value,
+                new ArrayLiteral(ImmutableList.of(new DoubleLiteral(0.75))), 
new DoubleLiteral(2048));
+        LogicalAggregate<LogicalOneRowRelation> sameValue = new 
LogicalAggregate<>(ImmutableList.of(),
+                ImmutableList.of(new Alias(first, "p25"), new 
Alias(sameValueOtherParameters, "p75")), relation);
+        Assertions.assertEquals(1, 
AggregateUtils.distinctArgumentGroupCountUpToTwo(sameValue));
+
+        PercentileApproxArray otherValue = new PercentileApproxArray(true, 
other,
+                new ArrayLiteral(ImmutableList.of(new DoubleLiteral(0.75))), 
new DoubleLiteral(2048));
+        LogicalAggregate<LogicalOneRowRelation> differentValues = new 
LogicalAggregate<>(ImmutableList.of(),
+                ImmutableList.of(new Alias(first, "p25"), new 
Alias(otherValue, "p75")), relation);
+        Assertions.assertEquals(2, 
AggregateUtils.distinctArgumentGroupCountUpToTwo(differentValues));
+    }
+
     @Test
     void testChooseStrategyWithoutStatsSatisfyDistribution() throws Exception {
         DistinctAggregateRewriter rewriter = 
DistinctAggregateRewriter.INSTANCE;


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

Reply via email to