Github user HyukjinKwon commented on a diff in the pull request:

    https://github.com/apache/spark/pull/16976#discussion_r120034550
  
    --- Diff: 
sql/core/src/main/scala/org/apache/spark/sql/DataFrameReader.scala ---
    @@ -463,6 +463,7 @@ class DataFrameReader private[sql](sparkSession: 
SparkSession) extends Logging {
        * <li>`columnNameOfCorruptRecord` (default is the value specified in
        * `spark.sql.columnNameOfCorruptRecord`): allows renaming the new field 
having malformed string
        * created by `PERMISSIVE` mode. This overrides 
`spark.sql.columnNameOfCorruptRecord`.</li>
    +   * <li>`wholeFile` (default `false`): parse one record, which may span 
multiple lines.</li>
    --- End diff --
    
    Definitely. I wanted to emphasize multiple lines is not _per file_. 
    
    For example, CSV reads multiple records (multiple lines) per file (newline 
is replaced to `\n` manually for readability).
    
    ```csv
    "I am
    Hyukjin Kwon"
    "Hyukjin Kwon
    I love Spark!"
    ```
    
    ```scala
    scala> spark.read.option("wholeFile", true).csv("test.csv").show()
    +---------------------+
    |                  _c0|
    +---------------------+
    |   I am\nHyukjin Kwon|
    |Hyukjin Kwon\nI lo...|
    +---------------------+
    ```
    
    Whereas JSON reads the record _per file_. I am pretty sure object root 
support is primary.
    
    ```json
    {
      "I am": "HyukjinKwon",
      "HyukjinKwon": "I love Spark!"
    }
    ```
    
    ```scala
    scala> spark.read.option("wholeFile", true).json("test.json").show()
    +-------------+-----------+
    |  HyukjinKwon|       I am|
    +-------------+-----------+
    |I love Spark!|HyukjinKwon|
    +-------------+-----------+
    ```
    
    but note that it could (in terms of input/output), work similarly with CSV 
when the input is a json array.
    
    ```json
    [{
      "I am": "HyukjinKwon",
      "HyukjinKwon": "I love Spark!"
    },{
      "I am": "HyukjinKwon",
      "HyukjinKwon": "I love Spark!"
    }]
    ```
    
    ```scala
    scala> spark.read.option("wholeFile", true).json("test.json").show()
    +-------------+-----------+
    |  HyukjinKwon|       I am|
    +-------------+-----------+
    |I love Spark!|HyukjinKwon|
    |I love Spark!|HyukjinKwon|
    +-------------+-----------+
    ```
    
    Comparing array case and CSV, they work still differently. JSON, up to my 
knowledge, parses whole files and produces each record (in case or an array) 
whereas CSV parses record by record from the stream.



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