Skip to content

Fix UUID dictionary leaves and union children that the Arrow IPC reader declared with the wrong type - #132550

Merged
cursor[bot] merged 2 commits into
arrow-ipc-nested-hint-type-consistencyfrom
cursor/arrow-ipc-union-uuid-hint-fixes-74ac
Nov 18, 2026
Merged

cursor[bot] merged 2 commits into
arrow-ipc-nested-hint-type-consistencyfrom
cursor/arrow-ipc-union-uuid-hint-fixes-74ac

Conversation

@yakov-olkhovskiy

Copy link
Copy Markdown
Member

Two fixes on top of #132416, for findings from its review. In both, the type declared for a decoded Arrow IPC column did not describe the column, so the cast of the column read it through the serialization of another type: a failed assert_cast in debug builds, a segmentation fault or garbage output in release builds. Each fix is a separate commit, so either can be taken into the branch of #132416 on its own.

  • UUID dictionary leaves (Declare raw-byte leaves of Arrow IPC columns with their decoded type #132416 (comment)). A dictionary-encoded fixed_size_binary(16) child is converted to UUID when a dotted header column such as t.u UUID requests it, but rawByteLeafType did not list UUID, so reading t String, `t.u` UUID still declared the child as FixedString(16). It is listed now, and a String or FixedString leaf that holds a column of any other type throws a LOGICAL_ERROR instead of reaching the cast.
  • Union children (Declare raw-byte leaves of Arrow IPC columns with their decoded type #132416 (comment)). The children of a union restart the dotted path, so the struct child s of a union child picked up the requested type of an unrelated header column s, while decodeUnion declares its children from the Arrow schema. Besides the raw-byte case from the comment, the same leak kept the null map of a nested struct when s was requested as a Tuple under enable_nullable_tuple_type = 0, so reconciling the Variant alternatives would not have been enough. Requested types are no longer looked up below a union: neither while decoding its children, nor for the dictionaries of fields below it. Dictionary positions below a union are kept apart from equally named positions outside it, so a dictionary shared with a field outside the union cannot hand the union that field's decoding.

Tests: 05828_arrow_ipc_dictionary_raw_byte_hint_parent_type, 05829_arrow_ipc_union_unrelated_hint, and 05830_arrow_ipc_union_dictionary_unrelated_hint. The last one needs pyarrow (hence no-fasttest), because the ClickHouse writer does not dictionary-encode inside a union. Every UUID and union case in them aborts the debug build of #132416 at dbc60529 and passes with these commits. The first commit alone fixes 05828 and leaves the union cases failing.

Verified on a local Debug build in the fast-test configuration:

  • all 72 fast-test Arrow tests pass;
  • the remaining Arrow tests pass, except ones that need features this reduced build lacks (Avro, SQLite, Iceberg, Arrow Flight, SSL, base64Decode, brotli);
  • all 321 Arrow/ArrowStream rows of 05361_arrow_testing_corpus match the reference.

This PR targets the branch of #132416, so CI does not run on it.

Related: #132416

Changelog category (leave one):

  • Not for changelog (changelog entry is not required)
Open in Web Open in Cursor 

cursoragent and others added 2 commits November 18, 2026 00:55
…ded type

A dictionary-encoded `fixed_size_binary(16)` child is converted to `UUID` when a dotted header
column such as `t.u UUID` requests it: `decodeDictionaryBatch` rewrites the dictionary values with
`reinterpretRawByteColumns`. `rawByteLeafType` listed only the types that `reinterpretStringLeaf`
produces, so `matchColumnNullability` kept declaring the leaf as `FixedString(16)`. When the parent
`t` was requested too, with a type that does not describe `u` (for example `String`), the cast of `t`
read the `UUID` column as a `FixedString` one: a failed `assert_cast` in debug builds, undefined
behavior in release builds.

Declare such a leaf as `UUID`, and throw a `LOGICAL_ERROR` for a `String` or `FixedString` leaf that
holds a column of any other type, so a conversion this walk does not know becomes an exception
instead of undefined behavior.

Review: #132416 (comment)
Related: #132416
Co-authored-by: Yakov Olkhovskiy <[email protected]>
The children of an Arrow union restart the dotted path, so the struct child `s` of a union child
has the path `s`, and the lookup in the requested types found the unrelated header column `s`. Its
type changed how the child decodes (raw bytes read as `IPv6`, or the null map of a struct kept for a
`Tuple`), while `decodeUnion` declares its children from the Arrow schema, so the cast of the union
read the column as another type: a failed `assert_cast` in debug builds, a segmentation fault in
release builds. A dictionary of a field below a union got the same hint, from
`collectDictionaryUses` and again in `decodeDictionaryValues`.

Look up no requested type while decoding the children of a union, and the values of a dictionary
used below one. Keep these dictionary positions apart from equally named positions outside the
union (`FieldPosition::below_union`), so a dictionary that a field outside the union shares does not
hand the union the decoding requested for that field.

Review: #132416 (comment)
Related: #132416
Co-authored-by: Yakov Olkhovskiy <[email protected]>
@cla-assistant

cla-assistant Bot commented Nov 18, 2026

Copy link
Copy Markdown

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you sign our Contributor License Agreement before we can accept your contribution.
You have signed the CLA already but the status is still pending? Let us recheck it.

@clickhouse-gh clickhouse-gh Bot added the comp-formats Input/output formats (CSV/JSON/Parquet/ORC/Arrow/Protobuf/etc.). label Nov 18, 2026
@cursor
cursor Bot merged commit b5ef697 into arrow-ipc-nested-hint-type-consistency Nov 18, 2026
3 of 4 checks passed
@cursor
cursor Bot deleted the cursor/arrow-ipc-union-uuid-hint-fixes-74ac branch November 18, 2026 04:48
groeneai added a commit to groeneai/ClickHouse that referenced this pull request Nov 19, 2026
The branch is in conflict with master. Conflicts in the ArrowIPC reader only: master (ClickHouse#132416) keys the
dictionary uses and the registry by position and requested hint (`DictionaryUse::operator==`,
`DictionaryRegistry::useKey`, `dictionaryUse`), as this branch did with `DictionaryUse::key`; master's code
is kept and the branch's copy dropped. Master's `below_union` position (ClickHouse#132550) is kept with this
branch's exact-name hint lookup (`resolveHint` with case-insensitive matching), the per-struct
`structFieldHints` and the top-level field name as the starting path.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

comp-formats Input/output formats (CSV/JSON/Parquet/ORC/Arrow/Protobuf/etc.).

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants