-
Notifications
You must be signed in to change notification settings - Fork 28.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[SPARK-18260] Make from_json null safe #15771
Conversation
Seq("""{"a": 1}""").toDF("value").write.parquet(new File(dir, "p=x").toString) | ||
Seq("""{"a": 2}""").toDF("record").write.parquet(new File(dir, "p=y").toString) | ||
val schema = new StructType().add("a", IntegerType) | ||
val df = spark.read.parquet(dir.toString) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why parquet? Seems this is testing more than it needs to (and thus runs slower).
@@ -499,6 +499,7 @@ case class JsonToStruct(schema: StructType, options: Map[String, String], child: | |||
|
|||
override def eval(input: InternalRow): Any = { | |||
try parser.parse(child.eval(input).toString).head catch { | |||
case _: NullPointerException => null |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would consider doing this with an if
. I think catching and throwing an exception can be expensive (though maybe JVM optimizations save us?). Since its easy I'd rather not rely on that.
@marmbrus Addressed |
Test build #68151 has finished for PR 15771 at commit
|
Test build #68156 has finished for PR 15771 at commit
|
Test build #68155 has finished for PR 15771 at commit
|
@@ -498,7 +498,7 @@ case class JsonToStruct(schema: StructType, options: Map[String, String], child: | |||
override def children: Seq[Expression] = child :: Nil | |||
|
|||
override def eval(input: InternalRow): Any = { | |||
try parser.parse(child.eval(input).toString).head catch { | |||
try Option(child.eval(input)).map(json => parser.parse(json.toString).head).orNull catch { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry to keep iterating... I think you want to avoid an extra allocation in the execution path. I would use an if
statement.
LGTM, pending tests |
Test build #68165 has finished for PR 15771 at commit
|
Merging in master/branch-2.1. |
## What changes were proposed in this pull request? `from_json` is currently not safe against `null` rows. This PR adds a fix and a regression test for it. ## How was this patch tested? Regression test Author: Burak Yavuz <[email protected]> Closes #15771 from brkyvz/json_fix. (cherry picked from commit 6e27018) Signed-off-by: Reynold Xin <[email protected]>
## What changes were proposed in this pull request? `from_json` is currently not safe against `null` rows. This PR adds a fix and a regression test for it. ## How was this patch tested? Regression test Author: Burak Yavuz <[email protected]> Closes apache#15771 from brkyvz/json_fix.
What changes were proposed in this pull request?
from_json
is currently not safe againstnull
rows. This PR adds a fix and a regression test for it.How was this patch tested?
Regression test