You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@spark.apache.org by we...@apache.org on 2021/04/28 06:01:22 UTC
[spark] branch branch-3.0 updated: [SPARK-35244][SQL] Invoke should
throw the original exception
This is an automated email from the ASF dual-hosted git repository.
wenchen pushed a commit to branch branch-3.0
in repository https://gitbox.apache.org/repos/asf/spark.git
The following commit(s) were added to refs/heads/branch-3.0 by this push:
new 6e83789b [SPARK-35244][SQL] Invoke should throw the original exception
6e83789b is described below
commit 6e83789be5fe5141affee600f9b614996cd91482
Author: Wenchen Fan <we...@databricks.com>
AuthorDate: Wed Apr 28 10:45:04 2021 +0900
[SPARK-35244][SQL] Invoke should throw the original exception
### What changes were proposed in this pull request?
This PR updates the interpreted code path of invoke expressions, to unwrap the `InvocationTargetException`
### Why are the changes needed?
Make interpreted and codegen path consistent for invoke expressions.
### Does this PR introduce _any_ user-facing change?
no
### How was this patch tested?
new UT
Closes #32370 from cloud-fan/minor.
Authored-by: Wenchen Fan <we...@databricks.com>
Signed-off-by: hyukjinkwon <gu...@apache.org>
---
.../spark/sql/catalyst/expressions/objects/objects.scala | 7 ++++++-
.../sql/catalyst/expressions/ObjectExpressionsSuite.scala | 10 ++++++++++
2 files changed, 16 insertions(+), 1 deletion(-)
diff --git a/sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/expressions/objects/objects.scala b/sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/expressions/objects/objects.scala
index 7ebf70b..71eacce 100644
--- a/sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/expressions/objects/objects.scala
+++ b/sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/expressions/objects/objects.scala
@@ -127,7 +127,12 @@ trait InvokeLike extends Expression with NonSQLExpression {
// return null if one of arguments is null
null
} else {
- val ret = method.invoke(obj, args: _*)
+ val ret = try {
+ method.invoke(obj, args: _*)
+ } catch {
+ // Re-throw the original exception.
+ case e: java.lang.reflect.InvocationTargetException => throw e.getCause
+ }
val boxedClass = ScalaReflection.typeBoxedJavaMapping.get(dataType)
if (boxedClass.isDefined) {
boxedClass.get.cast(ret)
diff --git a/sql/catalyst/src/test/scala/org/apache/spark/sql/catalyst/expressions/ObjectExpressionsSuite.scala b/sql/catalyst/src/test/scala/org/apache/spark/sql/catalyst/expressions/ObjectExpressionsSuite.scala
index c401493..50c76f1 100644
--- a/sql/catalyst/src/test/scala/org/apache/spark/sql/catalyst/expressions/ObjectExpressionsSuite.scala
+++ b/sql/catalyst/src/test/scala/org/apache/spark/sql/catalyst/expressions/ObjectExpressionsSuite.scala
@@ -604,6 +604,16 @@ class ObjectExpressionsSuite extends SparkFunSuite with ExpressionEvalHelper {
checkExceptionInExpression[RuntimeException](
serializer4, EmptyRow, "Cannot use null as map key!")
}
+
+ test("SPARK-35244: invoke should throw the original exception") {
+ val strClsType = ObjectType(classOf[String])
+ checkExceptionInExpression[StringIndexOutOfBoundsException](
+ Invoke(Literal("a", strClsType), "substring", strClsType, Seq(Literal(3))), "")
+
+ val mathCls = classOf[Math]
+ checkExceptionInExpression[ArithmeticException](
+ StaticInvoke(mathCls, IntegerType, "addExact", Seq(Literal(Int.MaxValue), Literal(1))), "")
+ }
}
class TestBean extends Serializable {
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@spark.apache.org
For additional commands, e-mail: commits-help@spark.apache.org