-
Notifications
You must be signed in to change notification settings - Fork 28.9k
[SPARK-17763][SQL] JacksonParser silently parses null as 0 when the field is not nullable #15329
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
Conversation
|
Test build #66257 has finished for PR 15329 at commit
|
|
retest this please |
|
The tests in |
|
Test build #66258 has finished for PR 15329 at commit
|
|
Test build #66260 has finished for PR 15329 at commit
|
|
Hi @yhuai and @cloud-fan , I recall changing codes here was reviewed by you both. Do you mind if I ask to review this please? |
|
|
||
| private[sql] class SparkSQLJsonProcessingException(msg: String) extends RuntimeException(msg) | ||
|
|
||
| private[sql] class NotAllowedNullException(msg: String) extends SparkSQLJsonProcessingException(msg) |
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 do we need this exception?
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 added this one to differentiate this case from other SparkSQLJsonProcessingException[1] because when it fails to parse due to not-allowed null, permissive parse mode is not allowed (because permissive mode virtually means allowing nulls on other fields).
| } | ||
| Nil | ||
| } else { | ||
| throw new NotAllowedNullException(s"Null not allowed: $record") |
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.
Please explain why null is not allowed in the error message. Is it possible to know which field is not nullable? I am not sure if just printing the record is really helpful at here (considering users may often have long JSON records).
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.
Sure, let me try to produce a better message.
|
Actually, when will a user want to specify non-nullable for any json field? I am not sure if we are actually addressing the right problem. I am wondering if we should just not allow non-nullable fields for json. |
|
@yhuai Sure, I support that idea too as I think in the same way. These would be minor cases. However, just the case I thought instantly is, to use the same schema used as it is (because inferring schema in JSON is discouraged in production). For example, df.write.format("json").save(...)
...
spark.read.schema(df.schema).load(...)or anotherDF.select(from_json("a", df.schema))In that case, I guess the original FYI, as you might already know, it forces to the nullable schema reading/writing it from files but not for structured streaming/reading from rdd/ |
|
I am willing to follow your decision if you confirm. |
|
Yea. That's a good point. If we do not allow non-nullable fields, we should also let users easily convert nullability field. Let me also check with @marmbrus. |
|
After re-thinking, I think this might be blocked by #14124 (or at least closely related). Anyhow, it looks dependent of it. Let me close this for now and try to reopen this if I can feel able to proceed this further independently. |
What changes were proposed in this pull request?
This PR proposes handling not nullable field properly in
JacksonParser. For example, the codes below:prints
Before
After
How was this patch tested?
Unit test in
JsonSuite.