[SPARK] Infer cast-wrapped join keys in InferRebalanceAndSortOrders#7587
Open
ulysses-you wants to merge 1 commit into
Open
[SPARK] Infer cast-wrapped join keys in InferRebalanceAndSortOrders#7587ulysses-you wants to merge 1 commit into
ulysses-you wants to merge 1 commit into
Conversation
ulysses-you
force-pushed
the
ne-infer-cast-wrapped-join-keys
branch
from
July 24, 2026 07:58
988e1eb to
3999f3a
Compare
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.
Why are the changes needed?
Two fixes to
InferRebalanceAndSortOrders(applied across the Spark 3.5, 4.0, 4.1 and 4.2 extension modules):Support cast-wrapped join keys. When join key columns have mismatched types (e.g. via a
UNION ALLbranch that widensinttobigint), the analyzer inserts a cast on the join key such ascast(genre_tag_id as bigint). The outer projection's alias map is keyed by the unary-peeled attribute, so the full cast expression never matched and the key was silently dropped by theoutputSetfilter — only the un-cast keys survived, weakening the inferred rebalance/sort. This addsmapThroughAlias, which retries the alias lookup with the unary-peeled key (symmetric with howgetAliasMapbuilds its keys), so a cast-wrapped key maps back to its aliased output attribute.Castis also treated as cheap inisCheapfor keys that survive without being aliased away.Gate the cheap-column check by
maxColumns.INFER_REBALANCE_AND_SORT_ORDERS_MAX_COLUMNSis now threaded intoinferand the truncation is applied before the cheap-column check, so only the firstmaxColumnsinferred columns need to be cheap (previously an expensive key beyond the limit could discard the whole inference).How was this patch tested?
Added unit tests in
RebalanceBeforeWritingSuitefor each affected module:Castover a cheap column is treated as cheap,maxColumnsgates the cheap-column check.Verified locally with:
build/mvn -Pspark-3.5 test -pl extensions/spark/kyuubi-extension-spark-3-5 -am -DwildcardSuites=org.apache.spark.sql.RebalanceBeforeWritingSuite-Pscala-2.13): same suite per module.All suites pass;
dev/reformatapplied.Was this patch authored or co-authored using generative AI tooling?
Assisted-by: Claude:claude-opus-4-8