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

   ### What changes were proposed in this pull request?
   
   Introduces more basic exceptions.
   
   - ArithmeticException
   - ArrayIndexOutOfBoundsException
   - DateTimeException
   - NumberFormatException
   - SparkRuntimeException
   
   ### Why are the changes needed?
   
   There are more exceptions that Spark throws but PySpark doesn't capture.
   
   We should introduce more basic exceptions; otherwise we still see 
`Py4JJavaError` or `SparkConnectGrpcException`.
   
   ```py
   >>> spark.conf.set("spark.sql.ansi.enabled", True)
   >>> spark.sql("select 1/0")
   DataFrame[(1 / 0): double]
   >>> spark.sql("select 1/0").show()
   Traceback (most recent call last):
   ...
   py4j.protocol.Py4JJavaError: An error occurred while calling o44.showString.
   : org.apache.spark.SparkArithmeticException: [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.
   == SQL(line 1, position 8) ==
   select 1/0
          ^^^
   
        at 
org.apache.spark.sql.errors.QueryExecutionErrors$.divideByZeroError(QueryExecutionErrors.scala:225)
   ... JVM's stacktrace
   ```
   
   ```py
   >>> spark.sql("select 1/0").show()
   Traceback (most recent call last):
   ...
   pyspark.errors.exceptions.connect.SparkConnectGrpcException: 
(org.apache.spark.SparkArithmeticException) [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.
   == SQL(line 1, position 8) ==
   select 1/0
          ^^^
   ```
   
   ### Does this PR introduce _any_ user-facing change?
   
   The error message is more readable.
   
   ```py
   >>> spark.sql("select 1/0").show()
   Traceback (most recent call last):
   ...
   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.
   == SQL(line 1, position 8) ==
   select 1/0
          ^^^
   ```
   
   or
   
   ```py
   >>> spark.sql("select 1/0").show()
   Traceback (most recent call last):
   ...
   pyspark.errors.exceptions.connect.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.
   == SQL(line 1, position 8) ==
   select 1/0
          ^^^
   ```
   
   ### How was this patch tested?
   
   Added the related tests.
   


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