Skip to content

feat: support bloom filters in native Iceberg writes - #5724

Open
NikitaMatskevich wants to merge 55 commits into
apache:mainfrom
NikitaMatskevich:feat/iceberg-bloom-filter-writes
Open

NikitaMatskevich wants to merge 55 commits into
apache:mainfrom
NikitaMatskevich:feat/iceberg-bloom-filter-writes

Conversation

@NikitaMatskevich

@NikitaMatskevich NikitaMatskevich commented Sep 5, 2026 •

Copy link
Copy Markdown

Which issue does this PR close?

Partially addresses #5643 and #5649. Does not close the generic Parquet writer issue #5304.

Rationale for this change

Enable native Iceberg writes for tables with column Bloom filters on identifiable Iceberg 1.5+ runtimes, with safeguards matching each runtime's property and column-path behavior. The legacy-runtime work from #7226 is now included here so both parts land together. A plain enabled=false property keeps otherwise eligible writes native, with or without the Bloom opt-in.

The default-off spark.comet.write.iceberg.bloomFilterFolding.enabled option accepts parquet-rs's folding behavior. Sparse filters can shrink toward the requested FPP, trading serialized space for potentially weaker pruning than Java's larger filters. The flag selects the writer; it cannot disable folding in the pinned parquet-rs implementation.

We are also pursuing an upstream parquet-rs option to disable folding, which would simplify compatibility with Java by retaining the initial filter size. The current Comet opt-in accepts folding; it does not disable it.

What changes are included in this PR?

  • Translate effective per-column enablement, FPP, and optional NDV through grouped protobuf settings, with Java-compatible initial allocation and conservative numeric/cap guards.
  • Resolve raw physical paths on Iceberg 1.5–1.7, field IDs and aliases on 1.8/1.9, and canonical names on 1.10+. Preserve Java validation with fallback for ambiguous aliases, unsupported settings, and unknown runtimes. Iceberg 1.6/1.7 explicit FPP settings use Java to preserve their independent validation pass.
  • Keep FLOAT/DOUBLE Bloom writes on Java to preserve NaN equality. Disabled Bloom settings retain native eligibility when their remaining properties are supported.
  • Charge each open file for its full Bloom targets so reservations and fanout spill selection include Bloom allocations; release the allowance on close or drop.
  • Document the opt-in, pruning and boolean differences, eligibility conditions, and pinned-profile compatibility matrix under Accepted divergences.
  • Extend the existing Iceberg write benchmark with native Bloom off/on cases and document independent JVM timing/RSS collection using standard tooling.

Benchmark results

Following Andy Grove’s suggestion, the existing CometIcebergWriteBenchmark compares native writes with Bloom filters off versus on at the default 1 MiB cap per column. Bloom filters are enabled on the bigint, string, and binary columns.

Measured on 2026-10-25 with a release native build; Spark 4.1 / Iceberg 1.11; JDK 21.0.6; Apple M4 Max, 64 GiB RAM; local[5], 8 GiB JVM heap. Each case writes 4,194,304 rows, with five measured iterations in a separate JVM.

Native writer Average write time Standard deviation Whole-process peak RSS
Bloom filters off 647 ms 20 ms 3,056 MiB
Bloom filters on 686 ms 21 ms 2,930 MiB

Bloom filters added approximately 6% to average write time in this local run. Peak RSS includes Maven/JVM startup, source generation, validation, and warmup; the lower observed RSS with filters enabled does not establish a memory saving. These measurements compare the native writer with filters off/on; they do not measure Java/native writer speed or reader pruning.

@andygrove andygrove added enhancement New feature or request area:Iceberg area:writer Native Parquet writer labels Sep 6, 2026
@NikitaMatskevich
NikitaMatskevich force-pushed the feat/iceberg-bloom-filter-writes branch 15 times, most recently from a9254ed to cd3042f Compare September 7, 2026 09:54
@NikitaMatskevich
NikitaMatskevich marked this pull request as ready for review September 7, 2026 09:55

@alessandro-nori alessandro-nori left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

found one divergence from iceberg Java, the rest of the implementation looks good to me

@NikitaMatskevich
NikitaMatskevich force-pushed the feat/iceberg-bloom-filter-writes branch from cd3042f to f86e8e4 Compare September 7, 2026 14:19
@NikitaMatskevich
NikitaMatskevich force-pushed the feat/iceberg-bloom-filter-writes branch from f86e8e4 to 1d8376b Compare September 7, 2026 15:30

