Abhinav-Agarwal021 opened a new pull request, #13697:
URL: https://github.com/apache/gluten/pull/13697

   ## What changes are proposed in this pull request?
   
   Proof of concept for #13685 and facebookincubator/velox#20483, as suggested 
by @rui-mo: one function, end to end.
   
   Depends on facebookincubator/velox#20514. With that change, Velox reports 
the Spark error condition as the error code `SPARK:<condition>`, and 
`checked_divide` reports `SPARK:DIVIDE_BY_ZERO`.
   
   - New `NativeErrorTranslator` (`gluten-core`, `org.apache.spark.sql.errors`):
     - Reads the first `Error Code: SPARK:<condition>` line of the native 
error, walking at most 16 causes. The `Error Code:` line comes before 
`Reason:`, so user data in the reason cannot pose as a code.
     - Builds the matching Spark exception and keeps the native error as its 
cause. Only `DIVIDE_BY_ZERO` is supported for now: 
`SparkArithmeticException("DIVIDE_BY_ZERO", config = spark.sql.ansi.enabled)`.
     - Any other `SPARK:` code logs a warning and keeps the native error, so 
behavior is unchanged.
   - `ColumnarBatchOutIterator.translateException` calls the translator first. 
Errors without a `SPARK:` code go through the existing path unchanged.
   
   Before (ANSI on, `SELECT a / zero FROM ansi_demo` with `zero = 0`):
   
   ```text
   org.apache.spark.SparkException: Job aborted due to stage failure: ...
   org.apache.gluten.exception.GlutenException: ... Exception: VeloxUserError
   Error Source: USER
   Error Code: INVALID_ARGUMENT
   Reason: division by zero
   ```
   
   After, the same condition and SQLSTATE as vanilla Spark, not wrapped:
   
   ```text
   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
   ```
   
   Known gaps, for discussion:
   - No query context (the `== SQL ==` fragment) yet.
   - Only `ColumnarBatchOutIterator` is wired.
   - One condition only.
   - Per @philo-he's comment on velox#20483: a single Gluten-defined fallback 
condition for all other Velox user errors would fit in this translator as a 
follow-up.
   
   ## How was this patch tested?
   
   - New `NativeErrorTranslatorSuite`, which covers:
     - reading the code;
     - ignoring a code-like value inside the `Reason:` text;
     - non-`SPARK:` and empty codes;
     - an unknown condition, which keeps the native error;
     - finding the code in the cause chain.
   - New `ArithmeticAnsiValidateSuite` test "divide by zero throws Spark 
DIVIDE_BY_ZERO error". It checks that the query runs natively 
(`ProjectExecTransformer`) and that the error is `ArithmeticException with 
SparkThrowable`, starts with `[DIVIDE_BY_ZERO]`, has SQLSTATE `22012`, and 
keeps the native error as its cause. This test needs the Velox PR.
   - Verified end to end on a Spark 4.2 cluster with both changes (output 
above).
   - The APIs used (`SparkArithmeticException(String, Map, Array[QueryContext], 
String)`, `QueryExecutionErrors.toSQLConf`) exist in Spark 3.4, 3.5 and 4.x.
   
   ## Was this patch authored or co-authored using generative AI tooling?
   
   Generated-by: GitHub Copilot CLI 1.0.112
   


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