forked from apache/spark
-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[SPARK-45022][SQL] Provide context for dataset API errors
### What changes were proposed in this pull request? This PR captures the dataset APIs used by the user code and the call site in the user code and provides better error messages. E.g. consider the following Spark app `SimpleApp.scala`: ```scala 1 import org.apache.spark.sql.SparkSession 2 import org.apache.spark.sql.functions._ 3 4 object SimpleApp { 5 def main(args: Array[String]) { 6 val spark = SparkSession.builder.appName("Simple Application").config("spark.sql.ansi.enabled", true).getOrCreate() 7 import spark.implicits._ 8 9 val c = col("a") / col("b") 10 11 Seq((1, 0)).toDF("a", "b").select(c).show() 12 13 spark.stop() 14 } 15 } ``` After this PR the error message contains the error context (which Spark Dataset API is called from where in the user code) in the following form: ``` Exception in thread "main" 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. == Dataset == "div" was called from SimpleApp$.main(SimpleApp.scala:9) at org.apache.spark.sql.errors.QueryExecutionErrors$.divideByZeroError(QueryExecutionErrors.scala:201) at org.apache.spark.sql.catalyst.expressions.DivModLike.eval(arithmetic.scala:672 ... ``` which is similar to the already provided context in case of SQL queries: ``` 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 1) == a / b ^^^^^ at org.apache.spark.sql.errors.QueryExecutionErrors$.divideByZeroError(QueryExecutionErrors.scala:201) at org.apache.spark.sql.errors.QueryExecutionErrors.divideByZeroError(QueryExecutionErrors.scala) ... ``` Please note that stack trace in `spark-shell` doesn't contain meaningful elements: ``` scala> Thread.currentThread().getStackTrace.foreach(println) java.base/java.lang.Thread.getStackTrace(Thread.java:1602) $line15.$read$$iw$$iw$$iw$$iw$$iw$$iw$$iw$$iw.<init>(<console>:23) $line15.$read$$iw$$iw$$iw$$iw$$iw$$iw$$iw.<init>(<console>:27) $line15.$read$$iw$$iw$$iw$$iw$$iw$$iw.<init>(<console>:29) $line15.$read$$iw$$iw$$iw$$iw$$iw.<init>(<console>:31) $line15.$read$$iw$$iw$$iw$$iw.<init>(<console>:33) $line15.$read$$iw$$iw$$iw.<init>(<console>:35) $line15.$read$$iw$$iw.<init>(<console>:37) $line15.$read$$iw.<init>(<console>:39) $line15.$read.<init>(<console>:41) $line15.$read$.<init>(<console>:45) $line15.$read$.<clinit>(<console>) $line15.$eval$.$print$lzycompute(<console>:7) $line15.$eval$.$print(<console>:6) $line15.$eval.$print(<console>) java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method) java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ... ``` so this change doesn't help with that usecase. ### Why are the changes needed? To provide more user friendly errors. ### Does this PR introduce _any_ user-facing change? Yes. ### How was this patch tested? Added new UTs to `QueryExecutionAnsiErrorsSuite`. ### Was this patch authored or co-authored using generative AI tooling? No. Closes apache#43334 from MaxGekk/context-for-dataset-api-errors. Lead-authored-by: Max Gekk <[email protected]> Co-authored-by: Peter Toth <[email protected]> Signed-off-by: Max Gekk <[email protected]>
- Loading branch information
1 parent
e1bc48b
commit feea99e
Showing
71 changed files
with
1,163 additions
and
471 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
31 changes: 31 additions & 0 deletions
31
common/utils/src/main/java/org/apache/spark/QueryContextType.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
/* | ||
* Licensed to the Apache Software Foundation (ASF) under one or more | ||
* contributor license agreements. See the NOTICE file distributed with | ||
* this work for additional information regarding copyright ownership. | ||
* The ASF licenses this file to You under the Apache License, Version 2.0 | ||
* (the "License"); you may not use this file except in compliance with | ||
* the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package org.apache.spark; | ||
|
||
import org.apache.spark.annotation.Evolving; | ||
|
||
/** | ||
* The type of {@link QueryContext}. | ||
* | ||
* @since 4.0.0 | ||
*/ | ||
@Evolving | ||
public enum QueryContextType { | ||
SQL, | ||
DataFrame | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
Oops, something went wrong.