@unikdahal unikdahal left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Thanks for the detailed work here. The nested list/map physical-path fix looks good.

I found three remaining parquet-mr compatibility gaps in Bloom-filter property handling/sizing. Details inline.

@NikitaMatskevich
NikitaMatskevich force-pushed the feat/iceberg-bloom-filter-writes branch from 1d8376b to 7d218de Compare September 7, 2026 19:42

@unikdahal unikdahal left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Thanks for addressing the earlier comments. I re-checked the latest changes, and those issues look resolved.

I found one remaining cross-version test issue and left an inline comment on it. Other than that, the implementation LGTM.

Also, could you please rebase against main to resolve the merge conflicts?

@sunchao sunchao 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.

Correctness

Reviewed 7d218de7 against authoritative base 7f1e0018, with authored changes measured from merge base 719cba11. Previously, an enabled Bloom-filter property forced Iceberg writes onto the JVM path. The PR lifts that restriction, maps configured columns to Parquet paths, carries FPP/NDV/max-byte settings through protobuf, and configures the native writer. Its eligibility checks keep unsupported runtime properties, unrepresentable caps and problematic numeric values on the classic writer.

The previous discussions about enabled=false plus NDV, the 32-byte cap and overflowing NDV are addressed in the current control flow. NDV can re-enable a configured column, associated malformed values are checked even when enabled is false, and the two sizing boundaries fall back. The list/map path adjustment also addresses the previously reported missing intermediate path components.

One new [P2] remains: the new map assumes Iceberg Java's physical field names are also the native writer's names. Java sanitizes names such as order id to order_x20id, while the pinned native schema conversion preserves order id. The native Bloom-property lookup therefore misses the configured column. The inline comment requests matching the native writer's schema or falling back for renamed fields.

The maintained Spark 3.5 and 4.0 parsers accept backquoted names containing spaces and punctuation, and their schemas retain the names. This is a valid column shape, not an invalid-name input. Spark's V2 commit/abort protocol is unchanged by this PR. Bloom filters affect pruning rather than row values, so correct row results alone cannot establish that these properties were honored.

The existing cross-version test issue also remains. Both suites' shared assumption checks only the FPP constant. Iceberg 1.8.1 and 1.10.0 expose that constant but lack NDV support, so the assumption passes while production correctly rejects explicit NDV. NDV cases that expect native execution or Compatible need a separate capability assumption. I have not duplicated that inline comment.

Validation

No check runs, statuses or Actions runs were present for this head in the fresh check at 2026-09-08 04:40:59 UTC. No CI checkout, merge-tree equivalence or native artifact provenance could therefore be credited. The author's local-suite statement is not independently verified. The assigned base has advanced beyond this branch's merge base, including overlapping writer/reflection/test changes that must survive the requested rebase.

A bounded component test compiled the exact Java name-sanitizing methods, parquet-rs column-path identity/conversion and Comet path/sizing functions. Plain names matched. Three sanitized names missed the native column keys, and controls using native paths matched. It also passed 115 allocation round trips across supported powers of two and representative FPPs, plus default, underestimated-NDV, binding-cap and pathological-FPP controls. This used a simple property-map fixture and a Java precondition stub. It was not a complete Parquet-file or Spark/JNI reproduction. No local Comet build, Spark suite or performance benchmark was run. Maintained Spark 3.4/4.1 source branches were unavailable.

Performance

The default requests up to 1 MiB per configured column per row group, with larger supported caps up to 128 MiB. Allocation and hashing occur in the native writer, and fanout can multiply concurrent allocations. The sizing translation preserves the intended cap/NDV precedence in the inspected cases. The pinned parquet-rs encoder folds filters on flush, so final file size can differ from initial allocation.

The new path mismatch silently loses requested Bloom pruning for affected names. Apart from that finding, I found no material unnecessary work introduced by the translation. Schema-path reflection is performed during driver serialization, and the inverse sizing usually takes one candidate with a bounded search fallback. File-size assertions and sizing calculations do not establish write-throughput or downstream query gains.

Design

Separating eligibility, protobuf translation and native writer-property construction keeps fallback decisions before task execution. Explicit defaults prevent parquet-rs's different FPP default from leaking into Iceberg writes, and preserving absent NDV is necessary for the JVM sizing precedence. The physical-path mapping is the weak boundary: its source must agree with the schema actually emitted by the native writer.

Abstraction & complexity

