From 90d0493b60a012be7240c0ec0c0ea7aa925e0152 Mon Sep 17 00:00:00 2001 From: Pxl Date: Fri, 20 Mar 2026 18:12:53 +0800 Subject: [PATCH] [Bug](function) add ndv decimalv2 support (#61546) This pull request focuses on improving support for the `DECIMALV2` data type in aggregate functions and updating related regression tests to ensure correctness. The most important changes are grouped below: ### Aggregate Function Support * Added `TYPE_DECIMALV2` to the supported types for the `approx_count_distinct` aggregate function in `aggregate_function_approx_count_distinct.cpp`, enabling this function to work with `DECIMALV2` columns. ### Regression Test Enhancements * Updated the output in `test_decimalv2.out` to reflect higher precision for `DECIMALV2` values, showing results with more decimal places to match the new behavior. * Added a new test case in `test_decimalv2.groovy` to verify the correct behavior of the `ndv` (number of distinct values) aggregate function on `DECIMALV2` columns. --- ...gregate_function_approx_count_distinct.cpp | 5 +- .../nereids_p0/datatype/test_decimalv2.out | 59 ++++++++++--------- .../nereids_p0/datatype/test_decimalv2.groovy | 2 + 3 files changed, 36 insertions(+), 30 deletions(-) diff --git a/be/src/vec/aggregate_functions/aggregate_function_approx_count_distinct.cpp b/be/src/vec/aggregate_functions/aggregate_function_approx_count_distinct.cpp index b3d46a891520db..81fb8462db14b3 100644 --- a/be/src/vec/aggregate_functions/aggregate_function_approx_count_distinct.cpp +++ b/be/src/vec/aggregate_functions/aggregate_function_approx_count_distinct.cpp @@ -29,8 +29,9 @@ AggregateFunctionPtr create_aggregate_function_approx_count_distinct( const bool result_is_nullable, const AggregateFunctionAttr& attr) { return creator_with_type_list< TYPE_BOOLEAN, TYPE_TINYINT, TYPE_SMALLINT, TYPE_INT, TYPE_BIGINT, TYPE_LARGEINT, - TYPE_FLOAT, TYPE_DOUBLE, TYPE_DECIMAL32, TYPE_DECIMAL64, TYPE_DECIMAL128I, - TYPE_DECIMAL256, TYPE_VARCHAR, TYPE_DATEV2, TYPE_DATETIMEV2, TYPE_IPV4, TYPE_IPV6, + TYPE_FLOAT, TYPE_DOUBLE, TYPE_DECIMALV2, TYPE_DECIMAL32, TYPE_DECIMAL64, + TYPE_DECIMAL128I, TYPE_DECIMAL256, TYPE_VARCHAR, TYPE_DATEV2, TYPE_DATETIMEV2, + TYPE_IPV4, TYPE_IPV6, TYPE_TIMESTAMPTZ>::create(argument_types, result_is_nullable, attr); diff --git a/regression-test/data/nereids_p0/datatype/test_decimalv2.out b/regression-test/data/nereids_p0/datatype/test_decimalv2.out index 70c7ed37cbbf78..7df088d5649870 100644 --- a/regression-test/data/nereids_p0/datatype/test_decimalv2.out +++ b/regression-test/data/nereids_p0/datatype/test_decimalv2.out @@ -1,52 +1,55 @@ -- This file is automatically generated. You should know what you did if you want to edit this -- !sql1 -- -1.230 +1.230000000 -- !sql2 -- 1.230 -- !sql1 -- -1 1.230 -2 2.340 -3 3.450 +1 1.230000000 +2 2.340000000 +3 3.450000000 -- !sql2 -- -1 1.230 1 1.230 -2 2.340 2 2.340 -3 3.450 3 3.450 +1 1.230000000 1 1.230000000 +2 2.340000000 2 2.340000000 +3 3.450000000 3 3.450000000 -- !sql2 -- -1 1.230 1 1.230 -2 2.340 2 2.340 -3 3.450 3 3.450 +1 1.230000000 1 1.230000000 +2 2.340000000 2 2.340000000 +3 3.450000000 3 3.450000000 -- !sql2 -- -1 1.230 1 1.230 -2 2.340 2 2.340 -3 3.450 3 3.450 +1 1.230000000 1 1.230000000 +2 2.340000000 2 2.340000000 +3 3.450000000 3 3.450000000 -- !sql2 -- -1 1.230 1 1.230 -2 2.340 2 2.340 -3 3.450 3 3.450 +1 1.230000000 1 1.230000000 +2 2.340000000 2 2.340000000 +3 3.450000000 3 3.450000000 -- !sql2 -- -1 1.230 1 1.230 -2 2.340 2 2.340 -3 3.450 3 3.450 +1 1.230000000 1 1.230000000 +2 2.340000000 2 2.340000000 +3 3.450000000 3 3.450000000 -- !sql2 -- -1 1.230 1 1.230 -2 2.340 2 2.340 -3 3.450 3 3.450 +1 1.230000000 1 1.230000000 +2 2.340000000 2 2.340000000 +3 3.450000000 3 3.450000000 -- !sql2 -- -1 1.230 1 1.230 -2 2.340 2 2.340 -3 3.450 3 3.450 +1 1.230000000 1 1.230000000 +2 2.340000000 2 2.340000000 +3 3.450000000 3 3.450000000 -- !sql2 -- -1 1.230 1 1.230 -2 2.340 2 2.340 -3 3.450 3 3.450 +1 1.230000000 1 1.230000000 +2 2.340000000 2 2.340000000 +3 3.450000000 3 3.450000000 + +-- !test -- +3 diff --git a/regression-test/suites/nereids_p0/datatype/test_decimalv2.groovy b/regression-test/suites/nereids_p0/datatype/test_decimalv2.groovy index 3bdab1ccd51045..6b689d7f152a38 100644 --- a/regression-test/suites/nereids_p0/datatype/test_decimalv2.groovy +++ b/regression-test/suites/nereids_p0/datatype/test_decimalv2.groovy @@ -84,5 +84,7 @@ suite("test_decimalv2") { sql " set runtime_filter_type = 8; " qt_sql2 "select * from ${tbName} a, ${tbName} b WHERE a.c2 = b.c2 ORDER BY a.c0" + qt_test "select ndv(c2) from ${tbName}; " + sql "DROP TABLE ${tbName}" }