GitHub user HyukjinKwon opened a pull request:
https://github.com/apache/spark/pull/15329
[SPARK-17763][SQL] JacksonParser silently parses null as 0 when the field
is not nullable
## What changes were proposed in this pull request?
This PR proposes handling not nullable field properly in `JacksonParser`.
For example, the codes below:
```scala
val testJson = """{"nullInt":null}""" :: Nil
val testSchema = StructType(StructField("nullInt", IntegerType, false) ::
Nil)
val data = spark.sparkContext.parallelize(testJson)
spark.read.schema(testSchema).json(data).show()
```
prints
**Before**
```
+-------+
|nullInt|
+-------+
| 0|
+-------+
```
**After**
```
org.apache.spark.sql.catalyst.json.NotAllowedNullException: Null not
allowed: {"nullInt":null}
at
org.apache.spark.sql.catalyst.json.JacksonParser.failedRecord(JacksonParser.scala:131)
at
org.apache.spark.sql.catalyst.json.JacksonParser.parse(JacksonParser.scala:472)
...
```
## How was this patch tested?
Unit test in`JsonSuite`.
You can merge this pull request into a Git repository by running:
$ git pull https://github.com/HyukjinKwon/spark SPARK-17763
Alternatively you can review and apply these changes as the patch at:
https://github.com/apache/spark/pull/15329.patch
To close this pull request, make a commit to your master/trunk branch
with (at least) the following in the commit message:
This closes #15329
----
commit 88241865ac192a04270ab86b1be65f1b29466707
Author: hyukjinkwon <[email protected]>
Date: 2016-10-03T07:49:54Z
JacksonParser silently parses null as 0 when the field is not nullable
----
---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at [email protected] or file a JIRA ticket
with INFRA.
---
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]