Skip to content

Commit

Permalink
[optimization](agg) add float/double type in agg percentile_array (#4…
Browse files Browse the repository at this point in the history
…3953)

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: apache/doris-website#1350
  • Loading branch information
zhangstar333 committed Feb 19, 2025
1 parent 1f858d9 commit 5c21935
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ void register_aggregate_function_percentile(AggregateFunctionSimpleFactory& fact
creator_with_numeric_type::creator<AggregateFunctionPercentile>);
factory.register_function_both(
"percentile_array",
creator_with_integer_type::creator<AggregateFunctionPercentileArray>);
creator_with_numeric_type::creator<AggregateFunctionPercentileArray>);
}

void register_percentile_approx_old_function(AggregateFunctionSimpleFactory& factory) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -45,6 +46,10 @@ public class PercentileArray extends NotNullableAggregateFunction
implements BinaryExpression, ExplicitlyCastableSignature {

public static final List<FunctionSignature> 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))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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]

Original file line number Diff line number Diff line change
Expand Up @@ -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;"
}

0 comments on commit 5c21935

Please sign in to comment.