The synthetic NDV is justified by the pinned API's lack of a separate byte-cap setter. The inverse calculation verifies its result, and the numeric search is bounded. The JVM representability check duplicates part of that sizing logic, but it serves a distinct purpose by rejecting unsupported settings before execution. Keeping those checks tied to dependency versions and boundary tests is necessary. Beyond correcting the path mapping, I found no actionable abstraction change.

@NikitaMatskevich
NikitaMatskevich force-pushed the feat/iceberg-bloom-filter-writes branch from 9875a7b to fcef2c4 Compare September 8, 2026 09:55
@NikitaMatskevich
NikitaMatskevich force-pushed the feat/iceberg-bloom-filter-writes branch from 0408885 to 0364676 Compare November 25, 2026 16:58

@andygrove andygrove 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.

Disclaimer: this review was produced by an automated AI assistant (Claude Code) on behalf of @andygrove and has not been hand-edited. Please treat it as a review aid and push back where it is wrong.

Thanks for the work here and for combining the legacy-runtime part into this PR. The sizing mirror, the per-runtime path resolution, the float/double fallback and the opt-in all look careful. I compared the gate against branch-1.2 and ran the three Iceberg write suites locally on Spark 3.5 with Iceberg 1.8.1 (276 passed, 0 failed, with the 1.8-specific alias, collision and empty-name tests running) plus the iceberg_write Rust tests. So the 1.8.1 short-name gap from the earlier reviews is fixed.

My earlier block on enabled=false staying native is resolved for identifiable 1.5 to 1.9 runtimes. One residual case remains and is in the inline comment on CometIcebergNativeWrite.scala. That is why I am keeping this as request changes.

Two comments below are not on lines this PR changes, so they are here.

docs/source/contributor-guide/memory_management.md (Iceberg writer bullet, "Native writes decline Bloom filters today, and neither figure would include them")
This is now stale. With this PR each open file reserves its Bloom targets. Could this sentence say that instead, and could the description of what the share counts mention the fixed allowance?

docs/source/user-guide/latest/iceberg.md ("Plans for each fallback", "Planned to be lifted: Bloom filters ... PR #5724")
This entry is stale, and the section says a rule is lifted only once the native writer matches iceberg-java. The opt-in accepts differences, so could the entry go, with the remaining Bloom fallbacks listed where they belong (FLOAT/DOUBLE columns, 1.6/1.7 explicit FPP, unidentified runtimes, non-representable settings)? Could the section also say how the opt-in fits its rule?

spark/.../IcebergReflection.scala (probeExecutorReflection)
The probe resolves only the 2-arg GenericManifestFile constructor. See the inline comment on newDataManifestFile for the members the fallback also needs.

}
}

