From c42afe2439cbc43e7d2f543e85ac876d31ba4ecd Mon Sep 17 00:00:00 2001 From: before-Sunrise <71162020+before-Sunrise@users.noreply.github.com> Date: Thu, 16 Jan 2025 12:40:07 +0800 Subject: [PATCH] [BugFix] make max_by/min_by's output result column always nullable (#55116) Signed-off-by: before-Sunrise --- be/src/exec/aggregator.cpp | 4 +-- .../R/test_max_min_by_with_empty_table | 36 +++++++++++++++++++ .../T/test_max_min_by_with_empty_table | 32 +++++++++++++++++ 3 files changed, 70 insertions(+), 2 deletions(-) create mode 100644 test/sql/test_max_min_by_not_filter_nulls_with_nulls/R/test_max_min_by_with_empty_table create mode 100644 test/sql/test_max_min_by_not_filter_nulls_with_nulls/T/test_max_min_by_with_empty_table diff --git a/be/src/exec/aggregator.cpp b/be/src/exec/aggregator.cpp index 6737b0703ee1f..52e98e5afb8ed 100644 --- a/be/src/exec/aggregator.cpp +++ b/be/src/exec/aggregator.cpp @@ -42,8 +42,8 @@ namespace starrocks { -static const std::unordered_set ALWAYS_NULLABLE_RESULT_AGG_FUNCS = {"variance_samp", "var_samp", - "stddev_samp", "covar_samp", "corr"}; +static const std::unordered_set ALWAYS_NULLABLE_RESULT_AGG_FUNCS = { + "variance_samp", "var_samp", "stddev_samp", "covar_samp", "corr", "max_by_v2", "min_by_v2"}; static const std::string AGG_STATE_UNION_SUFFIX = "_union"; static const std::string AGG_STATE_MERGE_SUFFIX = "_merge"; diff --git a/test/sql/test_max_min_by_not_filter_nulls_with_nulls/R/test_max_min_by_with_empty_table b/test/sql/test_max_min_by_not_filter_nulls_with_nulls/R/test_max_min_by_with_empty_table new file mode 100644 index 0000000000000..5b366f1c9f286 --- /dev/null +++ b/test/sql/test_max_min_by_not_filter_nulls_with_nulls/R/test_max_min_by_with_empty_table @@ -0,0 +1,36 @@ +-- name: test_max_min_by_with_empty_table +CREATE TABLE `primary_table_with_null_partition` ( + `k1` date not null, + `k2` datetime not null, + `k3` varchar(20) not null, + `k4` varchar(20) not null, + `k5` boolean not null, + `v1` tinyint, + `v2` smallint, + `v3` int, + `v4` bigint, + `v5` largeint, + `v6` float, + `v7` double, + `v8` decimal(27,9) + ) + PRIMARY KEY(`k1`, `k2`,`k3`) + COMMENT "OLAP" + PARTITION BY RANGE(`k1`) + ( + PARTITION `p202006` VALUES LESS THAN ("2020-07-01"), + PARTITION `p202007` VALUES LESS THAN ("2020-08-01"), + PARTITION `p202008` VALUES LESS THAN ("2020-09-01") + ) + DISTRIBUTED BY HASH(`k1`, `k2`) BUCKETS 3 + PROPERTIES ( + "replication_num" = "1", + "enable_persistent_index" = "true", + "storage_format" = "v2" + ); +-- result: +-- !result +select max_by(k1,k1) from primary_table_with_null_partition; +-- result: +None +-- !result \ No newline at end of file diff --git a/test/sql/test_max_min_by_not_filter_nulls_with_nulls/T/test_max_min_by_with_empty_table b/test/sql/test_max_min_by_not_filter_nulls_with_nulls/T/test_max_min_by_with_empty_table new file mode 100644 index 0000000000000..e073158b6cb2c --- /dev/null +++ b/test/sql/test_max_min_by_not_filter_nulls_with_nulls/T/test_max_min_by_with_empty_table @@ -0,0 +1,32 @@ +-- name: test_max_min_by_with_empty_table +CREATE TABLE `primary_table_with_null_partition` ( + `k1` date not null, + `k2` datetime not null, + `k3` varchar(20) not null, + `k4` varchar(20) not null, + `k5` boolean not null, + `v1` tinyint, + `v2` smallint, + `v3` int, + `v4` bigint, + `v5` largeint, + `v6` float, + `v7` double, + `v8` decimal(27,9) + ) + PRIMARY KEY(`k1`, `k2`,`k3`) + COMMENT "OLAP" + PARTITION BY RANGE(`k1`) + ( + PARTITION `p202006` VALUES LESS THAN ("2020-07-01"), + PARTITION `p202007` VALUES LESS THAN ("2020-08-01"), + PARTITION `p202008` VALUES LESS THAN ("2020-09-01") + ) + DISTRIBUTED BY HASH(`k1`, `k2`) BUCKETS 3 + PROPERTIES ( + "replication_num" = "1", + "enable_persistent_index" = "true", + "storage_format" = "v2" + ); + +select max_by(k1,k1) from primary_table_with_null_partition; \ No newline at end of file