Repository navigation
Fix Bad cast ColumnSparse to ColumnString in groupConcat over Tuple with sparse subcolumn - #108790
Conversation
…ith sparse subcolumn The Aggregator only stripped top-level sparsity from aggregate arguments. A column that is dense at the top level but holds sparse subcolumns (e.g. a Tuple with a sparse String element) was left un-materialized and took the regular add() path. groupConcat text-serializes its argument there, and SerializationString::serializeTextQuoted does assert_cast<const ColumnString&>, which aborts with 'Bad cast from type DB::ColumnSparse to DB::ColumnString'. Materialize an argument with recursiveRemoveSparse() unless it is a genuine top-level ColumnSparse (the only form the addBatchSparse fast-path consumes). recursiveRemoveSparse() recurses into Tuple and is a no-op when nothing is sparse, so the dense and top-level-sparse paths are unchanged. Co-Authored-By: Claude Opus 4.8 <[email protected]>
Pre-PR validation gate (click to expand)
Session id: cron:clickhouse-worker-slot-1:20260629-041000 |
|
cc @KochetovNicolai @nickitat — could you review this? The Aggregator only stripped top-level sparsity from aggregate arguments, so a |
|
Workflow [PR], commit [73dbf25] Summary: ✅
AI ReviewSummaryThis PR fixes aggregate argument preparation so a top-level-dense Missing context / blind spots
Final VerdictStatus: ✅ Approve |
LLVM Coverage Report
Changed lines: Changed C/C++ lines covered by tests: 5/5 (100.00%) | Lost baseline coverage (was covered on master, now uncovered in this PR): 8 line(s) · Uncovered code |
CI finish ledger — 73dbf25CI fully finished on this head (Finish Workflow pass; no checks queued/in_progress; >20-min ingestion buffer). This PR's own fix (the
Session id: cron:our-pr-ci-monitor:20260629-090000 |
|
Fixing PR for the Performance Comparison (arm_release) report-build MEMORY_LIMIT_EXCEEDED host-OOM created: #108804 |
20481eb
|
Hi — this looks like a backport candidate for |
|
The test #115705 adds,
@alexey-milovidov could you apply One note for whoever merges #117073: the window half of that cherry-pick looks like a correct adaptation, since |
The backported test crashed on `26.3` with `Bad cast from type DB::ColumnSparse to DB::ColumnString` already in the plain `SELECT groupConcat(t)` query, before reaching the window function that this backport is about. `Aggregator::prepareAggregateInstructions` on `26.3` only strips top-level sparsity from aggregate arguments. A column that is dense at the top level but holds sparse subcolumns - exactly a `Tuple` with a sparse element - was left un-materialized and took the regular `add` path, where `SerializationString::serializeTextQuoted` does `assert_cast<const ColumnString &>` and aborts. Cherry-pick the one-line condition (and its test) from #108790, which is on `master` but was never backported: keep the argument sparse only when it is a genuine top-level `ColumnSparse`, which is the only form the `addBatchSparse` fast path consumes. `recursiveRemoveSparse` is a no-op when there is nothing sparse to strip, so the dense and top-level-sparse paths are unchanged. Verified against the `26.3` CI binary of this pull request: the reference output of `04416_groupconcat_tuple_sparse_subcolumn` matches, and the query aborts without this fix. Related: #108790
The backported test `05025_group_concat_window_sparse_tuple` also runs a plain `SELECT length(groupConcat(t))`, which aborts on `26.6` because `Aggregator::prepareAggregateInstructions` only strips *top-level* sparsity: a `Tuple` that is dense at the top level but holds a sparse `String` element reaches `SerializationString::serializeTextQuoted` as a `ColumnSparse`. That is fixed on `master` by 73dbf25 (from #108790), which was never backported. Cherry-pick its one-line change and its test `04416_groupconcat_tuple_sparse_subcolumn` so that this backport is self-contained. Reproduced on `26.6` with the PR's own CI binary: the plain `groupConcat` over the sparse `Tuple` aborts, and the `['Sparse','Sparse','Sparse']` reference line is identical to `master`.
Backport #108790 to 26.3: Fix Bad cast ColumnSparse to ColumnString in groupConcat over Tuple with sparse subcolumn
…mnString in groupConcat over Tuple with sparse subcolumn
…concat-tuple-sparse-subcolumn Fix Bad cast ColumnSparse to ColumnString in groupConcat over Tuple with sparse subcolumn
AGG: window function over a Tuple with a sparse element -> crash. Effect in the production build a394e92: wrong/failing (the upstream test fails on it and passes on official 26.8.8.8; evidence/fix_ci_20260925/upstream_repro/residual/115705.PROD263.txt). Upstream patch unchanged, with its test(s): 04416_groupconcat_tuple_sparse_subcolumn, 05025_group_concat_window_sparse_tuple. It also contains the fix of ClickHouse#108790 (groupConcat over a Tuple with a sparse String, 26.3 backport ClickHouse#117568, reproduced on the production build: evidence/fix_ci_20260925/upstream_repro/residual/108790.PROD263.txt): the 26.3 backport ClickHouse#117073 carries the identical Aggregator.cpp change and test 04416, so ClickHouse#108790 needs no separate commit. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Related: #108722
Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
Fix a
Bad cast from type DB::ColumnSparse to DB::ColumnStringlogical error (server abort in debug and sanitizer builds) whengroupConcatis applied to aTuplewhoseStringelement is stored sparse.Description
The Aggregator's
prepareAggregateInstructionsonly stripped top-level sparsity from aggregate arguments: it kept a column as-is whenisSparse()was true (for theaddBatchSparsefast path) and otherwise calledrecursiveRemoveSparse. AColumnTupleis never top-level sparse, so aTuplewith a sparse subcolumn (e.g.Tuple(String)where the innerStringis sparse-serialized) was left un-materialized and took the regularadd()path.groupConcattext-serializes its argument there, andSerializationString::serializeTextQuoteddoesassert_cast<const ColumnString &>, which aborts:The code already removes
LowCardinalityrecursively (recursiveRemoveLowCardinalitydescends intoTuple), but the symmetric recursive sparse removal was missing.Fix: keep the column sparse only when it is a genuine top-level
ColumnSparse(the only formaddBatchSparseconsumes); otherwise materialize it withrecursiveRemoveSparse, which descends intoTupleand is a no-op when nothing is sparse. The dense and top-level-sparse paths are unchanged.Among the single-argument aggregate functions tested over
Tuple(sparse String)(any,anyLast,min,max,argMax,groupArray,uniqExact,count,topK,groupUniqArray), onlygroupConcataborted, because it is the only one that uses text serialization with a denseassert_cast; the fix at the Aggregator level covers any future text-serializing consumer of the regularadd()path. Verified that the result on a sparse-serialized table matches the result on a never-sparse table.Found by the AST fuzzer (CIDB STID 3336-3d40, check
AST fuzzer (arm_asan_ubsan)):https://s3.amazonaws.com/clickhouse-test-reports/json.html?PR=108722&sha=3286c6cd675541995b290a1faafb8f0be49b3740&name_0=PR&name_1=AST%20fuzzer%20%28arm_asan_ubsan%29
No related open issue found.
Added a regression test
04416_groupconcat_tuple_sparse_subcolumnthat aborts the server on the unfixed binary and passes with the fix.Version info
26.7.1.250(included in26.7and later)26.3.30.10