private val requireSupportedBloomFilterRuntime: TriggerRule = ctx => {

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.

The rules in this block run for any key with a Bloom prefix, including a plain enabled=false that requests no filter. On branch-1.2 that table writes natively. Here it goes to Java in two cases I can see. One is a runtime whose version is not three numeric parts, such as a four-part vendor version like 1.8.1.2, which bloomFilterVersion cannot parse. The other is two disabled spellings that resolve to the same leaf on 1.8/1.9, which hits the collision fallback. The user guide says enabled=false keeps the write native, so should the unidentified-runtime rejection and the collision check apply only when hasEnabledBloomFilters is true? The 1.6/1.7 FPP rule is separate and would stay as it is.

// The copy builder retains the cached length but not the input file.
cls.getMethod("length").invoke(manifest)
val builder = cls
.getMethod("copyOf", loadClass(ClassNames.MANIFEST_FILE))

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.

probeExecutorReflection accepts the 2-arg GenericManifestFile constructor, but this fallback also needs GenericManifestFile.copyOf(ManifestFile), length(), and the builder's withSnapshotId(Long) and build(). Could the probe resolve those in its NoSuchMethodException branch, so a runtime missing one falls back at plan time instead of failing the task? CI covers 1.5.2 and 1.7.2 but not 1.6.x.

| 3.5 | 1.8.1 | Native eligible; field names and aliases; FPP interpreted, NDV ignored |
| 4.0 | 1.10.0 | Native eligible; FPP interpreted, NDV ignored |
| 4.1 | 1.11.0 | Native eligible; FPP and NDV interpreted |
| 4.2 | 1.10.0 | Native eligible; FPP interpreted, NDV ignored |

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.

The Spark 4.2 row says Iceberg 1.10.0 is pinned and Bloom writes are native eligible. iceberg-writes.md says no Iceberg runtime is published for Spark 4.2, the 4.2 profile reuses the 4.0 runtime, and the Iceberg suites skip there. Should this row say Iceberg is not available on 4.2 rather than imply it works?

upload-test-reports: true
skip-native-build: true

legacy-iceberg-writes:

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.

These two rows run on every pull request and merge-queue run, whether or not Iceberg write code changed. In the fork run they took about 8 minutes each. Could they run only when the Iceberg write paths change, through compute-changes.py, or sit behind run-iceberg-tests?

@comphead

comphead commented Dec 4, 2026

Copy link
Copy Markdown
Contributor

I would post review a bit later, but vision the PR should be split across different systems, like arrow-rs, iceberg-rust

@comphead

comphead commented Dec 4, 2026

Copy link
Copy Markdown
Contributor

Following up on my iceberg-rust question, I went through the Bloom pieces of this PR at 036467688b against iceberg-rust (main and the current pin de0a6ac), parquet-rs (59.3.2 and main) and DataFusion main, to see what could live upstream.

DataFusion: nothing. The native Iceberg writer builds parquet-rs WriterProperties and hands them to iceberg-rust's ParquetWriterBuilder. DataFusion's ParquetSink and TableParquetOptions are not in that path.

iceberg-rust

parquet-rs

  • BloomFilterProperties only has fpp and ndv, which is why this PR encodes Java's byte count as a synthetic NDV and checks it on both sides. A byte-size field would retire synthetic_ndv_for_bloom_filter_bytes and bloomFilterSizesRepresentable. I could not find an arrow-rs issue for it.
  • On feat(parquet): allow disabling Bloom filter folding arrow-rs#11892, mbutrovich and adriangb questioned byte parity as a goal, and mbutrovich asked whether a minimum filter size is the better knob. A floor equal to the initial size turns folding off, so pairing it with the byte-size ask may be easier to land than an on/off switch.
  • set_bloom_filter_for_dictionary_encoded_chunks shipped in 60.0.0 ([Parquet] Add writer option to skip bloom filters for column chunks whose data pages are all dictionary encoded arrow-rs#10963) and defaults to true. parquet-java writes no filter when every data page is dictionary encoded (source), so setting it to false once deps: upgrade to DataFusion 56.0.0 #7249 brings parquet 60.1.0 removes the dictionary-only divergence.
  • FLOAT/DOUBLE: parquet-java hashes through ByteBuffer.putDouble, which keeps the NaN payload (a JDK 17 check kept 0x7ff8000000000001 as is), so both writers hash raw bits. The NaN miss reproduced earlier came from a dictionary-only chunk where Java writes no filter. I expect, but have not checked, that the option above lets the FLOAT/DOUBLE fallback go. That needs an end-to-end test, including a chunk that falls back from dictionary encoding.

Possible in this PR without upstream changes

  • Carry field ids in IcebergColumnBloomFilterProps instead of Java's dot-joined physical path, and resolve leaves natively. ArrowSchemaConverter keeps PARQUET:field_id as each leaf's id, and bloom_filter_memory_bytes already converts the schema. The filter then lands on the leaf the native writer emits, so the renamed-column fallback and the . splitting can go, and Java's Parquet schema is only needed for raw-path names on 1.5 to 1.7. The message has not shipped yet, so now is the cheap time to change it.
  • BloomFilterProperties::builder()...try_build() (parquet 59.0+) returns an error for a bad FPP instead of the setters' panic.
  • Optional: the JVM could call the runtime's own BlockSplitBloomFilter.optimalNumOfBits (public static, shaded under org.apache.iceberg.shaded.org.apache.parquet in the runtime jar) and send the byte count, so the parquet-mr arithmetic lives once instead of in Scala and Rust.

Stays in Comet: the per-runtime naming and validation rules, the Java fallbacks, the exact parquet-mr sizing (the & ~256 rounding and the ignored 32-byte cap), the folding opt-in until parquet-rs has a knob, and the legacy CI job.

Side note: iceberg-rust's reader has optional Bloom pruning since apache/iceberg-rust#2398, and the current pin has it, but iceberg_scan.rs does not enable it (source). So Comet's own native reads do not use these filters yet.

The analysis above is from reading source, apart from the JDK check.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area:Iceberg area:writer Native Parquet writer enhancement New feature or request run-all-spark-profiles Run the Comet test suites against every Spark profile on this pull request, ahead of the merge queue run-iceberg-tests

Projects

None yet

Development

Successfully merging this pull request may close these issues.

8 participants