fix: support Spark 4.1 BloomFilter V2 format and bit-scattering#4196
Open
andygrove wants to merge 3 commits intoapache:mainfrom
Open
fix: support Spark 4.1 BloomFilter V2 format and bit-scattering#4196andygrove wants to merge 3 commits intoapache:mainfrom
andygrove wants to merge 3 commits intoapache:mainfrom
Conversation
Closes apache#4193. Spark 4.1 (`BloomFilter.create`) defaults to a new V2 binary format and a new bit-scattering algorithm in `BloomFilterImplV2`: - V2 binary: `[version=2][numHashFunctions][seed][numWords][bits...]` (V1 omits the seed). - V2 scatter: `combinedHash = (long)h1 * Integer.MAX_VALUE; for (i = 0; i < numHashFunctions; i++) combinedHash += h2;` then take `combinedHash < 0 ? ~combinedHash : combinedHash` mod bitSize. V1 uses `h1 + i*h2` with i in 1..=N and 32-bit arithmetic. Comet's reader hard-rejected non-V1 bytes, and the writer always emitted V1, so on Spark 4.1 both `BloomFilterMightContain from random input` and `bloom_filter_agg` failed with byte/result mismatches. This change: - Adds `SparkBloomFilterVersion` (V1, V2) and a `seed` field to `SparkBloomFilter`. Deserializer detects version from the leading 4 bytes; for V2 it reads the extra seed. Serializer writes the matching layout. `put_long`/`put_binary`/`might_contain_long` branch on version for the bit-scattering algorithm and seed murmur3 with `self.seed` (always 0 for V1; configurable for V2). - Threads the version through `BloomFilterAgg::new` so the aggregator emits the version that matches Spark's output. `BloomFilterAggregate` in Spark always uses `BloomFilterImplV2.DEFAULT_SEED = 0`. - Adds a `version` field to the `BloomFilterAgg` proto and the `BloomFilterVersion` enum (V1 / V2 / Unspecified). - `CometBloomFilterAggregate` (JVM serde) sets V2 on Spark 4.1+ and V1 on Spark <= 4.0. - New Rust tests cover V1 and V2 round-trips, that the two scattering schemes produce different bit patterns for the same input, and that the deserializer rejects unknown versions. - Removes the `assume(!isSpark41Plus, ...)` guards from the `BloomFilterMightContain from random input` and `bloom_filter_agg` Comet test suites; both now pass on Spark 4.1, and the V1 path still passes on Spark 4.0.
The original `assume(!isSpark41Plus, ...)` guards skipped on both 4.1 and 4.2. The previous commit removed them entirely, but Spark 4.2 has a separate `might_contain` / `bloom_filter_agg` registration issue tracked in apache#4142 (`Function identifier must be fully qualified (3-part)`). Tightening the guards back to `assume(!isSpark42Plus, "apache#4142")` lets the tests run on 4.1 (the goal of this PR) while staying skipped on 4.2 (existing behavior).
The previous commit added a `version: SparkBloomFilterVersion` parameter to `BloomFilterAgg::new`, but missed updating the criterion bench under `spark-expr/benches/bloom_filter_agg.rs`. Pass V1 explicitly to match the historic behaviour the bench was written against.
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.
Which issue does this PR close?
Closes #4193 (sub-issue of #4098).
Rationale for this change
Spark 4.1's `BloomFilter.create` defaults to a new V2 implementation (`BloomFilterImplV2`) with both a new binary format and a new bit-scattering algorithm. Comet's reader hard-rejects non-V1 bytes and Comet's writer always emits V1, so on Spark 4.1 both `BloomFilterMightContain from random input` and `bloom_filter_agg` produce wrong results vs Spark.
V1 vs V2:
What changes are included in this PR?
How are these changes tested?