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 91f1ac486e5 [fix](function) Preserve DISTINCT in median percentile
conversion (#68386)
91f1ac486e5 is described below
commit 91f1ac486e53a044aa5654759ea74028abddf716
Author: Mryange <[email protected]>
AuthorDate: Thu Sep 24 15:54:49 2026 +0800
[fix](function) Preserve DISTINCT in median percentile conversion (#68386)
`median(DISTINCT expr)` was rewritten to a non-distinct
`percentile(expr, 0.5)`, causing duplicate values to affect the result.
The conversion now preserves the MEDIAN aggregate's DISTINCT flag when
constructing PERCENTILE.
### Release note
None
### Check List (For Author)
- Test <!-- At least one of them must be included. -->
- [ ] Regression test
- [ ] Unit Test
- [ ] Manual test (add detailed scripts or steps below)
- [ ] No need to test or manual test. Explain why:
- [ ] This is a refactor/code format and no logic has been changed.
- [ ] Previous test can cover this change.
- [ ] No code files have been changed.
- [ ] Other reason <!-- Add your reason? -->
- Behavior changed:
- [ ] No.
- [ ] Yes. <!-- Explain the behavior change -->
- Does this need documentation?
- [ ] No.
- [ ] Yes. <!-- Add document PR link here. eg:
https://github.com/apache/doris-website/pull/1214 -->
### Check List (For Reviewer who merge this PR)
- [ ] Confirm the release note
- [ ] Confirm test cases
- [ ] Confirm document
- [ ] Add branch pick label <!-- Add branch pick label that this PR
should merge into -->
---
.../doris/nereids/rules/expression/rules/MedianConvert.java | 2 +-
.../expression/test_convert_median_to_percentile.out | 3 +++
.../expression/test_convert_median_to_percentile.groovy | 13 +++++++++++++
3 files changed, 17 insertions(+), 1 deletion(-)
diff --git
a/fe/fe-core/src/main/java/org/apache/doris/nereids/rules/expression/rules/MedianConvert.java
b/fe/fe-core/src/main/java/org/apache/doris/nereids/rules/expression/rules/MedianConvert.java
index e6e295ef98c..d8144bf2508 100644
---
a/fe/fe-core/src/main/java/org/apache/doris/nereids/rules/expression/rules/MedianConvert.java
+++
b/fe/fe-core/src/main/java/org/apache/doris/nereids/rules/expression/rules/MedianConvert.java
@@ -39,7 +39,7 @@ public class MedianConvert implements
ExpressionPatternRuleFactory {
public List<ExpressionPatternMatcher<? extends Expression>> buildRules() {
return ImmutableList.of(
matchesType(Median.class).then(median ->
- new Percentile(median.child(0), DoubleLiteral.of(0.5))
+ new Percentile(median.isDistinct(), median.child(0),
DoubleLiteral.of(0.5))
).toRule(ExpressionRuleType.MEDIAN_CONVERT)
);
}
diff --git
a/regression-test/data/nereids_rules_p0/expression/test_convert_median_to_percentile.out
b/regression-test/data/nereids_rules_p0/expression/test_convert_median_to_percentile.out
index 3cccc3d6fb0..43e5deec56b 100644
---
a/regression-test/data/nereids_rules_p0/expression/test_convert_median_to_percentile.out
+++
b/regression-test/data/nereids_rules_p0/expression/test_convert_median_to_percentile.out
@@ -19,3 +19,6 @@
-- !select_6 --
2001 125.5
+-- !median_distinct --
+5.5 1
+
diff --git
a/regression-test/suites/nereids_rules_p0/expression/test_convert_median_to_percentile.groovy
b/regression-test/suites/nereids_rules_p0/expression/test_convert_median_to_percentile.groovy
index ea26b5480bd..f5357ae4e05 100644
---
a/regression-test/suites/nereids_rules_p0/expression/test_convert_median_to_percentile.groovy
+++
b/regression-test/suites/nereids_rules_p0/expression/test_convert_median_to_percentile.groovy
@@ -74,6 +74,19 @@ suite("test_convert_median_to_percentile") {
qt_select_5 "${sql5}"
qt_select_6 "${sql6}"
+ sql "DROP TABLE IF EXISTS median_distinct"
+ sql """
+ CREATE TABLE median_distinct (
+ id INT,
+ value INT
+ )
+ DISTRIBUTED BY HASH(id) BUCKETS 1
+ PROPERTIES ("replication_num" = "1")
+ """
+ sql "INSERT INTO median_distinct VALUES (1, 1), (2, 1), (3, 10)"
+ order_qt_median_distinct "SELECT median(DISTINCT value), median(value)
FROM median_distinct"
+ sql "DROP TABLE IF EXISTS median_distinct"
+
sql "DROP TABLE if exists sales"
sql "DROP DATABASE if exists test_convert_median_to_percentile"
}
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]