Repository navigation
Use the type default for values missing from Native and JSON input - #131189
PedroTadim merged 1 commit into
Conversation
A column missing from a Native block or from a JSONColumns object, and an element of a named Tuple missing from a JSON object, were filled with the column zero (`cloneResized`, `insertManyDefaults`, `insertDefault`). For an `Enum` whose members do not include 0 that stores a value outside the type, and every later text read of the table fails with UNKNOWN_ELEMENT_OF_ENUM; for an Enum that has 0 as a non-first member it silently stores the wrong member. Only `IDataType::insertDefaultInto` knows the type default. Take the type default at the three sites when it is not the column zero (`isDefaultInsertTrivial`), the same branch the hash join uses (`HashJoinResult.cpp`); trivial types keep their current code path, and a missing `Nothing` element is still accepted. `SerializationTuple` only held element serializations, so it now also holds the element types, used only for these defaults. They are not part of its pool key: the key of each element serialization already determines the default of its type (`Enum` hashes its values, a `JSON` element is never pooled), and hashing the types would hash the whole declaration of a large `Enum` on every serialization request (the `Map(Enum16, Int64)` of `system.metric_log`). Related: ClickHouse#130898 Co-Authored-By: Claude Opus 5.5 <[email protected]>
Internal second-model review (2 rounds, head e382c90)
Round 2 (delta re-review of the fix): no findings. |
Pre-PR validation gate (click to expand)
Session id: cron:clickhouse-impl-slot-6:20261113-021000 |
|
Workflow [PR], commit [e382c90] Summary: ✅
AI ReviewSummaryPR #131189 uses type defaults for columns missing from Missing context / blind spots
Final Verdict✅ Approve — no actionable code findings. Required CI checks still need to complete successfully before merge. |
Build profile diff (arm_release)Comparing ✅ No significant changes. Binary sizes
The official master build is compiled with Slowest function optimization changes (ThinLTO)Median per-function time ratio to the master baseline:
Compile time of recompiled translation units16 translation units recompiled, 53 s compile time in total, 16 of them have a recent master baseline. |
|
@groeneai I am seeing lots of prs fixing default values for types today. Are you sure there is no design issue? |
|
Yes, there is one, and it is specific to
Measured on master
Options:
The open PRs fix bugs present in released versions, so I would keep them. I will hold the remaining per-site work (the nested paths) until you choose. Do you want me to do 1, with 2 as a separate PR, or do you prefer another direction? |
544355c
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]>
Related: #130898
Related: #130259
Related: #130975
Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
A column missing from
NativeorJSONColumnsinput, and an element of a namedTuplemissing from a JSON object, get the default of their type instead of the zero of the column: anEnumwithout a 0 member stored an invalid value, and every later read of the table failed withUNKNOWN_ELEMENT_OF_ENUM.Description
On 26.10.2.103 (also 26.8.21.12 and 26.3.33.24),
INSERT INTO t SELECT * FROM file('old.native')into a table whosestatus Enum8('a' = 1, 'b' = 2)column the file lacks stores 0, and every laterSELECT * FROM tfails withUNKNOWN_ELEMENT_OF_ENUM.JSONColumnsinput without the column and a JSON object without a namedTupleelement store the same 0; forEnum8('m' = -3, 'n' = 0, 'o' = 4)they silently store'n'instead of the default'm'.NativeReader::read,JSONColumnsBlockInputFormatBase::readandSerializationTuple::deserializeTupleJSONImplfilled the absent value through the column API (cloneResized,insertManyDefaults,insertDefault), which knows only the column zero; onlyIDataType::insertDefaultIntoknows the type default.When
isDefaultInsertTrivial()is false, the three sites now useinsertManyDefaultsInto/insertDefaultInto, the branchHashJoinResult.cppalready uses; every other type keeps its current code path, and a missingNothingelement is still accepted.SerializationTuplenow holds its element types for these defaults; they are not part of its pool key, because the element serializations already determine the defaults.New test
05628fails on master withCode: 691and passes with the fix (50 randomized runs, ASan).Not covered here: Parquet, ORC, Arrow and Vortex (#130259), CSV, TSV and
*WithNamesformats (#130975); theJSONtype,JSONExtract, Avro withinput_format_avro_allow_missing_fields, Protobuf,VALUES (..., DEFAULT),RowBinaryWithDefaultsand JSONempty_as_defaultstill store the zero.Workflow [PR]
Sync PR [sync-upstream/pr/131189]
Version info
26.11.1.2203-master(included in26.11and later)