Repository navigation
feat: Deletion vector reader - #866
Conversation
laskoviymishka
left a comment
There was a problem hiding this comment.
nice work!
this is a solid foundation for DV read support: envelope parsing is correct, puffin ReadAt integration is clean, and the Java golden test data is a great choice for cross-impl validation.
main concerns:
- OOM from sparse keys — the gap-filling loop in DeserializeRoaringPositionBitmap can allocate billions of empty bitmaps with adversarial input (keys [0, 0xFFFFFFFF]). needs a cap or a map-based representation
- Serialize writes empty gap bitmaps — Java only writes non-empty keys, so Go-serialized output won't match. reader-only for now but it's public — either fix or unexport
- ReadDV cardinality trap — always passes dvFile.Count() which is 0 when unset, rejecting valid DVs
- dvMockDataFile/strPtr missing — tests won't compile, looks like a helper file was left out of the PR
- 4 golden files unused — especially all-container-types-position-index.bin which exercises run containers, the main cross-library bug source
left some comments.
Also general observation - we should add for serialize / write puffin x-engine compatibility e2e tests, this probably beyond this PR scope, but need to keep this in mind once we start to enable DV support.
| const ( | ||
| // DVMagicNumber is the magic number for deletion vectors. | ||
| // Spec bytes: D1 D3 39 64 (big-endian) = 0x6439D3D1 (little-endian uint32) | ||
| DVMagicNumber uint32 = 0x6439D3D1 |
There was a problem hiding this comment.
Will defining the constant this way work for big-endian architectures or do we need to add a conditional compilation etc? Can we just use the actual uint32 value to avoid endian differences?
There was a problem hiding this comment.
change it to
DVMagicNumber uint32 = 1681511377
like here ??
| // - Magic (4 bytes, little-endian): must be 0x6439D3D1 | ||
| // - Bitmap (variable): roaring bitmap in Iceberg portable format | ||
| // - CRC-32 (4 bytes, big-endian): checksum over magic + bitmap |
There was a problem hiding this comment.
it's super weird that the spec jumps back and forth between big and little endian representations....
| } | ||
| defer f.Close() | ||
|
|
||
| reader, err := puffin.NewReader(f) |
There was a problem hiding this comment.
does the puffin reader need a defer reader.Close()?
There was a problem hiding this comment.
puffin reader doesn't own the file IO , it gets it from caller so i would like the caller of puffin file be responsible for closing not puffin reader
let me know if you think otherwise
laskoviymishka
left a comment
There was a problem hiding this comment.
no major concerns from my side.
A few minors to keep in mind for future work on DV:
uint64vs signed-with-guards. If we move touint64later, thepos < 0guards andcount < 0checks go away. Probably the cleaner shape long-term.- X-engine compat e2e tests for serialize/write once DV write support lands. Currently reader-only, so low risk today, but we'll want Spark/Java-produced DVs decoded + Go-produced DVs read back by Spark before enabling write. This is a way bigger item, so need to do a separate research
maxBitmapCountis currently a package constant. If we ever hit a real table that legitimately needs more, it becomes a config knob conversation, worth a brief note in the code on where the number came from.
2abd5bb to
2d06d13
Compare
- add writer-byte-identity check: regenerate the envelope in-memory and
assert byte-equality against the on-disk fixture. without this the test
was reader-only round-trip and writer drift would silently calcify into
the next regen. this is the load-bearing wire-format pin.
- regen path self-validates via puffin.NewReader before overwriting, so a
writer change that produces an unreadable file fails on regen rather
than at the next CI run.
- tighten Fields assertion: assert.Equal []int32{} (not assert.Empty);
Java's parser rejects 'fields': null, so a future writer regression
emitting null instead of [] must fail.
- drop inner DV magic check: belongs to the deletion-vector codec
(apache#866), not to the puffin envelope test. avoids two tests asserting
the same constant in different packages.
- rename TestReadDeletionVectorPuffin -> TestDeletionVectorPuffinWireFormat;
signal intent in test-list output.
- soften godoc + README: 'Java-equivalent wire format' rather than
'Java-produced'. property values (referenced-data-file, cardinality,
created-by) are fixture choices not Java bytes; only the inner roaring
payload and the envelope structure are Java-canonical.
- README adds fixture details (50 bytes, positions 1/3/5/7/9, cardinality 5)
and a diff-before-commit reminder for the regen recipe.
Pins the puffin envelope shape around a deletion-vector-v1 blob without depending on the in-flight roaring decoder (apache#866). The fixture is two files: - puffin/testdata/deletion-vector-v1-payload.bin — a Java-produced 64-bit roaring DV payload lifted directly from apache/iceberg test resources (small-alternating-values-position-index.bin, 50 bytes; bitmap encodes positions 1, 3, 5, 7, 9). - puffin/testdata/deletion-vector-v1.puffin — the same payload wrapped by puffin.Writer with the spec-canonical metadata (snapshot-id=-1, sequence-number=-1, deletion-vector-v1 blob type, referenced-data-file and cardinality properties). The test asserts both layers. Reader side: blob count, type, spec-mandated invariants, properties, and that ReadBlob round-trips the inner payload byte-for-byte equal to the standalone Java fixture. Writer side: regenerates the envelope in-memory and asserts byte equality against the on-disk fixture. Without the writer-side check the test was reader-only round-trip and writer drift would silently calcify into the next regeneration. Honest framing: this is a Go-writer wire-format pin with a Java- equivalent inner payload, not a strong Java cross-impl pin. The basic envelope shape is cross-checked by TestWriterBitIdenticalWithJava, but that test does not exercise empty Fields arrays or multi-key blob Properties — both of which this fixture relies on — and JSON key ordering of blob Properties is encoder-defined. A regen test gated on REGEN_FIXTURES=1 reproduces the .puffin from the inner payload and self-validates by reading the blob back before overwriting the on-disk file. Closes apache#1008.
Signed-off-by: Shreyas220 <[email protected]>
Signed-off-by: Shreyas220 <[email protected]>
Signed-off-by: Shreyas220 <[email protected]>
Signed-off-by: Shreyas220 <[email protected]>
2d06d13 to
036db40
Compare
|
@zeroshade, I rebased onto main, it should be mergeable now. All issues from reviews addressed in the current state: Three threads from your review never got formally closed — would love your read on whether these are good as-is:
Context for the nudge: C2 (#996, scanner integration) and C3 (#997, DV writer) are both blocked on this landing. I plan to focus on this next week, would love to start as soon as possible. Once #866 is in, scanner should be a small wiring PR, and the DV writer becomes a real first-non-Java client item for v3. Can we merge as-is? |
zeroshade
left a comment
There was a problem hiding this comment.
I think this is good to merge as-is and we can see if anything comes up while we continue the work
|
Thanks much! |
Closes apache#996. v3 tables with deletion vectors are now readable end-to-end. Before this change, arrow_scanner.go's GetRecords returned ErrNotImplemen- ted for any task carrying a DV manifest entry, and scan planning paired DVs with their data files but never read the bitmaps. This wires those plans through to the row-filter pipeline. Scanner read path. readAllDeletionVectors mirrors readAllDeleteFiles in shape — concurrent reads via errgroup, returns a perFilePosDeletes map keyed by referenced data file path. A compile-time signature assertion in the test file pins that both loaders share the perFilePosDeletes return type, so the merge in GetRecords (`deletesPerFile[file] = append(...)`) is type-safe by construction. The downstream collapse into a set[int64] inside recordsFromTask / producePosDeletesFromTask absorbs both sources without pipeline changes. Dedup is by referenced-data-file path, not by puffin file path: the spec permits one puffin file to carry multiple DV blobs (one per data file), and keying by the puffin path would silently drop all but the first. The same loop rejects (a) DV entries missing referenced_data_file or content_offset / content_size_in_bytes, (b) two distinct DV blobs (different puffin path OR content offset) targeting the same data file — the latter mirrors Java's DeleteFileIndex "Can't index multiple DVs for %s" ValidationException, since silently unioning two bitmaps is an over-deletion bug. Same-blob dedup across multiple tasks is a no-op (deliberate divergence from Java's stricter rejection — re-reading the same blob is wasteful, not incorrect). Validation runs entirely up front before any goroutine launches. An earlier draft mixed validation into the goroutine-dispatch loop, which created a close-on-closed-channel panic when a bad entry was reached after one or more g.Go calls had dispatched workers still trying to send to the result channel. The current shape — populate uniqueDVs in a serial pre-pass, then fan out — makes that state unreachable by construction. On goroutine error, accumulated *arrow.Chunked values are released before returning, since arrow.NewChunked allocations are not freed by GC alone. bitmapToInt64Chunked materializes a bitmap as a chunked Int64 array via the new dv.RoaringPositionBitmap.Iter() iter.Seq[uint64] method. Lazy iteration avoids the intermediate []uint64 allocation that would double memory pressure for large DVs. The Reserve hint is clamped to math.Max- Int so a 32-bit int build (or a future raised puffin blob-size limit) can't wrap the Cardinality int64 cast to a negative reservation. The int64(p) position cast trusts dv.DeserializeDV as the bytes-to-bitmap boundary — positions ≥ 2^63 would wrap, but the spec bounds positions by the data file's row count, well under that limit. scanner.go: a data file with an applicable DV no longer also has its Parquet position-delete files matched. Spec §Scan Planning predicate "There is no deletion vector that must be applied to the data file" is a precondition for pos-delete application, and Java's DeleteFileIndex. forDataFile enforces it. The gap was latent before this PR because GetRecords errored on DVs; making DVs readable also makes pairing DV+pos-deletes for the same file observable. For spec-compliant tables the set-union absorbs the overlap, but a writer whose DV omits prior pos-delete positions would silently over-delete. dv package: RoaringPositionBitmap gains Iter() (primary, lazy) and ToArray() (convenience wrapper via slices.AppendSeq). The Iter contract is single-goroutine / no-mutation-mid-iteration — the closure captures the bitmap by pointer and roaring.Bitmap doesn't support concurrent Set/Iterator. Tests build a real puffin file via puffin.Writer rather than vendoring fixture bytes, so this PR is independent of apache#1041's golden fixture. Coverage: position decoding and dedup keying by referenced data file, identical-DV dedup across multiple tasks, no-tasks no-op, the four rejection paths (missing referenced_data_file, missing content_offset, multiple distinct DVs for same data file, nil-ref-before-goroutine- dispatch panic regression), and the compile-time signature assertion. TODO(apache#1041) marks the hand-built DV envelope in writeDVPuffinFixture for replacement once that PR exports dv.SerializeDV. End-to-end coverage (DV positions actually filtered out of GetRecords output for a real Parquet data file) is deferred — would need v3 table- metadata scaffolding outside this PR's scope. Several adjacent gaps are also deferred as follow-ups: DV sequence-number guard in PlanFiles (pre-existing from apache#855), tighter ReadDV cardinality validation (pre- existing from apache#866), Puffin reader DV snapshot-id/sequence-number guard (pre-existing from apache#676), and the parallel arrow-leak in readAllDelete- Files (pre-existing).
Pins the puffin envelope shape around a deletion-vector-v1 blob without depending on the in-flight roaring decoder (#866). The fixture is two files: - puffin/testdata/deletion-vector-v1-payload.bin — a Java-produced 64-bit roaring DV payload lifted directly from apache/iceberg test resources (small-alternating-values-position-index.bin, 50 bytes; bitmap encodes positions 1, 3, 5, 7, 9). - puffin/testdata/deletion-vector-v1.puffin — the same payload wrapped by puffin.Writer with the spec-canonical metadata (snapshot-id=-1, sequence-number=-1, deletion-vector-v1 blob type, referenced-data-file and cardinality properties). The test asserts both layers. Reader side: blob count, type, spec-mandated invariants, properties, and that ReadBlob round-trips the inner payload byte-for-byte equal to the standalone Java fixture. Writer side: regenerates the envelope in-memory and asserts byte equality against the on-disk fixture. Without the writer-side check the test was reader-only round-trip and writer drift would silently calcify into the next regeneration. Honest framing: this is a Go-writer wire-format pin with a Java- equivalent inner payload, not a strong Java cross-impl pin. The basic envelope shape is cross-checked by TestWriterBitIdenticalWithJava, but that test does not exercise empty Fields arrays or multi-key blob Properties — both of which this fixture relies on — and JSON key ordering of blob Properties is encoder-defined. A regen test gated on REGEN_FIXTURES=1 reproduces the .puffin from the inner payload and self-validates by reading the blob back before overwriting the on-disk file. Closes #1008.
No description provided.