Repository navigation
Declare raw-byte leaves of Arrow IPC columns with their decoded type - #132416
Conversation
A dotted header column such as `t.s IPv6` makes the native Arrow IPC reader decode the binary child `s` of the struct `t` as `IPv6`. When the parent `t` is requested too, with a type that does not describe `s` (for example `String`), the decoded `t` still declared the child as `String`, because its declared type comes from the Arrow schema. The raw-byte rewrite after decoding follows the parent target type only, so it did not reconcile the child, and the cast of `t` read the `IPv6` column as a `ColumnString`. `matchColumnNullability` already walks the declared type alongside the decoded column. Extend it to leaves: a `String` or `FixedString` leaf that was decoded as `IPv6` or a big integer is declared with that type. Co-Authored-By: Claude Opus 5.5 <[email protected]>
|
Workflow [PR], commit [6cc3253] Summary: ✅
AI ReviewSummaryThe PR keeps decoded Final VerdictStatus: ✅ Approve |
Build profile diff (arm_release)Comparing ✅ No significant changes. Binary sizes
The official master build is compiled with Object file sizes4 object files changed (+65.98 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 Compile time of recompiled translation units8 translation units recompiled, 25 s compile time in total, 8 of them have a recent master baseline. |
…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]>
|
|
…d type The values of an Arrow dictionary are decoded once for each use: the position of a field encoding it, and the requested type hint the field resolves there. The uses were deduplicated and the decodings registered by position alone, but two fields at one position can resolve different hints: a field literally named `t.u` takes the type requested for `t.u`, while the child `u` of a struct `t` takes the type of `u` in a requested `t Tuple(...)`. When such fields shared a dictionary id, both read the decoding of whichever came first in the schema. For example, with ``t Tuple(u UUID), `t.u` String`` the field named `t.u` returned the 36-byte text of a `UUID` instead of its 16 bytes, and requesting it as `IPv6` threw. Key the uses and the registry by the position together with the hint, and look the decoding up with the use that `decodeField` and `decodeBatchColumn` resolve for the field. A use missing from the registry is now a `LOGICAL_ERROR` instead of a `std::out_of_range`. Review: #132416 (comment) Co-authored-by: Yakov Olkhovskiy <[email protected]>
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]>
…bcolumn-hint-with-parent Resolve conflicts with #132416, which keys the decodings of a shared dictionary by position and requested type (`DictionaryUse::operator==`, `DictionaryRegistry::useKey`), skips requested types below an Arrow union, and re-declares raw-byte leaves in `matchColumnNullability` (`rawByteLeafType`). - `DictionaryUse` keeps both `keep_raw_bytes` and `operator==`; `keep_raw_bytes` is derived from the position and the requested types, so it takes part in the equality but not in `useKey`. - `collectDictionaryUses` takes `below_union` and `RequestedTypes`; below a union no requested types are consulted for `keep_raw_bytes` either, and neither for `rawByteTarget` and `wrapsInNullable` while decoding below a union. - `matchColumnNullability` uses master's `rawByteLeafType` with its `LOGICAL_ERROR` check, and keeps this PR's re-declaration of converted dictionary (`LowCardinality`) leaves. - `positionKey` is dropped in favor of master's `useKey`. Co-Authored-By: Claude Opus 5.5 <[email protected]>
…several requests `05816_arrow_ipc_dotted_raw_byte_hint_parent_type` and `05828_arrow_ipc_dictionary_raw_byte_hint_parent_type` came from #132416 and pinned that a parent requested as `String` together with a dotted subcolumn such as `t.s IPv6` reads the child as converted for the subcolumn. This PR intentionally keeps the bytes of a field that is decoded for several requested columns and converts each column by its own type after decoding, so the parent `t String` now reads the raw bytes of `s` / `u`, exactly as when `t` is requested alone. The subcolumns are unchanged. Update the references and the test comments. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Resolve the conflicts of the cherry-pick of #132416 to 26.9. The fix applies in full; the differences from the original diff come only from master-only neighbours that 26.9 does not have: - `ArrowIPCBlockInputFormat.cpp`: 26.9 still checks that dictionary values are unique after registering them (master dropped the check in #125677). Keep the check and look the values up by the dictionary use, as the registry is now keyed by it. - `RecordBatchDecoder.cpp`: 26.9 has no `TypeKind::RunEndEncoded` case in `collectDictionaryUses` (run-end encoding, #126207, is master-only), so there is no call to pass `below_union` to there. The struct case keeps the 26.9 helpers `tupleElementHint` / `childPath` (master renamed them in #125674) and passes `below_union` as the original change does. - `RecordBatchDecoder.cpp`: include `base/scope_guard.h` for the two new `SCOPE_EXIT` uses. On master the include came with the big-endian reader (#126562); 26.9 does not include it, directly or transitively. - `RecordBatchDecoder.h`: no `[[nodiscard]]` on the changed declarations, as on the rest of the 26.9 file (master added them in #126158). Co-authored-by: yakov <[email protected]>
Resolve the conflicts of the cherry-pick of #132416 to 26.10. The fix applies in full; the differences from the original diff come only from master-only neighbours that 26.10 does not have: - `RecordBatchDecoder.cpp`: 26.10 has no `TypeKind::RunEndEncoded` case in `collectDictionaryUses` (run-end encoding, #126207, is master-only), so there is no call to pass `below_union` to there. The struct case keeps the 26.10 helpers `tupleElementHint` / `childPath` (master renamed them in #125674) and passes `below_union` as the original change does. - `RecordBatchDecoder.cpp`: include `base/scope_guard.h` for the two new `SCOPE_EXIT` uses. On master the include came with the big-endian reader (#126562); 26.10 does not include it, directly or transitively. - `RecordBatchDecoder.h`: no `[[nodiscard]]` on the changed declarations, as on the rest of the 26.10 file (master added them in #126158). Co-authored-by: yakov <[email protected]>
Cherry pick #132416 to 26.9: Declare raw-byte leaves of Arrow IPC columns with their decoded type
…s with their decoded type
Cherry pick #132416 to 26.10: Declare raw-byte leaves of Arrow IPC columns with their decoded type
…ns with their decoded type
Backport only the part of #132416 that applies to 26.8: requested types are no longer looked up below an Arrow union. 26.8 has the same lookup: the children of a union restart the dotted path, so a struct field `s` inside a union child resolves the requested type of an unrelated header column `s`. On 26.8 a `Nullable` requested type keeps the null map of a struct, while `decodeUnion` declares its children from the schema, so the cast of the union read a `ColumnNullable` as a `ColumnTuple`: a `Bad cast` logical error in debug builds, and garbage values in release builds, also on `INSERT ... FORMAT ArrowStream`. The fix sets `decoding_below_union` in `decodeUnion` and skips the lookup in `resolveTargetHint` while it is set, as on master. It also includes `base/scope_guard.h` for `SCOPE_EXIT`, which 26.8 does not include. The rest of #132416 does not apply to 26.8: it changes the decode-time raw-byte conversion and the decoding of dictionary values once per field position and requested type, which came with #110531 and are not on 26.8 (26.8 decodes each dictionary once, without requested types). Its tests are adapted: - `05829_arrow_ipc_union_unrelated_hint` gets a case with a `Nullable` unrelated column, the shape that reaches 26.8. Its other cases pass on 26.8 with or without the fix. - `05830_arrow_ipc_union_dictionary_unrelated_hint` is kept; it passes on 26.8. - `05816`, `05828` and `05831` are dropped: they cover the parts that are not on 26.8, and they fail on 26.8 with or without the fix, because 26.8 does not read those raw-byte subcolumns and converts a dictionary-encoded `fixed_size_binary(16)` to `UUID` with a cast. Co-authored-by: yakov <[email protected]>
Cherry pick #132416 to 26.8: Declare raw-byte leaves of Arrow IPC columns with their decoded type
…s with their decoded type
Backport #132416 to 26.10: Declare raw-byte leaves of Arrow IPC columns with their decoded type
Backport #132416 to 26.9: Declare raw-byte leaves of Arrow IPC columns with their decoded type
Backport #132416 to 26.8: Declare raw-byte leaves of Arrow IPC columns with their decoded type
The native Arrow IPC reader (
Arrow,ArrowStream) can decode a binary child of a struct asIPv6or a big integer when a dotted header column requests it, for example"t.s" IPv6. The parenttcan be requested too, with a type that does not describes, for exampleString. In that case the decodedtstill declared the child asString, because the declared type comes from the Arrow schema. The raw-byte rewrite after decoding follows only the target type of the parent, so it did not fix this child. The cast oftthen read theIPv6column as aColumnString, and the server crashed. The same happens for a struct inside a list (a String, "a.s" Array(IPv6)). It also happens for a dictionary-encodedfixed_size_binary(16)child requested asUUID(t String, "t.u" UUID), whose dictionary values are converted before any record batch is decoded.The fix extends
matchColumnNullability, which already compares the declared type with the decoded column at each level, to leaf columns. AStringorFixedStringleaf that was decoded asIPv6,UUID,Int128,UInt128,Int256orUInt256is now declared with that type. So every column of the chunk that uses the decoded field sees a type that matches its column. AStringorFixedStringleaf that holds a column of any other type throws aLOGICAL_ERROR, so a conversion this walk does not know about becomes an exception instead of undefined behavior.An Arrow union crashed the same way without any dotted name. The children of a union restart the dotted path, so the struct child
sof a union child has the paths, and the lookup of requested types found an unrelated header columns, for exampleu String, s IPv6. Its type changed how the child decoded: raw bytes were read asIPv6, or the null map of a struct was kept for aTuple. MeanwhiledecodeUniondeclares its children from the Arrow schema. Requested types are no longer looked up below a union, neither while decoding its children nor for the dictionaries of fields below it. The dictionary positions of such fields are kept apart from equally named positions outside the union.The values of a dictionary are decoded before any record batch, once for each field that encodes the dictionary, as that field would decode them inline. Fields sharing a dictionary id were told apart only by their position, meaning the dotted name and the list depth. But two fields at one position can resolve different requested types: a field literally named
t.utakes the type requested fort.u, while the childuof a structttakes the type ofuin a requestedt Tuple(...). Both read the decoding of whichever came first in the schema. For example, witht Tuple(u UUID), `t.u` String, the field namedt.ureturned the text of aUUIDinstead of its 16 bytes. Each decoding is now identified by the position together with the requested type.Tests:
05816_arrow_ipc_dotted_raw_byte_hint_parent_type,05828_arrow_ipc_dictionary_raw_byte_hint_parent_type,05829_arrow_ipc_union_unrelated_hint,05830_arrow_ipc_union_dictionary_unrelated_hint, and05831_arrow_ipc_shared_dictionary_dotted_name. The last two need pyarrow, henceno-fasttest.Related: #132550
Related: #120702
Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
Fix a crash in the
ArrowandArrowStreaminput formats when a requested type changed how a nested field was decoded while another requested column read that field with a type that does not describe it: a struct column together with a dotted subcolumn of it, such ast String, "t.s" IPv6(including dictionary-encodedUUIDchildren), or an Arrow union with a struct child named like another requested column.Workflow [PR]
Sync PR [sync-upstream/pr/132416]
Version info
26.11.1.2801-master(included in26.11and later)26.10.8.33,26.9.34.15,26.8.42.13