Skip to content

feat: puffin Reader and Writer - #676

Merged
zeroshade merged 9 commits into
apache:mainfrom
Shreyas220:feat/puffin
Feb 24, 2026
Merged

zeroshade merged 9 commits into
apache:mainfrom
Shreyas220:feat/puffin

Conversation

@Shreyas220

@Shreyas220 Shreyas220 commented Jan 12, 2026 •

Copy link
Copy Markdown
Contributor

for #589

  • Added PuffinWriter
  • Added PuffinReader
  • uncompressed only

Signed-off-by: Shreyas220 <[email protected]>
Signed-off-by: Shreyas220 <[email protected]>
Signed-off-by: Shreyas220 <[email protected]>
Signed-off-by: Shreyas220 <[email protected]>
@Shreyas220

Shreyas220 commented Jan 12, 2026 •

Copy link
Copy Markdown
Contributor Author

Hey 👋 @zeroshade , @twuebi would appreciate a review
tests coming next

@Shreyas220
Shreyas220 marked this pull request as ready for review January 12, 2026 22:54

@zeroshade zeroshade left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for starting this up! I've been wanting to get a puffin reader/writer in here for a while now. I've gone through with a bunch of questions / requests etc. But this also needs to have some tests and potentially examples if possible!

Thanks again!

Comment thread puffin/puffin.go Resolved
Comment thread puffin/puffin.go Resolved
Comment thread puffin/puffin_writer.go Resolved
Comment thread puffin/puffin_writer.go Resolved
Comment thread puffin/puffin_writer.go Resolved
Comment thread puffin/puffin_reader.go Resolved
Comment thread puffin/puffin_reader.go Resolved
Comment thread puffin/puffin_reader.go Resolved
Comment thread puffin/puffin_reader.go Resolved
Comment thread puffin/puffin_reader.go Resolved
Comment thread puffin/puffin_reader.go Resolved
Comment thread puffin/puffin_reader.go Resolved

@zeroshade zeroshade left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just a few remaining comments and then this looks good to me!

Is there any testing repository of existing, known-valid Puffin files that we could create an integration test with?

@subkanthi

Copy link
Copy Markdown
Contributor

Eagerly waiting for this to add compression support, @Shreyas220 happy to help.

@github-actions github-actions Bot added the INFRA label Feb 18, 2026
@zeroshade

Copy link
Copy Markdown
Member

Thanks for adding the tests @Shreyas220 can we add a comment in the file saying where the testdata files came from?

Also my previous two comments still need a response. Otherwise this looks good!

@Shreyas220

Shreyas220 commented Feb 21, 2026 •

Copy link
Copy Markdown
Contributor Author

@zeroshade resolved the last 2 comments and added a readme in testdata and a comment above the tests in puffin_test.go readFixture test to point to that exact location we got the puffin files from

@zeroshade zeroshade left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good, just one nitpick to address and I'll merge

Comment thread dev/release/rat_exclude_files.txt Resolved
@zeroshade
zeroshade merged commit 19bec10 into apache:main Feb 24, 2026
13 checks passed
rockwotj pushed a commit to rockwotj/iceberg-go that referenced this pull request Mar 18, 2026
for apache#589

  - Added PuffinWriter 
  - Added PuffinReader 
  -  uncompressed only

---------

Signed-off-by: Shreyas220 <[email protected]>
laskoviymishka added a commit to laskoviymishka/iceberg-go that referenced this pull request May 10, 2026
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).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants