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

    https://github.com/apache/spark/pull/16386#discussion_r100653835
  
    --- Diff: 
sql/core/src/test/scala/org/apache/spark/sql/execution/datasources/json/JsonSuite.scala
 ---
    @@ -1764,4 +1769,123 @@ class JsonSuite extends QueryTest with 
SharedSQLContext with TestJsonData {
         val df2 = spark.read.option("PREfersdecimaL", "true").json(records)
         assert(df2.schema == schema)
       }
    +
    +  test("SPARK-18352: Parse normal multi-line JSON files (compressed)") {
    +    withTempPath { dir =>
    +      val path = dir.getCanonicalPath
    +      primitiveFieldAndType
    +        .toDF("value")
    +        .write
    +        .option("compression", "GzIp")
    +        .text(path)
    +
    +      new File(path).listFiles() match {
    +        case compressedFiles =>
    +          assert(compressedFiles.exists(_.getName.endsWith(".gz")))
    +      }
    +
    +      val jsonDF = spark.read.option("wholeFile", true).json(path)
    +      val jsonDir = new File(dir, "json").getCanonicalPath
    +      jsonDF.coalesce(1).write
    +        .format("json")
    +        .option("compression", "gZiP")
    +        .save(jsonDir)
    +
    +      new File(jsonDir).listFiles() match {
    +        case compressedFiles =>
    +          assert(compressedFiles.exists(_.getName.endsWith(".json.gz")))
    +      }
    +
    +      val jsonCopy = spark.read
    +        .format("json")
    +        .load(jsonDir)
    +
    +      assert(jsonCopy.count === jsonDF.count)
    +      val jsonCopySome = jsonCopy.selectExpr("string", "long", "boolean")
    +      val jsonDFSome = jsonDF.selectExpr("string", "long", "boolean")
    +      checkAnswer(jsonCopySome, jsonDFSome)
    +    }
    +  }
    +
    +  test("SPARK-18352: Parse normal multi-line JSON files (uncompressed)") {
    +    withTempPath { dir =>
    +      val path = dir.getCanonicalPath
    +      primitiveFieldAndType
    +        .toDF("value")
    +        .write
    +        .text(path)
    +
    +      val jsonDF = spark.read.option("wholeFile", true).json(path)
    +      val jsonDir = new File(dir, "json").getCanonicalPath
    +      jsonDF.coalesce(1).write
    +        .format("json")
    +        .save(jsonDir)
    +
    +      val compressedFiles = new File(jsonDir).listFiles()
    +      assert(compressedFiles.exists(_.getName.endsWith(".json")))
    +
    +      val jsonCopy = spark.read
    +        .format("json")
    +        .load(jsonDir)
    +
    +      assert(jsonCopy.count === jsonDF.count)
    +      val jsonCopySome = jsonCopy.selectExpr("string", "long", "boolean")
    +      val jsonDFSome = jsonDF.selectExpr("string", "long", "boolean")
    +      checkAnswer(jsonCopySome, jsonDFSome)
    +    }
    +  }
    +
    +  test("SPARK-18352: Expect one JSON document per file") {
    +    // the json parser terminates as soon as it sees a matching END_OBJECT 
or END_ARRAY token.
    +    // this might not be the optimal behavior but this test verifies that 
only the first value
    +    // is parsed and the rest are discarded.
    +
    +    // alternatively the parser could continue parsing following objects, 
which may further reduce
    +    // allocations by skipping the line reader entirely
    +
    +    withTempPath { dir =>
    +      val path = dir.getCanonicalPath
    +      spark
    +        .createDataFrame(Seq(Tuple1("{}{invalid}")))
    +        .coalesce(1)
    +        .write
    +        .text(path)
    +
    +      val jsonDF = spark.read.option("wholeFile", true).json(path)
    +      // no corrupt record column should be created
    +      assert(jsonDF.schema === StructType(Seq()))
    +      // only the first object should be read
    +      assert(jsonDF.count() === 1)
    +    }
    +  }
    +
    +  test("SPARK-18352: Handle corrupt documents") {
    +    withTempPath { dir =>
    +      val path = dir.getCanonicalPath
    +      val corruptRecordCount = additionalCorruptRecords.count().toInt
    +      assert(corruptRecordCount === 5)
    +
    +      additionalCorruptRecords
    +        .toDF("value")
    +        .repartition(corruptRecordCount * 4)
    --- End diff --
    
    Probably, but I'm out of time for today. I'll be out for a few days and can 
pick this back up on Thursday or Friday next week.


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