Skip to content

Commit

Permalink
[BugFix] make max_by/min_by's output result column always nullable (S…
Browse files Browse the repository at this point in the history
…tarRocks#55116)

Signed-off-by: before-Sunrise <[email protected]>
  • Loading branch information
before-Sunrise authored Jan 16, 2025
1 parent 47e386b commit c42afe2
Show file tree
Hide file tree
Showing 3 changed files with 70 additions and 2 deletions.
4 changes: 2 additions & 2 deletions be/src/exec/aggregator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,8 @@

namespace starrocks {

static const std::unordered_set<std::string> ALWAYS_NULLABLE_RESULT_AGG_FUNCS = {"variance_samp", "var_samp",
"stddev_samp", "covar_samp", "corr"};
static const std::unordered_set<std::string> 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";
Expand Down
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
@@ -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;

0 comments on commit c42afe2

Please sign in to comment.