Github user gatorsmile commented on a diff in the pull request:
https://github.com/apache/spark/pull/18200#discussion_r120805631
--- Diff:
sql/core/src/test/scala/org/apache/spark/sql/execution/datasources/csv/CSVSuite.scala
---
@@ -1174,4 +1174,12 @@ class CSVSuite extends QueryTest with
SharedSQLContext with SQLTestUtils {
}
}
}
+
+ test("SPARK-20978: Set null for malformed column when the number of
tokens is less than schema") {
+ val df = spark.read
+ .schema("a string, b string, unparsed string")
+ .option("columnNameOfCorruptRecord", "unparsed")
+ .csv(Seq("a").toDS())
+ checkAnswer(df, Row("a", null, null))
--- End diff --
Without this PR, you can try this example.
```Scala
val corruptCVSRecords: Dataset[String] =
spark.createDataset(spark.sparkContext.parallelize(
"""1997, "b"""" ::
"""2015""" :: Nil))(Encoders.STRING)
val df1 = spark.read
.schema("col1 int, col2 String, __corrupted_column_name string")
.option("columnNameOfCorruptRecord", "__corrupted_column_name")
.option("mode", PermissiveMode.name)
.csv(corruptCVSRecords)
df1.show()
```
The output result of `Permissive` mode also treats the records with less
columns as corrupted.
```
+----+----+-----------------------+
|col1|col2|__corrupted_column_name|
+----+----+-----------------------+
|1997| "b"| null|
|2015|null| 2015|
+----+----+-----------------------+
```
---
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]