[SPARK-56444][SQL] Fix equals/hashCode contract violations in BatchScanExec#55297
Open
anton5798 wants to merge 1 commit intoapache:masterfrom
Open
[SPARK-56444][SQL] Fix equals/hashCode contract violations in BatchScanExec#55297anton5798 wants to merge 1 commit intoapache:masterfrom
anton5798 wants to merge 1 commit intoapache:masterfrom
Conversation
…anExec ### What changes were proposed in this pull request? Fix two contract violations in `BatchScanExec.equals()`/`hashCode()`: 1. **Reflexivity violation**: `equals()` had a `this.batch != null` guard, so `x.equals(x)` returned `false` when `batch` was null (which happens after serialization round-trip since `scan` is `@transient`). 2. **hashCode inconsistency**: `hashCode()` did not include `keyGroupedPartitioning`, but `equals()` compared it — violating the contract that equal objects must have equal hash codes. ### Why are the changes needed? These violations can cause incorrect behavior when `BatchScanExec` instances are used in hash-based collections (e.g., `HashMap`, `HashSet`) or when comparing plans after serialization. ### Does this PR introduce _any_ user-facing change? No. ### How was this patch tested? Added unit tests in `SparkPlanSuite` verifying: - Reflexivity when `batch` is null - hashCode consistency with equals - hashCode sensitivity to `keyGroupedPartitioning` ### Was this patch authored or co-authored using generative AI tooling? Yes.
aokolnychyi
approved these changes
Apr 10, 2026
Contributor
aokolnychyi
left a comment
There was a problem hiding this comment.
LGTM, pending CI.
@anton5798, double check this PR that added this.batch != null in equals.
szehon-ho
reviewed
Apr 10, 2026
| keyGroupedPartitioning = Some(Seq(Literal(2))) | ||
| ) | ||
| assert(!exec1.equals(exec2)) | ||
| assert(exec1.hashCode() != exec2.hashCode()) |
Member
There was a problem hiding this comment.
nit: would this fail with very low probability? should we remove?
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.
What changes were proposed in this pull request?
Fix two contract violations in
BatchScanExec.equals()/hashCode():equals()had athis.batch != nullguard, sox.equals(x)returnedfalsewhenbatchwas null (which happens after serialization round-trip sincescanis@transient).hashCode()did not includekeyGroupedPartitioning, butequals()compared it — violating the contract that equal objects must have equal hash codes.Why are the changes needed?
These violations can cause incorrect behavior when
BatchScanExecinstances are used in hash-based collections (e.g.,HashMap,HashSet) or when comparing plans after serialization.How was this patch tested?
Added unit tests in
SparkPlanSuiteverifying:batchis nullkeyGroupedPartitioningWas this patch authored or co-authored using generative AI tooling?
Yes.