This is an automated email from the ASF dual-hosted git repository.
yiguolei pushed a commit to branch branch-4.0
in repository https://gitbox.apache.org/repos/asf/doris.git
The following commit(s) were added to refs/heads/branch-4.0 by this push:
new 902d8e58d5b branch-4.0: [Fix](Agg) Fix the problem that add_batch
cannot handle rows with null value correctly #60398 (#60604)
902d8e58d5b is described below
commit 902d8e58d5b3a3a463dd93205ecc642598f71c8f
Author: github-actions[bot]
<41898282+github-actions[bot]@users.noreply.github.com>
AuthorDate: Tue Feb 10 21:31:39 2026 +0800
branch-4.0: [Fix](Agg) Fix the problem that add_batch cannot handle rows
with null value correctly #60398 (#60604)
Cherry-picked from #60398
Co-authored-by: linrrarity <[email protected]>
---
.../aggregate_functions/aggregate_function_null.h | 4 ++--
.../aggregate_functions/aggregate_function_sort.h | 2 +-
.../group_concat/test_group_concat.groovy | 28 ++++++++++++++++++++++
3 files changed, 31 insertions(+), 3 deletions(-)
diff --git a/be/src/vec/aggregate_functions/aggregate_function_null.h
b/be/src/vec/aggregate_functions/aggregate_function_null.h
index 5b8e5559a3c..02eb86fe6dc 100644
--- a/be/src/vec/aggregate_functions/aggregate_function_null.h
+++ b/be/src/vec/aggregate_functions/aggregate_function_null.h
@@ -391,7 +391,7 @@ public:
for (size_t i = 0; i < batch_size; ++i) {
this->add(place, columns, i, arena);
}
- } else {
+ } else if (batch_size > 0) {
this->set_flag(place);
const IColumn* nested_column = &column->get_nested_column();
this->nested_function->add_batch_single_place(batch_size,
this->nested_place(place),
@@ -407,7 +407,7 @@ public:
for (size_t i = batch_begin; i <= batch_end; ++i) {
this->add(place, columns, i, arena);
}
- } else {
+ } else if (batch_begin <= batch_end) {
this->set_flag(place);
const IColumn* nested_column = &column->get_nested_column();
this->nested_function->add_batch_range(batch_begin, batch_end,
diff --git a/be/src/vec/aggregate_functions/aggregate_function_sort.h
b/be/src/vec/aggregate_functions/aggregate_function_sort.h
index 3d8bc2480c2..e297c146bd3 100644
--- a/be/src/vec/aggregate_functions/aggregate_function_sort.h
+++ b/be/src/vec/aggregate_functions/aggregate_function_sort.h
@@ -171,7 +171,7 @@ public:
// place is essentially an AggregateDataPtr, passed as a
ConstAggregateDataPtr.
auto* place = const_cast<AggregateDataPtr>(targetplace);
Arena arena;
- if (!this->data(place).block.is_empty_column()) {
+ if (!this->data(place).block.empty()) {
this->data(place).sort();
ColumnRawPtrs arguments_nested;
diff --git
a/regression-test/suites/nereids_p0/group_concat/test_group_concat.groovy
b/regression-test/suites/nereids_p0/group_concat/test_group_concat.groovy
index d54d93bb417..80445e7a898 100644
--- a/regression-test/suites/nereids_p0/group_concat/test_group_concat.groovy
+++ b/regression-test/suites/nereids_p0/group_concat/test_group_concat.groovy
@@ -107,4 +107,32 @@ suite("test_group_concat") {
select * from test_view;
"""
sql """drop view if exists test_view"""
+
+ // Constant Folding Correctness Test
+ sql """ DROP TABLE IF EXISTS test_group_concat_fold_const_t1 """
+ sql """ DROP TABLE IF EXISTS test_group_concat_fold_const_t2 """
+ sql """ CREATE TABLE test_group_concat_fold_const_t1 (
+ pk INT NOT NULL
+ ) DISTRIBUTED BY HASH(pk) BUCKETS 1
+ PROPERTIES ("replication_num" = "1");
+ """
+ sql """ CREATE TABLE test_group_concat_fold_const_t2 (
+ pk INT NOT NULL,
+ val VARCHAR(100) NOT NULL,
+ filter_col DATETIME NOT NULL
+ ) DISTRIBUTED BY HASH(pk) BUCKETS 1
+ PROPERTIES ("replication_num" = "1");
+ """
+ sql """ INSERT INTO test_group_concat_fold_const_t1 VALUES (1), (2), (3);
"""
+ sql """ INSERT INTO test_group_concat_fold_const_t2 VALUES
+ (1, 'aaa', '2020-01-01 00:00:00'),
+ (2, 'bbb', '2020-01-01 00:00:00');
+ """
+ // `SELECT group_concat(...) FROM t1 LEFT JOIN t2 ON ... WHERE t2.col =
'...';`
+ // In constant folding, LEFT JOIN is rewritten as INNER JOIN.
+ // If there are no matching rows, GROUP_CONCAT is not executed and returns
NULL.
+ // In `debug_skip_fold_constant=true`, normal execution of LEFT OUTER
JOIN.
+ // After being filtered by WHERE, there are no matching rows, test if
`add_batch` can correctly handle the case of null values
+ // should return NULL instead of empty values
+ testFoldConst("SELECT group_concat(t2.val ORDER BY t1.pk) AS result FROM
test_group_concat_fold_const_t1 AS t1 LEFT JOIN test_group_concat_fold_const_t2
AS t2 ON t1.pk = t2.pk WHERE t2.filter_col = '2077-01-01 00:00:00';")
}
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]