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

   ### What changes were proposed in this pull request?
   
   This PR proposes to support `DataFrameQueryContext` for reverse operations, 
such as `rdiv`, `rsub` and `rmod`.
   
   ### Why are the changes needed?
   
   To improve debuggability for reverse binary operations.
   
   ### Does this PR introduce _any_ user-facing change?
   
   No API changes, but the user-facing error messages for reverse binary 
operations will be improved:
   
   **Example**
   
   The problematic `rdiv` is called from 4th line which raises `DIVIDE_BY_ZERO`:
   
   ```python
     1 spark.conf.set("spark.sql.ansi.enabled", True)
     2 df = spark.createDataFrame([(0,), (1,), (2,)], ["id"])
     3
     4 a = 10 / df.id
     5 b = 0 / df.id
     6
     7 df.select(
     8     a,
     9     df.id + 4,
    10     b,
    11     df.id * 5
    12 ).collect()
   ```
   
   **Before**
   ```python
   pyspark.errors.exceptions.captured.ArithmeticException: [DIVIDE_BY_ZERO] 
Division by zero. Use `try_divide` to tolerate divisor being 0 and return NULL 
instead. If necessary set "spark.sql.ansi.enabled" to "false" to bypass this 
error. SQLSTATE: 22012
   == DataFrame ==
   "divide" was called from
   java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native 
Method)
   ```
   
   **After**
   ```python
   pyspark.errors.exceptions.captured.ArithmeticException: [DIVIDE_BY_ZERO] 
Division by zero. Use `try_divide` to tolerate divisor being 0 and return NULL 
instead. If necessary set "spark.sql.ansi.enabled" to "false" to bypass this 
error. SQLSTATE: 22012
   == DataFrame ==
   "divide" was called from
   test_error_context.py:4
   ```
   
   
   ### How was this patch tested?
   
   
   ### Was this patch authored or co-authored using generative AI tooling?
   


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