Skip to content

[SPARK-56892][SQL] Bulk read optimization for Parquet DELTA_BINARY_PACKED decoding#56543

Open
iemejia wants to merge 2 commits into
apache:masterfrom
iemejia:SPARK-56892-delta-binary-packed-bulk-read-v2
Open

[SPARK-56892][SQL] Bulk read optimization for Parquet DELTA_BINARY_PACKED decoding#56543
iemejia wants to merge 2 commits into
apache:masterfrom
iemejia:SPARK-56892-delta-binary-packed-bulk-read-v2

Conversation

@iemejia

@iemejia iemejia commented Jun 16, 2026

Copy link
Copy Markdown
Member

What changes were proposed in this pull request?

Re-apply the bulk read optimization for VectorizedDeltaBinaryPackedReader (reverted in c13302a) with a fix for the INT32 widening bug that caused the CI failure.

Commit 1 — Reapply the original optimization (revert of the revert):

  • Bulk readIntegers/readLongs via prefix-sum + putInts/putLongs
  • Zero-allocation unsigned long encoding (encodeUnsignedLongBigEndian)
  • readIntegersAsLongs and readIntegersAsDoubles overrides

Commit 2 — Fix the INT32 widening bug:

  • The Parquet INT32 delta encoder (DeltaBinaryPackingValuesWriterForInteger) computes deltas using Java int arithmetic with modular overflow. The bulk widened readers (readIntegersAsLongs, readIntegersAsDoubles) were performing the prefix sum in long space and writing raw long results without truncating back to int. When delta overflow occurs (e.g. a sequence containing Int.MinValue), the reconstructed long has the wrong sign.
  • Fix: truncate each prefix-sum result to int before widening to long/double
  • Add focused low-level tests for the overflow case (single-batch and split reads)
  • Add benchmark cases for the overflow pattern

This is the same content as #55919, which was merged and reverted due to this bug.

Why are the changes needed?

The bulk read path eliminates per-value lambda dispatch overhead and enables the JIT to better vectorize the inner unpacking loop. See #55919 for full benchmark results.

Does this PR introduce any user-facing change?

No.

How was this patch tested?

  • ParquetTypeWideningSuite: IntegerType -> LongType, IntegerType -> DoubleType
  • ParquetDeltaEncodingInteger: new focused tests for modular delta overflow
  • ParquetDeltaEncodingInteger/Long: full suites (30 tests)
  • ParquetIOSuite: UINT_64 tests
  • VectorizedDeltaReaderBenchmark: full suite including new overflow cases

Was this patch authored or co-authored using generative AI tooling?

Yes.

Assisted-by: GitHub Copilot:claude-opus-4.6

cc @LuciferYang @sunchao

iemejia added 2 commits June 16, 2026 11:17
### What changes were proposed in this pull request?

Fix readIntegersAsLongs and readIntegersAsDoubles in
VectorizedDeltaBinaryPackedReader to truncate each prefix-sum
result to int before widening, matching the INT32 encoder's
modular arithmetic.

### Why are the changes needed?

The Parquet INT32 delta encoder (DeltaBinaryPackingValuesWriterForInteger)
computes deltas using Java int arithmetic, which wraps on overflow.
The bulk widened reader was performing the prefix sum in long space and
writing the raw long result without narrowing back to int.  When the
delta overflows 32 bits (e.g. a sequence containing Int.MinValue), the
reconstructed long value has the wrong sign -- Int.MinValue appears as
+2147483648 instead of -2147483648.

### Does this PR introduce _any_ user-facing change?

No.  This fixes a correctness bug introduced by the bulk read
optimization for readIntegersAsLongs/readIntegersAsDoubles.

### How was this patch tested?

- ParquetTypeWideningSuite: IntegerType -> LongType, IntegerType -> DoubleType
- ParquetDeltaEncodingInteger: new focused tests for modular delta overflow
  with both single-batch and split reads
- VectorizedDeltaReaderBenchmark: new overflow-pattern cases for
  readIntegersAsLongs and readIntegersAsDoubles
- Full ParquetDeltaEncodingInteger/Long suites (30 tests)
- ParquetIOSuite UINT_64 tests

### Was this patch authored or co-authored using generative AI tooling?

Yes.

Assisted-by: GitHub Copilot:claude-opus-4.6
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant