Github user cloud-fan commented on a diff in the pull request:
https://github.com/apache/spark/pull/11756#discussion_r56784202
--- Diff:
sql/core/src/test/scala/org/apache/spark/sql/execution/datasources/json/JsonSuite.scala
---
@@ -963,6 +964,53 @@ class JsonSuite extends QueryTest with
SharedSQLContext with TestJsonData {
)
}
+ test("SPARK-13764 Parse modes in JSON data source") {
+ val schemaOne = StructType(
+ StructField("a", StringType, true) ::
+ StructField("b", StringType, true) ::
+ StructField("c", StringType, true) :: Nil)
+
+ val schemaTwo = StructType(
+ StructField("a", StringType, true) :: Nil)
+
+ // `FAILFAST` mode should throw an exception for corrupt records.
+ val exceptionOne = intercept[SparkException] {
+ sqlContext.read
+ .option("mode", "FAILFAST")
+ .json(corruptRecords)
+ .collect()
+ }
+ assert(exceptionOne.getMessage.contains("Malformed line in FAILFAST
mode: {"))
+ val exceptionTwo = intercept[SparkException] {
+ sqlContext.read
+ .option("mode", "FAILFAST")
+ .schema(schemaTwo)
+ .json(corruptRecords)
+ .collect()
+ }
+ assert(exceptionTwo.getMessage.contains("Malformed line in FAILFAST
mode: {"))
+
+ // `DROPMALFORMED` mode should skip corrupt records
+ // For `PERMISSIVE` mode, it is tested in "Corrupt records" test.
+ val jsonDFOne = sqlContext.read
+ .option("mode", "DROPMALFORMED")
+ .json(corruptRecords)
+ checkAnswer(
+ jsonDFOne,
+ Row("str_a_4", "str_b_4", "str_c_4") :: Nil
+ )
+ assert(jsonDFOne.schema === schemaOne)
+
+ val jsonDFTwo = sqlContext.read
+ .option("mode", "DROPMALFORMED")
+ .schema(schemaTwo)
+ .json(corruptRecords)
+ checkAnswer(
+ jsonDFTwo,
+ Row("str_a_4") :: Nil)
+ assert(jsonDFTwo.schema === schemaTwo)
+ }
+
test("Corrupt records") {
--- End diff --
we can change this to: "Corrupt records: PERMISSIVE mode"
---
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]