GitHub user HyukjinKwon opened a pull request:

    https://github.com/apache/spark/pull/17492

    [SPARK-19641][SQL] JSON schema inference in DROPMALFORMED mode produces 
incorrect schema for non-array/object JSONs

    ## What changes were proposed in this pull request?
    
    Currently, when we infer the types for vaild JSON strings but object or 
array, we are producing empty schemas regardless of parse modes as below:
    
    ```scala
    scala> spark.read.option("mode", "DROPMALFORMED").json(Seq("""{"a": 1}""", 
""""a"""").toDS).printSchema()
    root
    
    
    scala> spark.read.option("mode", "FAILFAST").json(Seq("""{"a": 1}""", 
""""a"""").toDS).printSchema()
    root
    ```
    
    This PR proposes to handle parse modes in type inference.
    
    After this PR,
    
    ```scala
    
    scala> spark.read.option("mode", "DROPMALFORMED").json(Seq("""{"a": 1}""", 
""""a"""").toDS).printSchema()
    root
     |-- a: long (nullable = true)
    ```
    
    ```
    scala> spark.read.option("mode", "FAILFAST").json(Seq("""{"a": 1}""", 
""""a"""").toDS).printSchema()
    java.lang.RuntimeException: Failed to infer a common schema. Struct types 
are expected but string was found.
    ```
    
    This PR is based on 
https://github.com/NathanHowell/spark/commit/e233fd03346a73b3b447fa4c24f3b12c8b2e53ae
 and I and @NathanHowell talked about this in 
https://issues.apache.org/jira/browse/SPARK-19641
    
    
    ## How was this patch tested?
    
    Unit tests in `JsonSuite` for both `DROPMALFORMED` and `FAILFAST` modes.


You can merge this pull request into a Git repository by running:

    $ git pull https://github.com/HyukjinKwon/spark SPARK-19641

Alternatively you can review and apply these changes as the patch at:

    https://github.com/apache/spark/pull/17492.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 #17492
    
----
commit dc24522502b3f7816d539da2c8efb09a3515bb70
Author: hyukjinkwon <[email protected]>
Date:   2017-03-31T04:52:27Z

    JSON schema inference in DROPMALFORMED mode produces incorrect schema

----


---
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]

Reply via email to