Github user cloud-fan commented on a diff in the pull request:
https://github.com/apache/spark/pull/17023#discussion_r102540297
--- Diff:
sql/core/src/test/scala/org/apache/spark/sql/execution/datasources/json/JsonSuite.scala
---
@@ -1944,4 +1944,37 @@ class JsonSuite extends QueryTest with
SharedSQLContext with TestJsonData {
assert(exceptionTwo.getMessage.contains("Malformed line in FAILFAST
mode"))
}
}
+
+ test("Throw an exception if a `columnNameOfCorruptRecord` field violates
requirements") {
+ val columnNameOfCorruptRecord = "_unparsed"
+ val schema = StructType(
+ StructField(columnNameOfCorruptRecord, IntegerType, true) ::
+ StructField("a", StringType, true) ::
+ StructField("b", StringType, true) ::
+ StructField("c", StringType, true) :: Nil)
+ val errMsg = intercept[AnalysisException] {
+ spark.read
+ .option("mode", "PERMISSIVE")
+ .option("columnNameOfCorruptRecord", columnNameOfCorruptRecord)
+ .schema(schema)
+ .json(corruptRecords)
+ }.getMessage
+ assert(errMsg.startsWith("The field for corrupt records must be string
type and nullable"))
+
+ withTempPath { dir =>
+ val path = dir.getCanonicalPath
+ spark.createDataFrame(
+ corruptRecords.map(Row(_)), new StructType().add("value",
StringType)
--- End diff --
`corruptRecords.toDF("value")`?
---
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]