From 3b86faf766952031debc408ed690f40cdb983360 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A1nos=20Benjamin=20Antal?= Date: Wed, 15 Oct 2025 13:55:54 +0000 Subject: [PATCH] Merge pull request #88440 from korowa/fix-gby-overflow-sparse Fix sparse columns aggregation for any overflow mode --- src/AggregateFunctions/IAggregateFunction.h | 5 +++-- .../03657_gby_overflow_any_sparse.reference | 10 ++++++++++ .../0_stateless/03657_gby_overflow_any_sparse.sql | 14 ++++++++++++++ 3 files changed, 27 insertions(+), 2 deletions(-) create mode 100644 tests/queries/0_stateless/03657_gby_overflow_any_sparse.reference create mode 100644 tests/queries/0_stateless/03657_gby_overflow_any_sparse.sql diff --git a/src/AggregateFunctions/IAggregateFunction.h b/src/AggregateFunctions/IAggregateFunction.h index ee227db6d9d5..5b1fd9587529 100644 --- a/src/AggregateFunctions/IAggregateFunction.h +++ b/src/AggregateFunctions/IAggregateFunction.h @@ -482,8 +482,9 @@ class IAggregateFunctionHelper : public IAggregateFunction auto offset_it = column_sparse.getIterator(row_begin); for (size_t i = row_begin; i < row_end; ++i, ++offset_it) - static_cast(this)->add(places[offset_it.getCurrentRow()] + place_offset, - &values, offset_it.getValueIndex(), arena); + if (places[offset_it.getCurrentRow()]) + static_cast(this)->add(places[offset_it.getCurrentRow()] + place_offset, + &values, offset_it.getValueIndex(), arena); } void mergeBatch( diff --git a/tests/queries/0_stateless/03657_gby_overflow_any_sparse.reference b/tests/queries/0_stateless/03657_gby_overflow_any_sparse.reference new file mode 100644 index 000000000000..7f1bc308d222 --- /dev/null +++ b/tests/queries/0_stateless/03657_gby_overflow_any_sparse.reference @@ -0,0 +1,10 @@ +0 0 +1 0 +2 0 +3 0 +4 0 +5 0 +6 0 +7 0 +8 0 +9 0 diff --git a/tests/queries/0_stateless/03657_gby_overflow_any_sparse.sql b/tests/queries/0_stateless/03657_gby_overflow_any_sparse.sql new file mode 100644 index 000000000000..9d0891b6b710 --- /dev/null +++ b/tests/queries/0_stateless/03657_gby_overflow_any_sparse.sql @@ -0,0 +1,14 @@ +DROP TABLE IF EXISTS 03657_gby_overflow; + +CREATE TABLE 03657_gby_overflow(key UInt64, val UInt16) ENGINE = MergeTree ORDER BY tuple() +AS SELECT number, 0 from numbers(100000); + +SELECT key, any(val) FROM 03657_gby_overflow GROUP BY key ORDER BY key LIMIT 10 +SETTINGS group_by_overflow_mode = 'any', + max_rows_to_group_by = 100, + max_threads = 1, + max_block_size = 100, + group_by_two_level_threshold = 1000000000, + group_by_two_level_threshold_bytes = 1000000000; + +DROP TABLE 03657_gby_overflow;