This is an automated email from the ASF dual-hosted git repository. kxiao pushed a commit to branch branch-2.0 in repository https://gitbox.apache.org/repos/asf/doris.git
commit 8e68472b14f7babd31733157f38318d842cb4571 Author: starocean999 <[email protected]> AuthorDate: Wed Aug 23 10:05:08 2023 +0800 [fix](planner)avg function need support large int param (#23254) * [fix](planner)avg function need support large int param --- .../java/org/apache/doris/catalog/FunctionSet.java | 4 +++ .../trees/expressions/functions/agg/Avg.java | 2 ++ regression-test/data/correctness_p0/test_avg.out | 6 +++++ .../suites/correctness_p0/test_avg.groovy | 30 ++++++++++++++++++++++ 4 files changed, 42 insertions(+) diff --git a/fe/fe-core/src/main/java/org/apache/doris/catalog/FunctionSet.java b/fe/fe-core/src/main/java/org/apache/doris/catalog/FunctionSet.java index 41a9de9b66..d43e49cdbe 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/catalog/FunctionSet.java +++ b/fe/fe-core/src/main/java/org/apache/doris/catalog/FunctionSet.java @@ -1428,6 +1428,10 @@ public class FunctionSet<T> { Lists.<Type>newArrayList(Type.BIGINT), Type.DOUBLE, Type.BIGINT, "", "", "", "", "", "", "", false, true, false, true)); + addBuiltin(AggregateFunction.createBuiltin("avg", + Lists.<Type>newArrayList(Type.LARGEINT), Type.DOUBLE, Type.LARGEINT, + "", "", "", "", "", "", "", + false, true, false, true)); addBuiltin(AggregateFunction.createBuiltin("avg", Lists.<Type>newArrayList(Type.DOUBLE), Type.DOUBLE, Type.DOUBLE, "", "", "", "", "", "", "", diff --git a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/agg/Avg.java b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/agg/Avg.java index 48dff01884..6eea3d9e41 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/agg/Avg.java +++ b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/agg/Avg.java @@ -32,6 +32,7 @@ import org.apache.doris.nereids.types.DecimalV2Type; import org.apache.doris.nereids.types.DecimalV3Type; import org.apache.doris.nereids.types.DoubleType; import org.apache.doris.nereids.types.IntegerType; +import org.apache.doris.nereids.types.LargeIntType; import org.apache.doris.nereids.types.SmallIntType; import org.apache.doris.nereids.types.TinyIntType; @@ -51,6 +52,7 @@ public class Avg extends NullableAggregateFunction FunctionSignature.ret(DoubleType.INSTANCE).args(SmallIntType.INSTANCE), FunctionSignature.ret(DoubleType.INSTANCE).args(IntegerType.INSTANCE), FunctionSignature.ret(DoubleType.INSTANCE).args(BigIntType.INSTANCE), + FunctionSignature.ret(DoubleType.INSTANCE).args(LargeIntType.INSTANCE), FunctionSignature.ret(DoubleType.INSTANCE).args(DoubleType.INSTANCE), FunctionSignature.ret(DecimalV2Type.SYSTEM_DEFAULT).args(DecimalV2Type.SYSTEM_DEFAULT), FunctionSignature.ret(DecimalV3Type.WILDCARD).args(DecimalV3Type.WILDCARD) diff --git a/regression-test/data/correctness_p0/test_avg.out b/regression-test/data/correctness_p0/test_avg.out index 78a39b2a9c..cc4e2ae2ba 100644 --- a/regression-test/data/correctness_p0/test_avg.out +++ b/regression-test/data/correctness_p0/test_avg.out @@ -2,3 +2,9 @@ -- !select -- 9.18181818181868E14 +-- !select2 -- +\N \N + +-- !select3 -- +\N \N + diff --git a/regression-test/suites/correctness_p0/test_avg.groovy b/regression-test/suites/correctness_p0/test_avg.groovy index 88f8b54088..9e46842687 100644 --- a/regression-test/suites/correctness_p0/test_avg.groovy +++ b/regression-test/suites/correctness_p0/test_avg.groovy @@ -39,4 +39,34 @@ suite("test_avg") { } qt_select """ SELECT AVG(c_bigint) FROM ${tableName} """ sql""" DROP TABLE IF EXISTS ${tableName} """ + + + sql """ drop table if exists avg_test; """ + sql """ + CREATE TABLE `avg_test` ( + `k1` tinyint(4) NULL, + `k2` smallint(6) NULL, + `k3` int(11) NULL, + `k4` bigint(20) NULL, + `k5` DECIMAL NULL, + `k6` char(5) NULL, + `k10` date NULL, + `k11` datetime NULL, + `k7` varchar(20) NULL, + `k8` double MAX NULL, + `k9` float SUM NULL + ) ENGINE=OLAP + AGGREGATE KEY(`k1`, `k2`, `k3`, `k4`, `k5`, `k6`, `k10`, `k11`, `k7`) + COMMENT 'OLAP' + DISTRIBUTED BY HASH(`k1`) BUCKETS 5 + PROPERTIES ( + "replication_allocation" = "tag.location.default: 1" + ); + """ + sql "set enable_nereids_planner=true" + qt_select2 """select avg(distinct k2), avg(distinct cast(k4 as largeint)) from avg_test;""" + sql "set enable_nereids_planner=false" + qt_select3 """select avg(distinct k2), avg(distinct cast(k4 as largeint)) from avg_test;""" + + sql """ drop table if exists avg_test; """ } --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
