This is an automated email from the ASF dual-hosted git repository.
morrysnow 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 16c62be4598 [fix](nereids) fix rule AvgDistinctToSumDivCount need add
cast (#56887)
16c62be4598 is described below
commit 16c62be4598bc2687490f2a5e5bac067c21c12f1
Author: feiniaofeiafei <[email protected]>
AuthorDate: Thu Oct 16 16:39:45 2025 +0800
[fix](nereids) fix rule AvgDistinctToSumDivCount need add cast (#56887)
---
.../rules/analysis/AvgDistinctToSumDivCount.java | 3 ++-
.../avg_distinct_to_sum_div_count.out | 4 +++
.../avg_distinct_to_sum_div_count.groovy | 29 ++++++++++++++++++++++
3 files changed, 35 insertions(+), 1 deletion(-)
diff --git
a/fe/fe-core/src/main/java/org/apache/doris/nereids/rules/analysis/AvgDistinctToSumDivCount.java
b/fe/fe-core/src/main/java/org/apache/doris/nereids/rules/analysis/AvgDistinctToSumDivCount.java
index 9b612d7299f..2740e826976 100644
---
a/fe/fe-core/src/main/java/org/apache/doris/nereids/rules/analysis/AvgDistinctToSumDivCount.java
+++
b/fe/fe-core/src/main/java/org/apache/doris/nereids/rules/analysis/AvgDistinctToSumDivCount.java
@@ -57,7 +57,8 @@ public class AvgDistinctToSumDivCount extends
OneRewriteRuleFactory {
((Avg) function).child()));
Count count = (Count)
TypeCoercionUtils.processBoundFunction(
new Count(true, ((Avg)
function).child()));
- Expression divide =
TypeCoercionUtils.processDivide(new Divide(sum, count));
+ Expression divide =
TypeCoercionUtils.castIfNotSameType(TypeCoercionUtils.processDivide(
+ new Divide(sum, count)),
function.getDataType());
if (!function.nullable() && divide.nullable())
{
// add NonNullable to ensure the result of
divide is not nullable,
// otherwise AdjustNullable rule will
throw exception
diff --git
a/regression-test/data/nereids_rules_p0/avg_distinct_to_sum_div_count/avg_distinct_to_sum_div_count.out
b/regression-test/data/nereids_rules_p0/avg_distinct_to_sum_div_count/avg_distinct_to_sum_div_count.out
new file mode 100644
index 00000000000..38654c9ecca
--- /dev/null
+++
b/regression-test/data/nereids_rules_p0/avg_distinct_to_sum_div_count/avg_distinct_to_sum_div_count.out
@@ -0,0 +1,4 @@
+-- This file is automatically generated. You should know what you did if you
want to edit this
+-- !ctas --
+135.55 67.7750
+
diff --git
a/regression-test/suites/nereids_rules_p0/avg_distinct_to_sum_div_count/avg_distinct_to_sum_div_count.groovy
b/regression-test/suites/nereids_rules_p0/avg_distinct_to_sum_div_count/avg_distinct_to_sum_div_count.groovy
new file mode 100644
index 00000000000..826bda8fd8b
--- /dev/null
+++
b/regression-test/suites/nereids_rules_p0/avg_distinct_to_sum_div_count/avg_distinct_to_sum_div_count.groovy
@@ -0,0 +1,29 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements. See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership. The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License. You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied. See the License for the
+// specific language governing permissions and limitations
+// under the License.
+
+suite("avg_distinct_to_sum_div_count") {
+ sql "drop table if exists t1;"
+ sql """ create table t1 (
+ pk int,
+ c1 decimal(12,2) not null)
+ properties("replication_num" = "1");"""
+
+ sql "insert into t1 values(1,12.32),(2,123.23);"
+ sql "drop table if exists testctas;"
+ sql """create table testctas properties("replication_num" = "1") select
sum(distinct c1),avg(distinct c1) from t1;"""
+ qt_ctas "select * from testctas;"
+}
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]