Skip to content
Snippets Groups Projects
Commit e1afc4dc authored by Reynold Xin's avatar Reynold Xin Committed by Xiao Li
Browse files

[SPARK-20262][SQL] AssertNotNull should throw NullPointerException

## What changes were proposed in this pull request?
AssertNotNull currently throws RuntimeException. It should throw NullPointerException, which is more specific.

## How was this patch tested?
N/A

Author: Reynold Xin <rxin@databricks.com>

Closes #17573 from rxin/SPARK-20262.
parent 7577e9c3
No related branches found
No related tags found
No related merge requests found
...@@ -989,7 +989,7 @@ case class InitializeJavaBean(beanInstance: Expression, setters: Map[String, Exp ...@@ -989,7 +989,7 @@ case class InitializeJavaBean(beanInstance: Expression, setters: Map[String, Exp
* `Int` field named `i`. Expression `s.i` is nullable because `s` can be null. However, for all * `Int` field named `i`. Expression `s.i` is nullable because `s` can be null. However, for all
* non-null `s`, `s.i` can't be null. * non-null `s`, `s.i` can't be null.
*/ */
case class AssertNotNull(child: Expression, walkedTypePath: Seq[String]) case class AssertNotNull(child: Expression, walkedTypePath: Seq[String] = Nil)
extends UnaryExpression with NonSQLExpression { extends UnaryExpression with NonSQLExpression {
override def dataType: DataType = child.dataType override def dataType: DataType = child.dataType
...@@ -1005,7 +1005,7 @@ case class AssertNotNull(child: Expression, walkedTypePath: Seq[String]) ...@@ -1005,7 +1005,7 @@ case class AssertNotNull(child: Expression, walkedTypePath: Seq[String])
override def eval(input: InternalRow): Any = { override def eval(input: InternalRow): Any = {
val result = child.eval(input) val result = child.eval(input)
if (result == null) { if (result == null) {
throw new RuntimeException(errMsg) throw new NullPointerException(errMsg)
} }
result result
} }
...@@ -1021,7 +1021,7 @@ case class AssertNotNull(child: Expression, walkedTypePath: Seq[String]) ...@@ -1021,7 +1021,7 @@ case class AssertNotNull(child: Expression, walkedTypePath: Seq[String])
${childGen.code} ${childGen.code}
if (${childGen.isNull}) { if (${childGen.isNull}) {
throw new RuntimeException($errMsgField); throw new NullPointerException($errMsgField);
} }
""" """
ev.copy(code = code, isNull = "false", value = childGen.value) ev.copy(code = code, isNull = "false", value = childGen.value)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment