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:00:24 UTC
[spark] branch branch-3.1 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.1
in repository https://gitbox.apache.org/repos/asf/spark.git
The following commit(s) were added to refs/heads/branch-3.1 by this push:
new e58055b [SPARK-35244][SQL] Invoke should throw the original exception
e58055b is described below
commit e58055bdec919704ce82d659aad2d18913de7512
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 76ba523..b93e2e6 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 bc2b93e..6e71c95 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
@@ -608,6 +608,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