[SPARK-59056][SQL] Pre-size HashSets in ParquetFilters IN/InSet pushdown - #58349
Open
david-mollitor-db wants to merge 1 commit into
Open
[SPARK-59056][SQL] Pre-size HashSets in ParquetFilters IN/InSet pushdown#58349david-mollitor-db wants to merge 1 commit into
david-mollitor-db wants to merge 1 commit into
Conversation
`ParquetFilters.makeInPredicate` builds a `java.util.HashSet` for each IN predicate pushed down to Parquet and then adds exactly `values.length` elements. The sets start at the default capacity (16) and rehash as they grow. Pre-size each of the 12 sets from the known element count with Guava's `Sets.newHashSetWithExpectedSize(values.length)` so they hold all IN values without rehashing or reallocating the internal bucket array. The Guava helper is used rather than `new HashSet(values.length)` because `java.util.HashSet`'s int constructor treats the argument as bucket capacity, not expected size, so the naive form would still rehash past ~75% load. This mirrors the existing `Maps.newHashMapWithExpectedSize` usage in sql/catalyst.
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?
ParquetFilters.makeInPredicatebuilds ajava.util.HashSetfor eachINpredicate pushed down to Parquet, then adds exactly
values.lengthelements toit. The sets are created without an initial capacity, so they start at the
default capacity (16) and rehash as they grow.
This PR pre-sizes each of those 12 sets from the known element count using
Guava's
Sets.newHashSetWithExpectedSize(values.length), so they hold allINvalues without rehashing or reallocating the internal bucket array.
The Guava helper is used rather than
new HashSet(values.length)becausejava.util.HashSet's int constructor treats the argument as bucket capacity,not expected size, so the naive form would still rehash once the set passes
~75% load. This mirrors the existing
Maps.newHashMapWithExpectedSizeusage insql/catalyst.Why are the changes needed?
makeInPredicateis only reached when theINlist size exceedsspark.sql.parquet.pushdown.inFilterThreshold(default 10); smaller lists takea per-element equality OR-chain and never build a
HashSet. So by constructionthe set always holds more than the threshold's worth of values, and for larger
INlists (dozens to thousands) the default-capacity set rehashes several timesper pushed-down predicate, allocating and discarding bucket arrays, once per
Parquet file split scanned. Pre-sizing removes that avoidable work. The change
is capacity-only and behavior-preserving.
Does this PR introduce any user-facing change?
No.
How was this patch tested?
Existing
ParquetV1FilterSuite, which coversIN/InSetpredicate pushdown,passes. The change is capacity-only, so predicate semantics are unchanged.
Was this patch authored or co-authored using generative AI tooling?
Generated-by: Claude Opus 4.8