Repository navigation
Refactor convertToFullIfNeeded to avoid issues with recursive LowCardinality stripping - #107773
Conversation
…LowCardinality stripping `convertToFullIfNeeded` conflated two unrelated operations: stripping internal representation wrappers (Const/Sparse/Replicated) and stripping `LowCardinality`. The former is always safe — it normalizes column representation without changing the semantic type. The latter changes the type, requiring symmetric updates on the `DataType` side. Mixing both in one recursive method caused a trail of bugs with `Variant`/`Dynamic` columns (column/type mismatches when inner `LowCardinality` was stripped from columns but preserved in types) and led to workarounds in `concat`, `format`, `concatWithSeparator`, and `KeyCondition`. The new `convertToFullIfWrapped` only strips Const/Replicated/Sparse — recursively through subcolumns — and never touches `LowCardinality`. Callers that also need `LowCardinality` removed chain `->convertToFullColumnIfLowCardinality()` for top-level removal, or use `recursiveRemoveLowCardinality` for recursive removal. This eliminates the need for the no-op overrides in `ColumnVariant` and `ColumnDynamic` (which existed solely to prevent recursive LC stripping), removes the manual four-call-chain workarounds in `concat`/`format`/`concatWithSeparator` and `KeyCondition`, and structurally prevents the class of bugs where `convertToFullIfNeeded` would bypass `ColumnVariant`'s override when invoked on a `Const`-wrapped `Variant`. Related: #107373 Co-Authored-By: Claude Opus 4.6 <[email protected]>
|
Workflow [PR], commit [ac168bc] Summary: ❌
AI ReviewSummaryThis PR splits PR Metadata
Findings💡 Nits
Final VerdictStatus: ✅ Approve |
…:ClickHouse/ClickHouse into refactor-convertToFullIfWrapped
| @@ -1,5 +1,5 @@ | |||
| -- Concat with Variant type containing LowCardinality caused a LOGICAL_ERROR | |||
| -- because convertToFullIfNeeded recursively stripped LowCardinality from inside the Variant column | |||
| -- because convertToFullIfWrapped recursively stripped LowCardinality from inside the Variant column | |||
There was a problem hiding this comment.
This comment now attributes the old behavior to the new helper: convertToFullIfWrapped explicitly does not strip LowCardinality. The same mechanical rename appears in 03988_concat_with_separator_format_variant_low_cardinality.sql, 03989_set_low_cardinality_in_tuple.sql, 03990_set_dynamic_low_cardinality_join_runtime_filter.sql, 03991_set_variant_low_cardinality_in_global_in.sql, and 04105_key_condition_nested_lc_variant.sql.
Please keep the root-cause prose tied to the old convertToFullIfNeeded behavior, e.g. say the old helper recursively stripped nested LowCardinality while the new wrapper-only helper avoids that mismatch. Otherwise these regression tests document the opposite of the API contract introduced by the PR.
…or-convertToFullIfWrapped
LLVM Coverage Report
Changed lines: Changed C/C++ lines covered: 147/149 (98.66%) · Uncovered code |
Pick up the merged fix #107773 (Avogar's `convertToFullIfNeeded` refactor, commit eb3d620) which resolves the AST-fuzzer flake #107598 (`Bad cast from type DB::ColumnString to DB::ColumnLowCardinality`, STID 4054-600e) that was the sole functional red on this PR's CI. No code change to the PR itself.
Two differences against 26.3 had to be reconciled: - 26.3 has no `should_materialize` filter, so the fix applies to its materialize-every-column loop; - 26.3 has no `convertToFullIfWrapped`: that is master's post-rename name, from #107773, which also split `LowCardinality` stripping out of it. The predecessor `convertToFullIfNeeded` is present here and performs the same recursion into subcolumns, which is the actual fix - the previous explicit `convertToFullColumnIfReplicated`/`Const`/`Sparse` chain only converted the top level, so a sparse element inside a Tuple stayed sparse. The outer `recursiveRemoveLowCardinality` is kept as it was on this branch. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
Same two differences as the 26.3 cherry-pick: 26.6 has no `should_materialize` filter, so the fix applies to its materialize-every-column loop, and it has no `convertToFullIfWrapped` - that is master's name after #107773. The predecessor `convertToFullIfNeeded` is present here and does the same recursion into subcolumns, which is the fix: the explicit `convertToFullColumnIfReplicated`/`Const`/`Sparse` chain only converted the top level, leaving a sparse element inside a Tuple sparse. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
…ToFullIfWrapped Refactor `convertToFullIfNeeded` to avoid issues with recursive `LowCardinality` stripping
The change is taken as in the original (1a44640, #130895), with the adaptations below. Adapted: - `src/Formats/NativeReader.h`, `src/Formats/NativeReader.cpp`: the new `allowed_kinds_` parameter and the `allowed_kinds(allowed_kinds_)` initializer go after `block_missing_values_`, without the master-only `type_cache_` (`NativeReaderTypeCache`, #129831). The branch keeps its own `format_settings_ = std::nullopt` default. - `src/Processors/Formats/Impl/NativeFormat.cpp` (`makeReader`): the `/*type_cache_=*/ nullptr,` argument is dropped. The file merged without a conflict, but would not compile as merged. - `src/Server/TCPHandler.cpp`: the original only adds the `ISerialization::KindSet{ISerialization::Kind::DEFAULT}` argument; `getNativeWireFormatSettings` (#123649) is on its context lines and is not on the branch. `skipDataPacket` passes no format settings here, so an explicit `std::nullopt` stands in that position. `initBlockInput` keeps `getFormatSettings(state.query_context)`, with an explicit `nullptr` for `block_missing_values_` and without `type_cache_`. Both comments of the original are kept. - `src/Interpreters/AsynchronousInsertQueue.cpp`: `IColumn::convertToFullIfWrapped` (#107773) is not on the branch, and `convertToFullIfNeeded` also strips `LowCardinality`. The check uses a file-local `hasWrappedColumn` instead: a `ColumnBLOB`, `ColumnConst`, `ColumnReplicated` or `ColumnSparse` at any nesting depth, `LowCardinality` left alone, nothing converted. The exception and its message are as in the original. The only producers of `pushQueryWithBlock` on the branch are the two calls in `TCPHandler::processAsyncInsertQuery`: a header without columns, and the squashed blocks that `initBlockInput` reads, which now accepts only the default kind. Left out: - `tests/queries/0_stateless/04616_replicated_serialization_oob_index_native_protocol.python` and `.reference`: the scenarios the branch does not have: invalid index type size, index row count mismatch, sparse over replicated (#114186) and huge element count (#129932). The rewrite of the two existing scenarios and the new `replicatedTupleElementScenario` and `replicatedOnInsertScenario` are kept, with their reference lines. - `tests/queries/0_stateless/05473_sparse_truncated_values_native_protocol.python`, `.reference`, `.sh`: the original only edits this test, and it comes from #128363, which is not on the branch (modify/delete conflict). - `docs/resources/develop-contribute/native-protocol/format.mdx`: the branch has no English specification of the `Native` format, so the hunks have nowhere to go (modify/delete conflict). `tests/queries/0_stateless/helpers/fake_native_server.py` is as in the original here. It does not work with the client of this branch, which sends a `Ping` before each query; the next commit adapts it. Everything else merged without conflicts and has the same changed lines as the original. Co-Authored-By: Claude Fable 5.2 <[email protected]>
convertToFullIfNeededconflated two unrelated operations: stripping internal representation wrappers (Const/Sparse/Replicated) and strippingLowCardinality. The former is always safe — it normalizes column representation without changing the semantic type. The latter changes the type, requiring symmetric updates on theDataTypeside. Mixing both in one recursive method caused a trail of bugs withVariant/Dynamiccolumns (column/type mismatches when innerLowCardinalitywas stripped from columns but preserved in types) and led to workarounds inconcat,format,concatWithSeparator, andKeyCondition.The new
convertToFullIfWrappedonly stripsConst/Replicated/Sparse— recursively through subcolumns — and never touchesLowCardinality. Callers that also needLowCardinalityremoved chain->convertToFullColumnIfLowCardinality()for top-level removal, or userecursiveRemoveLowCardinalityfor recursive removal.This eliminates the need for the no-op overrides in
ColumnVariantandColumnDynamic(which existed solely to prevent recursive LC stripping), removes the manual four-call-chain workarounds inconcat/format/concatWithSeparatorandKeyCondition, and structurally prevents the class of bugs whereconvertToFullIfNeededwould bypassColumnVariant's override when invoked on aConst-wrappedVariant.Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
Refactor
convertToFullIfNeededto avoid issues with recursiveLowCardinalitystripping.Closes #107373
Closes #107598