Github user HyukjinKwon commented on the issue:

    https://github.com/apache/spark/pull/18865
  
    > the usage can cause weird results too
    
    > `_corrupt_record` should return all the records that Spark SQL fail to 
parse
    
    I think another point should be, this issue still exists even if we 
disallow selecting `_corrupt_record` alone here. If we select few columns 
together with `_corrupt_record`, this case will still exist and results won't 
be consistent. For example,
    
    ```
    echo '{"fieldA": 1, "fieldB": 2}
     {"fieldA": 3, "fieldB": 4}
     {"fieldA": "5", "fieldB": 6}' >/tmp/sample.json
    ```
    
    ```scala
    val file = "/tmp/sample.json"
    val dfFromFile = spark.read.schema("fieldA BYTE, fieldB BYTE, 
_corrupt_record STRING").json(file)
    dfFromFile.select($"fieldA", $"_corrupt_record").show()
    dfFromFile.select($"fieldB", $"_corrupt_record").show()
    ```
    
    ```
    scala> dfFromFile.select($"fieldA", $"_corrupt_record").show()
    +------+--------------------+
    |fieldA|     _corrupt_record|
    +------+--------------------+
    |     1|                null|
    |     3|                null|
    |  null| {"fieldA": "5", ...|
    +------+--------------------+
    
    
    scala> dfFromFile.select($"fieldB", $"_corrupt_record").show()
    +------+---------------+
    |fieldB|_corrupt_record|
    +------+---------------+
    |     2|           null|
    |     4|           null|
    |     6|           null|
    +------+---------------+
    ```
    
    If we should disallow, I think we should rather deprecate this option first 
with some warnings, or explain this behaviour in the documentation.


---
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 infrastruct...@apache.org or file a JIRA ticket
with INFRA.
---

---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscr...@spark.apache.org
For additional commands, e-mail: reviews-h...@spark.apache.org

Reply via email to