From 5c21935237281da99395a8357159b36d05dddac7 Mon Sep 17 00:00:00 2001 From: zhangstar333 Date: Mon, 18 Nov 2024 10:09:15 +0800 Subject: [PATCH] [optimization](agg) add float/double type in agg percentile_array (#43953) Related PR: #41206 Problem Summary: before in pr #41206 have support float/double in percentile function, and percentile_array is the same logical, so it's could support float/double also. doc: https://github.com/apache/doris-website/pull/1350 --- .../aggregate_function_percentile.cpp | 2 +- .../functions/agg/PercentileArray.java | 5 +++++ .../test_aggregate_percentile_no_cast.out | 3 +++ .../test_aggregate_percentile_no_cast.groovy | 17 +++++++++++++++++ 4 files changed, 26 insertions(+), 1 deletion(-) diff --git a/be/src/vec/aggregate_functions/aggregate_function_percentile.cpp b/be/src/vec/aggregate_functions/aggregate_function_percentile.cpp index bb4e1bd81e3db0..40b94168bf108f 100644 --- a/be/src/vec/aggregate_functions/aggregate_function_percentile.cpp +++ b/be/src/vec/aggregate_functions/aggregate_function_percentile.cpp @@ -66,7 +66,7 @@ void register_aggregate_function_percentile(AggregateFunctionSimpleFactory& fact creator_with_numeric_type::creator); factory.register_function_both( "percentile_array", - creator_with_integer_type::creator); + creator_with_numeric_type::creator); } void register_percentile_approx_old_function(AggregateFunctionSimpleFactory& factory) { diff --git a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/agg/PercentileArray.java b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/agg/PercentileArray.java index 49a0f836aedb09..61d4a328c0f177 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/agg/PercentileArray.java +++ b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/agg/PercentileArray.java @@ -27,6 +27,7 @@ import org.apache.doris.nereids.types.ArrayType; import org.apache.doris.nereids.types.BigIntType; import org.apache.doris.nereids.types.DoubleType; +import org.apache.doris.nereids.types.FloatType; import org.apache.doris.nereids.types.IntegerType; import org.apache.doris.nereids.types.LargeIntType; import org.apache.doris.nereids.types.SmallIntType; @@ -45,6 +46,10 @@ public class PercentileArray extends NotNullableAggregateFunction implements BinaryExpression, ExplicitlyCastableSignature { public static final List SIGNATURES = ImmutableList.of( + FunctionSignature.ret(ArrayType.of(DoubleType.INSTANCE)) + .args(DoubleType.INSTANCE, ArrayType.of(DoubleType.INSTANCE)), + FunctionSignature.ret(ArrayType.of(DoubleType.INSTANCE)) + .args(FloatType.INSTANCE, ArrayType.of(DoubleType.INSTANCE)), FunctionSignature.ret(ArrayType.of(DoubleType.INSTANCE)) .args(LargeIntType.INSTANCE, ArrayType.of(DoubleType.INSTANCE)), FunctionSignature.ret(ArrayType.of(DoubleType.INSTANCE)) diff --git a/regression-test/data/nereids_p0/sql_functions/aggregate_functions/test_aggregate_percentile_no_cast.out b/regression-test/data/nereids_p0/sql_functions/aggregate_functions/test_aggregate_percentile_no_cast.out index ead42332d0c84a..d9149d7cdddc65 100644 --- a/regression-test/data/nereids_p0/sql_functions/aggregate_functions/test_aggregate_percentile_no_cast.out +++ b/regression-test/data/nereids_p0/sql_functions/aggregate_functions/test_aggregate_percentile_no_cast.out @@ -43,3 +43,6 @@ 12 127.0 126.9885 12.0 12.0115 127 127.0 127.0 127.0 127.0 +-- !select -- +[19.5, 24.25, 101.325] + diff --git a/regression-test/suites/nereids_p0/sql_functions/aggregate_functions/test_aggregate_percentile_no_cast.groovy b/regression-test/suites/nereids_p0/sql_functions/aggregate_functions/test_aggregate_percentile_no_cast.groovy index 412bec35d8ff8c..816bc1f606990d 100644 --- a/regression-test/suites/nereids_p0/sql_functions/aggregate_functions/test_aggregate_percentile_no_cast.groovy +++ b/regression-test/suites/nereids_p0/sql_functions/aggregate_functions/test_aggregate_percentile_no_cast.groovy @@ -112,4 +112,21 @@ suite("test_aggregate_percentile_no_cast") { SELECT ARG0,PERCENTILE(NULLABLE(ARG0),1) OVER(ORDER BY t.ARG0 ROWS BETWEEN CURRENT ROW AND UNBOUNDED FOLLOWING ) as a,PERCENTILE(NULLABLE(ARG0),0.9999) OVER(ORDER BY t.ARG0 ROWS BETWEEN CURRENT ROW AND UNBOUNDED FOLLOWING ) as b,PERCENTILE(NULLABLE(ARG0),0) OVER(ORDER BY t.ARG0 ROWS BETWEEN CURRENT ROW AND UNBOUNDED FOLLOWING ) as c,PERCENTILE(NULLABLE(ARG0),0.0001) OVER(ORDER BY t.ARG0 ROWS BETWEEN CURRENT ROW AND UNBOUNDED FOLLOWING ) as d FROM (SELECT TEMPDATA . data, TABLE0.ARG0 FROM TEMPDATA CROSS JOIN (SELECT data AS ARG0 FROM TINYINTDATA_NOT_EMPTY_NOT_NULLABLE ) AS TABLE0) t GROUP BY ARG0 order by ARG0; """ + sql "DROP TABLE IF EXISTS percentile_test_db2" + sql """ + CREATE TABLE IF NOT EXISTS percentile_test_db2 ( + id int, + level double + ) + DISTRIBUTED BY HASH(id) BUCKETS 1 + PROPERTIES ( + "replication_num" = "1" + ) + """ + explain { + sql("""select percentile_array(level,[0.5,0.55,0.805])from percentile_test_db2;""") + notContains("cast") + } + sql "INSERT INTO percentile_test_db2 values(1,10.1), (2,8.2), (2,114.3) ,(3,10.4) ,(5,29.5) ,(6,101.6)" + qt_select "select percentile_array(level,[0.5,0.55,0.805])from percentile_test_db2;" }