pan3793 opened a new pull request, #7805:
URL: https://github.com/apache/kyuubi/pull/7805

   ### Why are the changes needed?
   
   `KyuubiEnsureRequirements` (used by `InsertShuffleNodeBeforeJoin` when 
`spark.sql.optimizer.forceShuffleBeforeJoin.enabled=true`) is a copy of Spark's 
`EnsureRequirements` with only two things removed: join predicate reordering 
and redundant repartition pruning. Both are done by `EnsureRequirements.apply` 
before it calls the private `ensureDistributionAndOrdering` on each operator; 
all the rest of the copy is `ensureDistributionAndOrdering` and its helpers.
   
   Recent Spark versions change that code frequently, even in patch releases 
and between RCs (e.g. the storage-partitioned join fixes SPARK-58968, 
SPARK-59045, SPARK-59121 backported to 4.2.1 break the compilation of the 4.2 
copy), so keeping a fork per Spark minor version in sync is costly and 
error-prone.
   
   This PR replaces the copy in the Spark 3.5, 4.0, 4.1 and 4.2 extensions with 
a thin rule that calls Spark's own `ensureDistributionAndOrdering` via 
reflection, so it always matches the Spark runtime, including patch releases:
   
   1. The method signature is unchanged from Spark 3.5.0 to master, and its 
body reads no `EnsureRequirements` state, so a default instance serves as the 
receiver.
   2. scalac compiles it to a public method with the expanded name 
`org$apache$spark$sql$execution$exchange$EnsureRequirements$$ensureDistributionAndOrdering`
 (verified on Scala 2.12 and 2.13); the plain private name is tried as a 
fallback.
   3. The lookup is lazy, so it only happens when the rule is enabled, and 
fails with a clear `KyuubiSQLExtensionException` if the method is missing.
   
   The Spark 4.3 extension is left unchanged for now.
   
   ### How was this patch tested?
   
   1. `build/mvn clean install -pl extensions/spark/kyuubi-extension-spark-<v> 
-am` with `-Pspark-3.5`, `-Pspark-4.0 -Pscala-2.13`, `-Pspark-4.1 -Pscala-2.13` 
and `-Pspark-4.2 -Pscala-2.13`, all tests pass, including 
`InsertShuffleNodeBeforeJoinSuite`.
   2. Ran the Spark 4.2 extension jar, built against Spark 4.2.1, on a Spark 
4.2.0 binary distribution with `forceShuffleBeforeJoin` enabled: the extra 
shuffles are inserted and the results match the run with the rule disabled.
   3. Pass GHA.
   
   ### Was this patch assisted by generative AI tooling?
   
   Assisted-by: Claude Opus 5.5
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to