From d41dc1ec61ea93853f0e17a3db27421f0a5df5d1 Mon Sep 17 00:00:00 2001 From: TengJianPing <18241664+jacktengg@users.noreply.github.com> Date: Wed, 15 Nov 2023 17:37:20 +0800 Subject: [PATCH] [fix](agg) fix coredump of multi distinct of decimal128I (#27014) * [fix](agg) fix coredump of multi distinct of decimal128 * fix --- .../aggregate_function_uniq.cpp | 3 ++ .../data/correctness_p0/test_distinct_agg.out | 11 +++++ .../correctness_p0/test_distinct_agg.groovy | 44 ++++++++++++++++++- 3 files changed, 57 insertions(+), 1 deletion(-) diff --git a/be/src/vec/aggregate_functions/aggregate_function_uniq.cpp b/be/src/vec/aggregate_functions/aggregate_function_uniq.cpp index a528162b28740e..97b0fba623cc91 100644 --- a/be/src/vec/aggregate_functions/aggregate_function_uniq.cpp +++ b/be/src/vec/aggregate_functions/aggregate_function_uniq.cpp @@ -48,6 +48,9 @@ AggregateFunctionPtr create_aggregate_function_uniq(const std::string& name, } else if (which.is_decimal64()) { return creator_without_type::create>>( argument_types, result_is_nullable); + } else if (which.is_decimal128i()) { + return creator_without_type::create>>( + argument_types, result_is_nullable); } else if (which.is_decimal128() || which.is_decimal128i()) { return creator_without_type::create>>( argument_types, result_is_nullable); diff --git a/regression-test/data/correctness_p0/test_distinct_agg.out b/regression-test/data/correctness_p0/test_distinct_agg.out index b70da182eeface..d75f85b923cfd5 100644 --- a/regression-test/data/correctness_p0/test_distinct_agg.out +++ b/regression-test/data/correctness_p0/test_distinct_agg.out @@ -1,4 +1,15 @@ -- This file is automatically generated. You should know what you did if you want to edit this +-- !distinct_1 -- + -- !select1 -- 本日 +-- !multi_distinct_1 -- +2 2 + +-- !multi_distinct_2 -- +369 1145 + +-- !multi_distinct_3 -- +184.5 572.5 + diff --git a/regression-test/suites/correctness_p0/test_distinct_agg.groovy b/regression-test/suites/correctness_p0/test_distinct_agg.groovy index 788f5271a6cedc..d69842a5fe6d6b 100644 --- a/regression-test/suites/correctness_p0/test_distinct_agg.groovy +++ b/regression-test/suites/correctness_p0/test_distinct_agg.groovy @@ -56,7 +56,7 @@ suite("test_distinct_agg") { result([['1', '2023-01-10', 1L]]) } - sql '''SELECT `b`.`dt` AS `dt` + qt_distinct_1 '''SELECT `b`.`dt` AS `dt` FROM (SELECT `dt`AS `dt`, count(DISTINCT `role_id`) AS `pay_role`, @@ -117,4 +117,46 @@ suite("test_distinct_agg") { sql 'drop view if exists dim_v2' sql 'drop view if exists dim_v3' sql 'drop table if exists test_distinct_agg_t' + + sql "drop table if exists multi_distinct_agg_tab;" + + sql """ + CREATE TABLE `multi_distinct_agg_tab` ( + `k1` bigint(20) NULL, + `k2` varchar(20) NULL, + `d1` DECIMAL(18, 0) NULL, + `d2` DECIMAL(38, 0) NULL + ) ENGINE = OLAP DUPLICATE KEY(`k1`) DISTRIBUTED BY HASH(`k1`) BUCKETS 2 PROPERTIES ( + "replication_allocation" = "tag.location.default: 1" + ); + """ + + sql """ + INSERT INTO + `multi_distinct_agg_tab` (`k1`, `k2`, `d1`, `d2`) + VALUES (1, 'aaa', 123, 356),(2, 'bbb', 123, 789), (3, 'ccc', 246, 789); + """ + sql "sync" + + qt_multi_distinct_1 """ + select + count(distinct d1), + count(distinct d2) + from + multi_distinct_agg_tab; + """ + qt_multi_distinct_2 """ + select + sum(distinct d1), + sum(distinct d2) + from + multi_distinct_agg_tab; + """ + qt_multi_distinct_3 """ + select + avg(distinct d1), + avg(distinct d2) + from + multi_distinct_agg_tab; + """ } \ No newline at end of file