Skip to content

Cherry pick #130279 to 26.3: Fix reading ORC lists and maps whose element struct has none of the requested fields - #130774

Merged
robot-clickhouse-ci-2 merged 6 commits into
backport/26.3/130279from
cherrypick/26.3/130279
Nov 11, 2026
Merged

robot-clickhouse-ci-2 merged 6 commits into
backport/26.3/130279from
cherrypick/26.3/130279

Conversation

@robot-ch-test-poll3

Copy link
Copy Markdown
Contributor

Original pull-request #130279

Do not merge this PR manually

This pull-request is a first step of an automated backporting.
It contains changes similar to calling git cherry-pick locally.
If you intend to continue backporting the changes, then resolve all conflicts if any.
Otherwise, if you do not want to backport them, then just close this pull-request.

The check results does not matter at this step - you can safely ignore them.

Before you resolve anything

Conflicts are often caused by a prerequisite change that has not been backported yet, rather than by a real divergence. The bot re-tries this cherry-pick against the release branch on every run, so if that is the case here it will merge itself as soon as the prerequisite lands, and you will see a comment saying so. Manual resolution is only needed while the conflict persists.

Troubleshooting

If the conflicts were resolved in a wrong way

If this cherry-pick PR is completely screwed by a wrong conflicts resolution, and you want to recreate it:

  • delete the pr-cherrypick label from the PR
  • delete this branch from the repository

You also need to check the Original pull-request for pr-backports-created label, and delete if it's presented there

The PR source

The PR is created in the CI job

groeneai and others added 5 commits November 9, 2026 07:03
…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]>
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]>
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]>
…ithout-requested-fields

Fix reading ORC lists and maps whose element struct has none of the requested fields
@robot-ch-test-poll3 robot-ch-test-poll3 added pr-cherrypick Cherry-pick of merge-commit before backporting. Do not use manually - automated use only! do not test disable testing on pull request pr-bugfix Pull request with bugfix, not backported by default labels Nov 11, 2026
The conflicts come from the `-WithMemoryTracking` containers of #126530,
which 26.3 does not have, and from `unwrapORCNullableTuple`, which 26.3
still has next to the new function: the new code uses std::unordered_set
and std::vector, and both functions are kept.

The test enables `allow_experimental_nullable_tuple_type`, which is off
by default on 26.3, and drops seven queries that fail on 26.3 with or
without this change: the five that read a subcolumn through a list
(`tb.l.b`, `an.x.v`, which 26.3 returns as empty arrays even for a field
that is in the file), and the two that read a field of the NULL struct
`ts` that is in the file as a non-Nullable element of a Nullable Tuple
(by name and by position), which 26.3 rejects with
CANNOT_INSERT_NULL_IN_ORDINARY_COLUMN, also when every field is
requested.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@groeneai

Copy link
Copy Markdown
Collaborator

Besides the container types (26.3 does not have the -WithMemoryTracking containers of #126530), 26.3 still has its own unwrapORCNullableTuple where the new matchORCTupleElementsByName goes, so both are kept.

git fetch https://github.com/groeneai/ClickHouse resolve-26.3-cherrypick-130279 && git push origin FETCH_HEAD:cherrypick/26.3/130279
  • 3197969c298e is a fast-forward from the cherry-pick head 9e17b5d05ef4. Compared with backport/26.3/130279 it changes only this PR's 4 files, and the source lines are the PR's apart from the container types.
  • The test needs three changes on 26.3, all for behaviour that is the same with or without this change: SET allow_experimental_nullable_tuple_type = 1 (the INSERT fails without it); dropping the 5 queries that read a subcolumn through a list (tb.l.b, an.x.v), which return empty arrays on 26.3 even for a field that is in the file; and dropping the 2 queries that read a field of the NULL struct ts into a non-Nullable element of a Nullable(Tuple), which 26.3 rejects with CANNOT_INSERT_NULL_IN_ORDINARY_COLUMN even when every field is requested.
  • On a 26.3 build (Debug, clang-21) the adapted test passes 3/3. The same build without this PR's source change fails it: [] for the list of id 0, then an abort on the map read. The official 26.3.61.6 binary crashes with SIGSEGV there, also with default settings.

@robot-clickhouse-ci-2
robot-clickhouse-ci-2 merged commit eba998b into backport/26.3/130279 Nov 11, 2026
2 checks passed
@robot-clickhouse-ci-2
robot-clickhouse-ci-2 deleted the cherrypick/26.3/130279 branch November 11, 2026 14:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

do not test disable testing on pull request pr-bugfix Pull request with bugfix, not backported by default pr-cherrypick Cherry-pick of merge-commit before backporting. Do not use manually - automated use only!

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants