Repository navigation
Fix reading ORC lists and maps whose element struct has none of the requested fields - #130279
Conversation
…d fields When the requested type of a struct below an ORC list or map (an element, a map key or a map value) names none of the struct's fields, as after a schema evolution that replaced them, `updateIncludeTypeIds` selected no column under it. The ORC reader then dropped the list from the selected type, so it was read as a missing column (`[]` for every row instead of one default tuple per element), and kept a map with only one child, so the MAP read threw `std::out_of_range` from `getSubtype(1)` (abort in debug, SIGSEGV in release) or left `elements` null (SIGSEGV for a struct key). The same happens through a dotted subcolumn of a struct (`t.l`, `tm.m`) and a subcolumn of a flattened Nested column (`n.z`). Selecting a carrier column alone is not enough: its values reach the result through the positional named-tuple cast, and the read-time type hint cannot tell such a struct apart, because on the flattened-subcolumn path the hint is the type of the first subcolumn, not of the struct. So the selection collects every struct below a list or a map (and the struct a flattened Nested subcolumn resolves to) with its requested type, and after all requested columns are resolved, a struct with no included column in its subtree and no included ancestor gets its narrowest field included and is recorded as read only for its count. The STRUCT read returns the recorded type's default values for such a struct. A struct that is read today is never recorded, so every read that works today is unchanged. The values now match what the Arrow reader returns. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Shorten three two-line comments on the count-only struct candidates and map to one line each. 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; 2 rounds, 4 findings) plus my own review (2 rounds).
Severity: ❌ blocker / Session id: cron:clickhouse-review-self-slot-58:20261109-080200 |
Pre-PR validation gate (click to expand)
Session id: cron:clickhouse-impl-self-slot-57:20261109-051200 |
|
cc @alexey-milovidov @vitlibar, could you review this and add the |
|
Workflow [PR], commit [4c8a1af] Summary: ✅
AI ReviewSummaryThe PR preserves ORC list/map shapes and struct presence when requested tuple fields are absent, then matches fields by name after reading. The previous default-value, nested-presence, and shared-projection findings are addressed. One map-key conversion path still bypasses the promised null/default handling. Consumer trace: checked parent structs, list elements and Missing context / blind spots
Findings
Tests
Final Verdict
|
CI finish ledger - 4277aeaEvery failure below has an owner: a fixing PR (mine or external), or a full-effort fix task
The other CIDB Session id: cron:our-pr-ci-monitor:20261109-123010 |
A list element or map key/value struct that has none of the requested fields was filled with `IDataType::getDefault`, which differs from the column default for `Date32` (1900-01-01 vs 1970-01-01). Every other missing value in the ORC reader (a missing column, a missing field of a struct that has some requested fields, which goes through the tuple CAST) uses the column default, so the same absent field read a different value depending on whether another field was requested. Use `insertManyDefaultsInto`: the column default, except for Enum, which gets its first value instead of an invalid 0. Add non-nullable `Date32` and `Enum8` cases with and without an overlapping field to the test. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Build profile diff (arm_release)Comparing ✅ No significant changes. Binary sizes
The official master build is compiled with Object file sizes3 object files changed (+49.64 KiB total), 0 added.
711 more object files are built by the master warmup baseline only (it builds every object-file target, a pull request build only Slowest function optimization changes (ThinLTO)Median per-function time ratio to the master baseline:
Compile time of recompiled translation units9 translation units recompiled, 29 s compile time in total, 9 of them have a recent master baseline. |
|
@groeneai This is waiting on you |
|
@groeneai I'll take over the PR |
|
Thanks for taking it over, and sorry for the slow response. I will not resolve clickhouse-gh threads anymore; the bot resolves them itself. I checked the open blocker (r4516679076) with the CI
Rows 1 and 3 are this PR's bug: the whole list element is defaulted, so a present Also still open from the bot summary: the |
Replace the count-only structs with a by-name match after the read, as in the Arrow reader. A requested struct with no field read gets its narrowest field read only for its size and null map, without converting its values, and the requested elements that were not read are filled with defaults, so a CAST never matches named tuples by position. Shared reads of a struct now serve any request. Unnamed tuples are still matched by position. Co-Authored-By: Claude Opus 5.5 <[email protected]>
| if (!key_type_hint && !DataTypeMap::isValidKeyType(key_column.type)) | ||
| key_type_hint = removeNullableOrLowCardinalityNullable(key_column.type); | ||
| if (key_type_hint) | ||
| key_column = matchORCTupleElementsByName(key_column, key_type_hint, case_insensitive_matching); |
There was a problem hiding this comment.
[Major] Apply null defaults before casting reconstructed map keys
For an ORC column m Map(Tuple(b Nullable(Tuple(a Int32))), String) containing {(NULL):'v'}, request m Map(Tuple(b Tuple(q Int32)), String) with input_format_null_as_default=1. The new matching pass reconstructs b as Nullable(Tuple(q Int32)), preserving its null map, but the immediately following castColumn rejects that null when converting to the non-nullable requested b. Execution never reaches insertNullAsDefaultIfNeeded in orcColumnsToCHChunk.
Consequently, the map-key variant of the newly supported disjoint-field read still throws CANNOT_INSERT_NULL_IN_ORDINARY_COLUMN with default substitution enabled, whereas the equivalent array-element and map-value paths substitute defaults. Please apply null/default handling before this key cast, or defer nested key conversions until the final matching/defaulting pass. Add a nullable nested map-key case checking success with the setting enabled and rejection with it disabled.
There was a problem hiding this comment.
🕵 This is how map keys already behave, not something this change introduces: the key is cast inside the MAP read, before insertNullAsDefaultIfNeeded, so input_format_null_as_default never applies to map keys. A request that shares a field with the file, such as m Map(Tuple(b Tuple(a Nullable(Int32), q Int32)), String), throws the same CANNOT_INSERT_NULL_IN_ORDINARY_COLUMN at 408c787, before this change. The disjoint key only succeeded there because the whole struct was replaced with defaults, which also accepted NULLs with input_format_null_as_default = 0. Now both requests behave the same, and map values keep substituting defaults.
We'll apply the null default handling to map keys before that cast in a follow-up, with tests for both settings.
|
Thanks, I reviewed 4c8a1af and it looks right to me. Checked on a debug build of it:
The new map key finding (#130279 (comment)) reproduces: a key On #130259: understood. I'll repurpose it to unify this rule across the readers along the lines of your note there, keep this PR ORC-only for the backport, and post the result here. |
…none of the requested fields) The unification of the by-name rule for named tuples across the format readers deletes matchORCTupleElementsByName, which exists only in ClickHouse#130279, so this PR builds on it until it merges. Requested in ClickHouse#130279 (comment) Co-Authored-By: Claude Opus 5.5 <[email protected]>
…readers The Arrow, ORC and Parquet readers each realigned a requested named tuple to the read one by name, because CAST converts named tuples without common element names positionally and insertNullAsDefaultIfNeeded pairs tuple elements by position. The copies chose different defaults for a missing element: the first value of an Enum in Arrow, the invalid value 0 in the others and in CAST. CAST gets an internal flag (not a user setting, part of updateHash) that matches named tuples by name also when they have no element name in common, used by castColumnToRequestedType and the reader casts through castColumnMatchingTupleElementsByName. insertNullAsDefaultIfNeeded gets the same flag to pair named tuple elements by name. A missing element or column is filled with the default of its type (insertManyDefaultsInto) in CAST and in every reader. The legacy Arrow by-name block and the ORC matchORCTupleElementsByName are deleted; ArrowIPC keeps only the recursion into requested elements. Requested in ClickHouse#130279 (comment) Design note: ClickHouse#130259 (comment) Co-Authored-By: Claude Opus 5.5 <[email protected]>
…bulk ORC lost case-insensitive matching on the extracted-subcolumn path once its own by-name realignment was removed: `c0.up Tuple(b UInt32)` over a file `UP Tuple(B UInt32)` read `(0)` instead of `(70)` (04401), because the subcolumn hint never reaches `UP` and the exact by-name cast then filled `b`. ArrowIPC's alignStructFieldNamesCaseInsensitive moves to src/Formats/castColumnToRequestedType and ORC calls it at the same point as ArrowIPC: after the read, before null-as-default and the cast. Its named tuple branch now uses the exact-first rule of the ORC struct read: an element spelled exactly keeps its name, and a requested element is taken by at most one case-folded element. The previous first-occurrence lookup renamed both fields of `c0 Tuple(A ..., a ...)` to the same name, so ArrowIPC failed with "Names of tuple elements must be unique", where ORC reads the struct. createColumnWithDefaults (DataTypes/Utils) replaces the per-row insertManyDefaultsInto at the five default-fill sites (CAST, Parquet, legacy Arrow, ArrowIPC, ORC): a bulk cloneResized when the type's default insert is trivial, as before, else one default row replicated with insertManyFrom. Requested in ClickHouse#130279 (comment) Co-Authored-By: Claude Opus 5.5 <[email protected]>
|
#130259 is repurposed along the lines of your note: #130259
One measurement on this PR's count-only carrier: |
Cherry pick #130279 to 26.3: Fix reading ORC lists and maps whose element struct has none of the requested fields
…t struct has none of the requested fields
Cherry pick #130279 to 26.8: Fix reading ORC lists and maps whose element struct has none of the requested fields
…t struct has none of the requested fields
Cherry pick #130279 to 26.9: Fix reading ORC lists and maps whose element struct has none of the requested fields
…t struct has none of the requested fields
Cherry pick #130279 to 26.10: Fix reading ORC lists and maps whose element struct has none of the requested fields
…nt struct has none of the requested fields
Backport #130279 to 26.8: Fix reading ORC lists and maps whose element struct has none of the requested fields
Backport #130279 to 26.10: Fix reading ORC lists and maps whose element struct has none of the requested fields
Backport #130279 to 26.9: Fix reading ORC lists and maps whose element struct has none of the requested fields
Backport #130279 to 26.3: Fix reading ORC lists and maps whose element struct has none of the requested fields
…t struct has none of the requested fields
…t struct has none of the requested fields
…t struct has none of the requested fields
…nt struct has none of the requested fields
Closes: #130274
Related: #130171
Related: #129992
Related: #130259
Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
Fixed reading an ORC struct whose requested
Tuplehas none of the struct's fields (for example after schema evolution): such a list or map no longer loses its elements or crashes, the struct keeps itsNULLs, and the requested fields are filled with default values.Description
On 26.10,
SELECT m FROM file('t.orc', ORC, 'm Map(String, Tuple(c Nullable(String)))')over amap<string, struct<a, b>>column crashes, andl Array(Tuple(d Nullable(Int32)))over a list of such structs returns[]for every row. The same happens for a struct map key, nested lists and maps, dotted subcolumns and flattenedNestedsubcolumns.updateIncludeTypeIdsselects only the struct fields the requestedTuplenames. When it names none, nothing is selected: the ORC reader drops the list and keeps a map with one child, which the MAP read indexes out of bounds. Selecting a field alone is not enough, because the finalCASTconverts named tuples with no element names in common by position, so the field's values would end up in the requested elements.Now a requested struct with nothing selected under it has its narrowest field selected, only for its size and null map: the read skips that field, so its values are not converted. After the read, the struct fields are matched to the requested
Tupleelements by name, throughNullable,ArrayandMap, and the requested elements that were not read are filled with defaults, as the Arrow reader does. The read keeps the file's shape, so a struct read once for several requested columns (a column and its subcolumns) serves each of them. Unnamed tuples are still matched by position.The fix is kept inside the ORC reader to be easy to backport. How the Arrow, ORC and Parquet copies of this rule could be unified is described in #130259 (comment).
Workflow [PR]
Sync PR [sync-upstream/pr/130279]
Version info
26.11.1.1945-master(included in26.11and later)