holdenk opened a new pull request, #60598:
URL: https://github.com/apache/spark/pull/60598

   Backport-of: #59814
   
   ### What changes were proposed in this pull request?
   
   When `spark.sql.crossJoin.enabled=false`, `ConvertToCatalyst` now keeps a 
transpiled UDF as a Python UDF if it is the only condition linking the two 
sides of a join. This covers the UDF in the join condition and in a `where` 
right above the join.
   
   co-authored with: jing.zhansnowflake.com
   
   ### Why are the changes needed?
   
   ```python
   spark.conf.set("spark.sql.crossJoin.enabled", "false")
   same = lambda a, b: a == b
   left.join(right, udf(same, BooleanType())("a", "b")).collect()
   ```
   
   - Transpilation off: fails with "Detected implicit cartesian product".
   - Transpilation on: no error, and it silently runs a `CartesianProduct`.
   
   The transpiled expression reads both sides, so `CheckCartesianProducts` lets 
it through. But Spark can't use it as a join key.
   
   ### Does this PR introduce _any_ user-facing change?
   
   Only for the unreleased, experimental 
`spark.sql.experimental.optimizer.transpilePyUDFs`. The cartesian product error 
now matches transpilation off.
   
   ### How was this patch tested?
   
   New tests in `ConvertToCatalystSuite` and `test_udf_transpile_unit.py`.
   
   ### Was this patch authored or co-authored using generative AI tooling?
   
   Co-authored by: Claude Code
   
   Closes #59814 from jzhan-2026/spark-58780-cartesian-guard.
   
   Authored-by: jzhan-2026 <[email protected]>
   Signed-off-by: Holden Karau <[email protected]>
   
   (cherry picked from commit 3438c728d38c11fc173f0829b86709c639123961)
   Signed-off-by: Holden Karau <[email protected]>


-- 
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