Repository navigation
Cherry pick #132416 to 26.8: Declare raw-byte leaves of Arrow IPC columns with their decoded type - #132839
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]>
…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]>
…-consistency Declare raw-byte leaves of Arrow IPC columns 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]>
|
Resolved as a partial backport: only the part of #132416 that applies to 26.8. 26.8 has the same lookup of requested types below an Arrow union. A struct field Not included, because the code isn't on 26.8 (it came with #110531): the decoded-type declaration of raw-byte leaves, and dictionary decoding per field position and requested type. 26.8 decodes each dictionary once without requested types and doesn't convert raw bytes while decoding, so those crashes can't happen there. Tests: |
decd564
into
backport/26.8/132416
Original pull-request #132416
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-picklocally.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:
pr-cherrypicklabel from the PRYou also need to check the Original pull-request for
pr-backports-createdlabel, and delete if it's presented thereThe PR source
The PR is created in the CI job