fix(core): read the delete record's wrapped ordering value - #663
Open
linliu-code wants to merge 2 commits into
Open
fix(core): read the delete record's wrapped ordering value#663linliu-code wants to merge 2 commits into
linliu-code wants to merge 2 commits into
Conversation
Squashed view of apache#639-apache#662 for review. Not for merge — the reviewable increments are those PRs; this is the same code in one diff. Ports the merge-on-read file group reader from onehouseinc/hudi-rs-internal into hudi-core, wires it behind a switch that defaults to the reader that has always served reads, and brings its end-to-end test harness across. The ported reader is `pub(crate)` and reached only through `hoodie.read.merge.engine = v2`. Nothing changes for anyone who does not set it. It is not at parity yet: the gaps are pinned as ignored cases carrying their findings, and the outstanding decisions are in the PR descriptions. Four fixes land on paths the existing reader shares: decimals had no Arrow conversion, Avro timestamp logical types lost their UTC zone, the properties-escaped create schema was not being unescaped by one of its two consumers, and the base file reader had no way to accept a pushdown predicate. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
A delete block whose ordering value is anything but a small integer fails to
read, with errors like `Union index 1490 out of bounds: 2`. The index is
nonsense because the byte stream is misaligned, not because a branch was chosen
wrongly.
`orderingVal` is declared here as a union of primitives. Hudi writes a union of
per-type wrapper records, and inserted `BooleanWrapper` at position 1, so every
position from `int` onward names a different type than this crate assumes.
Position 3 is `float` here and `LongWrapper` there. Reading a long as a float
consumes four bytes instead of two, and the next record's key length is read
from the middle of the previous value.
The delete block in `table_delete_ord_long` is exactly self-consistent under
Hudi's schema and not under this one:
04 | 02 02 34 | 02 00 | 06 c0 3e | 02 02 33 | 02 00 | 06 f0 2e | 00
two records, keys "4" and "3", ordering position 3, values 4000 and 3000
Decoded here, position 3 is a float, so `c0 3e 02 02` is eaten and `33` becomes
the next key's union index: zigzag 0x33 is -26, which is the reported error.
So this takes Hudi's schema. Two things follow from it:
The Arrow side wants a scalar, not a record with one field, so the wrapper is
unwrapped after the schema is narrowed — narrowing reads the position Hudi
wrote, and unwrapping rewrites it, so the order matters.
The wrapper is chosen for the value rather than for the column, so a table
whose ordering column is a long can still carry an `IntWrapper` for a small
value. The delete batch's ordering column is now cast to the type the data
schema declares. The old schema hid this by calling position 2 a long
regardless, which happened to match the two fixtures that exercise it.
`ArrayWrapper` orders by a list and is rejected in both places that read the
position, rather than mapped to something that would disagree with its value.
Older tables written with the primitive union are not supported. No fixture
here uses one, and the two shapes cannot be told apart from the bytes: where
they differ, decoding usually fails, and at position 2 both succeed and yield
the same number.
Un-ignores the eleven cases that pinned this.
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Stacked on #639–#662 — review only the last commit.
The bug
A delete block whose ordering value is anything but a small integer fails to read:
"out of bounds: 2" is the tell — the only 2-branch unions are
recordKeyandpartitionPath. So the decoder is reading a record key's union index and getting 1490. The byte stream is misaligned; the branch wasn't chosen wrongly.This is a pre-existing hudi-rs defect, not a port regression. It fails on the current reader too, through
Table::read.Cause
orderingValis declared here as a union of primitives. Hudi writes a union of per-type wrapper records, and insertedBooleanWrapperat position 1 — so every position fromintonward names a different type:Evidence
The delete block in
table_delete_ord_long, 26 bytes, is exactly self-consistent under Hudi's schema:04→ 2 records"4"and"3", empty partitions, ordering position 3, varints 4000 and 3000Decoded here, position 3 is a
float— 4 fixed bytes — soc0 3e 02 02is swallowed and33is read as the next record's key union index: zigzag(0x33) = −26, the reported error, byte for byte.What changed
[null, i]" logic still yields a primitive Arrow column and the output type is unchanged.Union(i, Record[("value", v)])→Union(1, v), applied after narrowing, since narrowing reads the position Hudi wrote and unwrapping rewrites it.IntWrapperfor a small value. The delete batch's ordering column is cast to the type the data schema declares. The old schema hid this by calling position 2 a long regardless.ArrayWrapperis rejected in both places that read the position, rather than mapped to something that disagrees with its value.A correction to an earlier claim
I previously reported that both shapes exist in the wild and could not be distinguished, after an attempt to swap the schema broke
v6_trips_8i3dandv8_trips_8i3u1d. That was wrong. Both use position 2, which islonghere andIntWrapper{int}there — and a wrapper's field is a bare primitive, so both decode the same bytes to the same number. Those fixtures never distinguished the schemas. They broke on the Arrow type of the result, which is what item 4 addresses.All 16 fixtures with delete blocks are consistent with the wrapper schema; none requires the primitive form.
Older tables
Not supported, deliberately. No fixture uses the primitive layout, and the two cannot be told apart from the bytes: where they differ, decoding usually fails (this bug), and at position 2 both succeed with the same value. If you know of tables written with the older layout, please say so — the alternative is a decode-and-retry fallback, which I did not take.
Tests
11 previously-ignored cases un-ignored and passing: ordering by long, decimal, timestamp, plus multi-log, watermark and instant-range cases that were blocked behind the same decode.
The schema's own unit tests asserted the old index space; they now assert the wire order, which is what a delete block's index actually refers to. Two new tests cover unwrapping and the
ArrayWrapperrejection.Full workspace green: 1177 lib + 79 table-read + 39 datafusion + 21 + 12. Ignored drops 19 → 8.
🤖 Generated with Claude Code