Repository navigation
Reject collection literals as data-type arguments (STID 1941-1bfa) - #104520
Conversation
Parser change in `ParserDataType` to no longer accept tuple/array/map
literals like `(1)`, `[1, 2]` or `{a: 1}` as arguments to a
parameterized data type (e.g. `multiply((NULL), Int8)` inside a column
type). Previously these were parsed by `ParserAllCollectionsOfLiterals`
into an `ASTLiteral` with `Field::Tuple` (or `Field::Array`) sitting
inside the type's argument list. The formatter then prints that Tuple
literal as `tuple(NULL)` (the explicit function form, see
`FieldVisitorToString::operator()(const Tuple &)`), and re-parsing
`multiply(tuple(NULL), Int8)` in this context yields an
`ASTDataType("tuple")` instead of an `ASTLiteral`, which breaks the AST
round-trip check in `executeQuery` (DEBUG/sanitizer builds) with
`LOGICAL_ERROR: Inconsistent AST formatting` (STID 1941-1bfa).
No real data type takes a collection literal as a parameter — every
parameterized type either takes simple literals (e.g. `FixedString(5)`,
`Decimal(10, 2)`, `DateTime64(3, 'UTC')`), nested types (e.g.
`Nullable(Int32)`, `Array(String)`), or has special handling
(`Tuple(Int32, String)`, `Enum8('a' = 1)`). Rejecting collection
literals at parse time is the cleanest fix: the malformed query is
caught up-front with `SYNTAX_ERROR` instead of crashing later in the
round-trip check.
Existing test `03210_inconsistent_formatting_of_data_types` had one
case (`Array((1), UInt8)`) in the "possibly incorrect but should
round-trip" section that depended on the old behavior. Move it to the
"invalid queries that don't parse" section together with three new
regression cases (`multiply((NULL), Int8)`, `multiply([NULL], Int8)`,
`Nullable(multiply((NULL), Int8))`) covering the STID 1941-1bfa
variants reported in CI.
Closes the chronic STID 1941-1bfa fuzzer family for the
collection-literal-in-data-type variant. CI: PR ClickHouse#100177
(commit 9322e66) AST fuzzer (amd_debug) failure
https://s3.amazonaws.com/clickhouse-test-reports/json.html?PR=100177&sha=9322e66151ea6cc3017cc476e1f8d958bb56421c&name_0=PR&name_1=AST%20fuzzer%20%28amd_debug%29
Co-Authored-By: Claude Opus 4.7 <[email protected]>
Pre-PR Validation GatePer TASK.md Phase 4 step 9 — answering the five mandatory questions: a) Deterministic repro? ✅ Yes. The minimal repro is one statement: Without the fix this aborts with b) Root cause explained? ✅ Yes. The parser uses c) Fix matches root cause? ✅ Yes. The fix is at the source of the divergence: data-type arguments no longer accept collection literals at all. No real data type takes a tuple/array/map literal as a parameter — every parameterized type uses simple literals ( d) Test intent preserved? / New tests added? ✅ Yes. e) Demonstrated in both directions? ✅ Yes. With the master HEAD binary, all three repro queries crash with f) Fix is general, not a narrow patch? ✅ Yes. This is the universal fix for the STID Session: |
|
cc @evillique @alexey-milovidov — could you review this? It fixes the chronic AST fuzzer trunk bug STID 1941-1bfa for the collection-literal-in-data-type variant (fuzzer mutates a column type to |
|
Workflow [PR], commit [427aaa2] Summary: ✅ AI ReviewSummaryThis PR fixes a real parser/formatter round-trip mismatch by rejecting collection literals in data-type argument lists, which turns a DEBUG/sanitizer ClickHouse Rules
Final Verdict
|
LLVM Coverage Report
Changed lines: 100.00% (4/4) · Uncovered code |
…_operators=false` contexts
Inside `CODEC` / `STATISTICS` / `BACKUP_NAME` argument lists, `ASTFunction::formatImpl`
forces `frame.allow_operators = false`, so a multi-argument `Function_tuple` falls back
to its function-call form `tuple(arg, arg, ...)` instead of the operator form
`(arg, arg, ...)`.
`RoundBracketsLayer::getResultImpl` in `src/Parsers/ExpressionListParsers.cpp` sets
`parenthesized = true` on any node it unwraps from a single-element `(expr)`. So when a
query like
CREATE TABLE t (c0 Int CODEC(not((not(materialize(1), materialize(2)))), ZSTD))
ENGINE = Memory
first formats, the parser-synthesized inner `Function_tuple` (lifted from the multi-arg
`not(a, b)`) emits as `tuple(materialize(1), materialize(2))`. Re-parsing the output then
sees `tuple(...)` wrapped in `(...)` from the outer `not(...)` argument list and sets
`parenthesized = true` on the re-parsed `Function_tuple`. The next format pass adds an
extra `(...)` around `tuple(...)` via the `parenthesized` flag's parens emission in
`IAST::decideParensEmission`, breaking the format-parse-format round-trip with
`Logical error: 'Inconsistent AST formatting' (STID 1941-1bfa)` in debug / sanitizer
builds.
Both `tuple(a, b)` and `(tuple(a, b))` denote the same value, so dropping the redundant
outer paren in `allow_operators = false` contexts is semantics-preserving and keeps the
round-trip stable. The new clause mirrors the existing literal-tuple suppression a few
lines above.
The fix is gated on `args.size() > 1` so the single-argument `tuple(x)` form keeps its
existing behaviour, and on `!frame.allow_operators` so plain expression contexts where
the operator form `(a, b)` is canonical are unaffected.
This is a partial fix for chronic STID 1941-1bfa: it addresses the `CODEC` / multi-arg
`not(a, b)` subvariant and the `ALTER TABLE ... MODIFY STATISTICS ... TYPE
concatAssumeInjective((...))` subvariant. The other reported subvariants — `DESCRIBE
TABLE (SELECT ... COLUMNS(multiIf(...)) ...)` and qualifier-chained `db.t.COLUMNS(*)` —
involve different parser/formatter paths (`COLUMNS` matcher / `DESCRIBE` wrapper) and
need separate fixes.
Related: PR ClickHouse#102547 (zoomxi, INSERT-with-SAMPLE-OFFSET), PR ClickHouse#104520 (data-type
collection literals), PR ClickHouse#104626 (lambda-after-comma).
Affected PRs (90-day window per @alexey-milovidov 2026-05-14 directive on PR ClickHouse#100412):
93037, 104440, 104812, 104591, 100177, 100651, 104523, 94517, 103428, 99495, 97540,
103866, 103349, 101447, 102646, 100453, 100386, 99179, 94849, 98677, 99131, 99277,
99275, 99227, 99229, 99246, 98884, 99138, 99021, 99105, 98906, 99055, 99011, 99066,
99033, 97821, 70661, 103389, 103347, 100700, master.
CI report (PR ClickHouse#100412 sighting):
https://s3.amazonaws.com/clickhouse-test-reports/json.html?PR=100412&sha=3284612ceea8078d500d582ce82e5ace86b239cf&name_0=PR&name_1=AST%20fuzzer%20%28amd_debug%2C%20targeted%29
Motivation
AST fuzzer (amd_debug)and related sanitizer/fuzzer jobs hit a chronicLOGICAL_ERROR: Inconsistent AST formatting(STID1941-1bfa) inexecuteQuery.cpp:1280whenever a fuzzed query puts a collection literal ((NULL),[NULL],{a: 1}) inside a parameterized data type's argument list.Latest hit: PR #100177 (commit
9322e66):CI report: https://s3.amazonaws.com/clickhouse-test-reports/json.html?PR=100177&sha=9322e66151ea6cc3017cc476e1f8d958bb56421c&name_0=PR&name_1=AST%20fuzzer%20%28amd_debug%29
The bug has been hit by 20+ unrelated PRs over the last 30 days. Master is unaffected (the round-trip check fires only in DEBUG/sanitizer builds, and master CI doesn't usually run AST fuzzer mutations against the same seed). PR #102547 by @zoomxi (merged 2026-04-29) fixed one specific variant (
INSERT with SAMPLE and OFFSET); this PR addresses the broader collection-literal variant.Root cause
Inside
ParserDataType::parseImpl(src/Parsers/ParserDataType.cpp), arguments to a parameterized data type were parsed withParserAllCollectionsOfLiterals, which accepts(...),[...],{...}(withfalsefor the map case). Formultiply((NULL), Int8)this givesDataType_multiply -> [Literal_Tuple_(NULL), DataType_Int8].Formatting that AST goes through
FieldVisitorToString::operator()(const Tuple &), which prints a single-element Tuple literal astuple(NULL)(the explicit function form, used to avoid(NULL)re-parsing as a parenthesized expression in regular SQL contexts).Re-parsing
multiply(tuple(NULL), Int8)in data-type-argument context:tuple(NULL)starts with an identifier (not(/[/{), soParserAllCollectionsOfLiteralsdoesn't trigger. Falls through toParserDataType, which parses it asASTDataType("tuple")with aLiteral_NULLchild. Different shape →getTreeHashdiffers →LOGICAL_ERROR.The same goes for
multiply([NULL], Int8)(Literal_Array_(NULL)↔[NULL]re-parsed as a Literal_Array... but the formatter for empty arrays / various edge cases also drifts). I confirmed the exact same crash for both(NULL)and[NULL]variants locally.Fix
No real data type takes a collection literal as a parameter:
FixedString(5),Decimal(10, 2),DateTime64(3, 'UTC')Nullable(Int32),Array(String),LowCardinality(...)Tuple(Int32, String),Enum8('a' = 1, 'b' = 2)(separate code paths in the same function)Replace
ParserAllCollectionsOfLiterals literal_parser(false)withParserLiteral literal_parser. Malformed queries are now rejected at parse time withSYNTAX_ERROR(Code 62) instead of crashing later in the round-trip check.Verified locally:
multiply((NULL), Int8),multiply([NULL], Int8),Nullable(multiply((NULL), Int8))→SYNTAX_ERROR(was:LOGICAL_ERRORcrash)UInt32,Decimal(10,2),DateTime64(3,'UTC'),FixedString(5),Nullable(String),Tuple(...),Array(Tuple(...)),Enum8(...),LowCardinality(Nullable(FixedString(10))),Map(String, Array(Int32)),SimpleAggregateFunction(sum, UInt64),AggregateFunction(uniq, Int32),Variant(...)) — all parse correctly.Test changes
tests/queries/0_stateless/03210_inconsistent_formatting_of_data_types.shhad one caseArray((1), UInt8)in the "possibly incorrect but should round-trip" section that relied on the old behavior. Move it to the "invalid queries that don't parse" section alongside three new regression cases for STID1941-1bfa. The 4 tracked-as-valid cases continue to round-trip unchanged.Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
...
Documentation entry for user-facing changes
Version info
26.5.1.499