Repository navigation
Fix a NULL element of an Array, Tuple or Map of Enum stored as 0 with input_format_null_as_default - #132086
Conversation
With `input_format_null_as_default` (the default) a NULL element of an
`Array`, a `Tuple` or a `Map` key or value whose type is a non-Nullable
`Enum` was stored as the column zero. 0 is not a member of e.g.
`Enum8('a' = 1, 'b' = 2)`, so the part was written and every later read of
the column failed with UNKNOWN_ELEMENT_OF_ENUM. The same happened for an
empty string element with `input_format_json_empty_as_default`.
Since ClickHouse#131190 / ClickHouse#131198 the `SerializationNullable::deserializeNullAsDefaultOrNested*`
and `JSONUtils::deserializeEmpyStringAsDefaultOrNested` helpers insert
`IDataType::insertDefaultInto` when they are given the type, and every
top-level reader passes it. The element readers of the composite
serializations did not: `SerializationArray` and `SerializationMap` held no
element type, `SerializationTuple` held `elem_types` (ClickHouse#131189) without
passing them, and the `tryDeserializeNullAsDefaultOrNested*` helpers had no
type parameter at all (used by every `tryDeserialize*` of a composite, e.g.
`Variant` text parsing).
`SerializationArray` now holds its element type and `SerializationMap` its
key and value types (mandatory in `create`, so a missed caller does not
compile); `SerializationArray::SubcolumnCreator` passes `prev_type`. The six
`try` helpers take the same trailing `nested_type` as the throwing ones, and
all 21 nested call sites (text, JSON, CSV, CSV split tuple columns, and the
JSON "" path) pass the element type.
The types are deliberately not part of the pool keys: hashing an Enum type
per serialization request was measured 51.9x slower on
`system.metric_log`'s `Map(Enum16(...), Int64)` in ClickHouse#131189. A pooled
serialization keeps the first creator's type, which is correct because
equal element serialization keys imply equal defaults: only `Enum`
(whose key hashes every value), `Tuple` (recursive key) and `JSON`
(never pooled) have a non-trivial default.
Closes ClickHouse#132007
Co-Authored-By: Claude Opus 5.5 <[email protected]>
Internal second-model review: adjudication log (click to expand)Pre-publication review by an independent model (engine: codex; 0 findings) plus my own cold review (3 nits, none blocking).
Severity: ❌ blocker / Session id: cron:clickhouse-review-slot-8:20261116-171400 |
|
cc @antonio2368, could you review this? A NULL (or JSON empty string) element of an Array, Tuple or Map read with input_format_null_as_default got the column zero instead of the element type default, which stored an out-of-domain Enum value; SerializationArray and SerializationMap now hold their element types and all nested call sites pass them to the null-as-default helpers, pool keys unchanged. |
Pre-PR validation gate (click to expand)
Session id: cron:clickhouse-impl-slot-40:20261116-160604 |
|
Workflow [PR], commit [6b6d35c] Summary: ✅
AI ReviewSummaryReviewed #132086 at Final VerdictStatus: ✅ Approve |
Build profile diff (arm_release)Comparing ✅ No significant changes. Binary sizes
The official master build is compiled with Compile time of recompiled translation units664 translation units recompiled, 5683 s compile time in total, 664 of them have a recent master baseline. |
4076a2c
Closes: #132007
Related: #131190
Related: #131189
Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
Fix a
NULLelement of anArray,TupleorMap(key or value) of a non-NullableEnumbeing stored as 0 instead of the default of the element type when read withinput_format_null_as_defaultfrom text formats (Values,JSONEachRow,CSV,TSVand others) or by aCASTfromString. For anEnumwithout a 0 element, every laterSELECTof the column failed withUNKNOWN_ELEMENT_OF_ENUM. The same is fixed for an empty string element withinput_format_json_empty_as_default.Description
On 26.10.2.103 (also reported on 24.8 LTS and 26.8),
INSERT INTO t VALUES ([NULL, 'b'])intoa Array(Enum8('a' = 1, 'b' = 2))stores[0, 2]with the defaultinput_format_null_as_default = 1, andSELECT a FROM tthen fails withUNKNOWN_ELEMENT_OF_ENUM. The same happens for aTupleelement, aMapkey or value, inJSONEachRow,JSONCompactEachRow,CSV,TSV,CAST('[NULL]' AS Array(Enum8(...)))andVarianttext parsing.Root cause: since #131190 the
SerializationNullable::deserializeNullAsDefaultOrNested*helpers insert the default of the type they are given, and every top-level reader passes it. The element readers ofSerializationArray,SerializationMapandSerializationTuplepassed no type, so a nested null still got the column zero:ArrayandMapheld no element type, and thetryvariants of the helpers had no type parameter.Change: one fix for the whole class, through the mechanism the top-level readers already use (the element type's
insertDefaultInto), so no second default mechanism is added toISerialization.SerializationArraygets its element type andSerializationMapits key and value types, as #131189 did forSerializationTuple(not part of the pool key: the element serialization key already determines the default). Thetryhelpers get the samenested_typeparameter, and all 21 nested call sites pass the element type, including the""path ofinput_format_json_empty_as_default. Only types with a non-trivial default change:Enum, and aTupleorJSONholding one.Not covered: a
Valuesrow that falls back to template expressions ([NULL, 2]) and a nested null read fromParquetare rejected (Code: 349/Code: 691) rather than stored as 0, before and after this change.Validation: the new test fails on master (24 rows store 0, the
MergeTreetable is unreadable) and passes with the fix (50/50 randomized runs). 1426 related existing tests: no new failures.Workflow [PR]
Sync PR [sync-upstream/pr/132086]
Version info
26.11.1.2590-master(included in26.11and later)