Skip to content

[SPARK-57561][SQL] Add size validation to bitmap_or_agg and bitmap_and_agg - #57567

Open
ybapat wants to merge 1 commit into
apache:masterfrom
ybapat:issue-57561-bitmap-validation
Open

[SPARK-57561][SQL] Add size validation to bitmap_or_agg and bitmap_and_agg#57567
ybapat wants to merge 1 commit into
apache:masterfrom
ybapat:issue-57561-bitmap-validation

Conversation

@ybapat

@ybapat ybapat commented Jul 27, 2026

Copy link
Copy Markdown
Contributor

What changes were proposed in this pull request?

bitmap_or_agg and bitmap_and_agg silently accept input bitmaps of any size. When an input bitmap is larger than BitmapExpressionUtils.NUM_BYTES (4096 bytes), bitmapMerge / bitmapAndMerge silently reads only the first 4096 bytes, discarding the rest. This can produce incorrect results without any indication that data was dropped.

This PR adds an explicit runtime check in the update() methods of both BitmapOrAgg and BitmapAndAgg. If the input exceeds 4096 bytes, a SparkRuntimeException with error class BITMAP_INPUT_TOO_LARGE is thrown.

Changes:

  • Add BITMAP_INPUT_TOO_LARGE error condition to error-conditions.json (SQLSTATE 22001 — string/binary data right truncation).
  • Add bitmapInputTooLargeError factory method to QueryExecutionErrors.
  • Add size guard in BitmapOrAgg.update() and BitmapAndAgg.update().
  • Update @ExpressionDescription for both aggregates to accurately document short-input behavior and the size limit.
  • Add two tests in BitmapExpressionsQuerySuite verifying the error is thrown.

Why are the changes needed?

Without validation, oversized inputs are silently truncated, producing incorrect aggregate results with no warning. Explicit validation follows Spark's design principle of failing fast with a structured error rather than silently producing wrong results.

Does this PR introduce any user-facing change?

Yes. Queries that pass bitmaps larger than 4096 bytes to bitmap_or_agg or bitmap_and_agg will now fail with BITMAP_INPUT_TOO_LARGE instead of silently truncating. Inputs created by bitmap_construct_agg() are always exactly 4096 bytes and are unaffected.

How was this patch tested?

  • New tests "bitmap_or_agg rejects input larger than 4096 bytes" and "bitmap_and_agg rejects input larger than 4096 bytes" in BitmapExpressionsQuerySuite.
  • Existing bitmap expression tests pass.

Closes #57561

Co-Authored-By: Claude Sonnet 4.6 noreply@anthropic.com

… oversized input validation

The ExpressionDescription for bitmap_or_agg and bitmap_and_agg stated
'input should be bitmaps from bitmap_construct_agg()' while examples
used 1-byte literals. Clarify that shorter inputs are supported and
add a runtime error for inputs exceeding 4096 bytes (which would
otherwise be silently truncated).

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@art000109

art000109 commented Jul 27, 2026

Copy link
Copy Markdown
Contributor

Spark-57561 is a task for this PR #56999

Isn't it?

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.

[SQL] Clarify bitmap_or_agg / bitmap_and_agg input contract: fixed 4096-byte vs. variable-length bitmaps

2 participants