Fix CreateColumnByType for SimpleAggregateFunction with non-terminal inner type - #542
Open
polyglotAI-bot wants to merge 1 commit into
Open
Conversation
…inner type CreateColumnByType returned nullptr for a SimpleAggregateFunction whose value type is a non-terminal wrapper such as LowCardinality, Nullable, Array, Tuple, Map or Enum (e.g. SimpleAggregateFunction(anyLast, LowCardinality(String))), which made reading any block containing such a column fail with "unsupported column type". The factory handled the SimpleAggregateFunction meta by calling CreateTerminalColumn on the inner type, but that only covers terminal type codes and falls through to nullptr for wrapper metas. Every other wrapper (Array, Nullable, Tuple, Map, LowCardinality) recurses through CreateColumnFromAst; SimpleAggregateFunction was the only one restricted to terminals. Recurse through CreateColumnFromAst instead (passing settings so low_cardinality_as_wrapped_column is honored). A SimpleAggregateFunction is transparent on the wire, so the created column matches its inner type. Fixes: #540
Contributor
There was a problem hiding this comment.
Pull request overview
This PR fixes CreateColumnByType failing to construct columns for SimpleAggregateFunction(func, T) when the inner type T is itself non-terminal (e.g., LowCardinality(String), Nullable(String), Array(...), etc.), which previously caused block deserialization to fail (issue #540). It does so by making SimpleAggregateFunction creation recurse through the general AST-driven factory path (so wrappers are handled consistently), and adds both unit and end-to-end tests to prevent regressions.
Changes:
- Fix column factory handling of
TypeAst::SimpleAggregateFunctionby recursing viaCreateColumnFromAst(..., settings)rather than terminal-only creation. - Add parameterized unit tests covering
SimpleAggregateFunctionwith both terminal and non-terminal inner types. - Add an integration test that creates, inserts into, and reads from a table containing
SimpleAggregateFunction(anyLast, LowCardinality(String)).
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
| clickhouse/columns/factory.cpp | Makes SimpleAggregateFunction column creation recurse into the inner type using the same wrapper-aware path and preserves settings propagation. |
| ut/CreateColumnByType_ut.cpp | Adds parameterized coverage ensuring CreateColumnByType returns a non-null column whose type matches the inner type for multiple wrapped inner-type cases. |
| ut/client_ut.cpp | Adds an end-to-end regression test verifying blocks containing SimpleAggregateFunction(..., LowCardinality(String)) can be read successfully. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
Fixes #540.
CreateColumnByType("SimpleAggregateFunction(any, LowCardinality(String))")returnednullptrinstead of a valid column, which made reading any block that contains such a column fail withunsupported column type: SimpleAggregateFunction(...).In
clickhouse/columns/factory.cpp,CreateColumnFromAsthandled theTypeAst::SimpleAggregateFunctionmeta by callingCreateTerminalColumnon the inner (value) type. ButCreateTerminalColumnis aswitchover terminal type codes only — it falls through toreturn nullptrfor non-terminal wrapper metas (LowCardinality,Nullable,Array,Tuple,Map,Enum). Every other wrapper case inCreateColumnFromAstrecurses throughCreateColumnFromAst;SimpleAggregateFunctionwas the only one restricted to terminal inner types.A
SimpleAggregateFunction(func, T)column is serialized on the wire identically to a column of typeT, so the created column must be the column for the inner typeT. The fix recurses throughCreateColumnFromAst(which itself dispatches terminal inner types toCreateTerminalColumn, so the existing terminal path is unchanged), passingsettingsthrough solow_cardinality_as_wrapped_columnis honored for aSimpleAggregateFunction-wrappedLowCardinalityjust as it is for a bare one.Changes
clickhouse/columns/factory.cpp— in theTypeAst::SimpleAggregateFunctioncase, recurse throughCreateColumnFromAst(GetASTChildElement(ast, -1), settings)instead ofCreateTerminalColumn(...)(one-line change).ut/CreateColumnByType_ut.cpp— new parametrized suiteCreateColumnBySimpleAggregateFunctionTypeassertingCreateColumnByTypebuilds the correct column for terminal (contrast — unchanged) and non-terminal inner types:LowCardinality(String),Nullable(String),Array(UInt64),Map(String, UInt64),Enum8(...),Tuple(UInt64, String).ut/client_ut.cpp— new end-to-endClientCase.SimpleAggregateFunctionLowCardinalitythat CREATEs a table with aSimpleAggregateFunction(anyLast, LowCardinality(String))column, inserts rows and reads them back.Test
master(returnsnullptr) for every non-terminal inner type and passes with the fix; the terminal caseSimpleAggregateFunction(sum, UInt64)stays green in both, proving the change is targeted.unsupported column type: SimpleAggregateFunction(anyLast, LowCardinality(String))onmasterand passes with the fix (verified on both uncompressed and LZ4 connections), demonstrating the reported user scenario — reading blocks containing the affected column type — is resolved.Pre-PR validation gate
unsupported column typeonmaster)ut/files)nullptrinputs now build a valid column; the terminal path is byte-identical