HyukjinKwon commented on code in PR #36401:
URL: https://github.com/apache/spark/pull/36401#discussion_r861713433
##########
sql/core/src/test/scala/org/apache/spark/sql/CsvFunctionsSuite.scala:
##########
@@ -79,6 +79,108 @@ class CsvFunctionsSuite extends QueryTest with
SharedSparkSession {
}
}
+ test("from_csv with option (escape)") {
+ val df = Seq("\"#\"\"").toDS()
+ val schema = new StructType().add("str", StringType)
+ val options = Map("escape" -> "#")
+
+ checkAnswer(
+ df.select(from_csv($"value", schema, options)),
+ Row(Row("\"")))
+ }
+
+ test("from_csv with option (comment)") {
+ val df = Seq("# This line is commented").toDS()
+ val schema = new StructType().add("str", StringType)
+ val options = Map("comment" -> "#")
+
+ checkAnswer(
+ df.select(from_csv($"value", schema, options)),
+ Row(Row(null)))
+ }
+
+ test("from_csv with option (ignoreLeadingWhiteSpace)") {
+ val df = Seq(" a ").toDS()
+ val schema = new StructType().add("str", StringType)
+ val options = Map("ignoreLeadingWhiteSpace" -> "true")
+
+ checkAnswer(
+ df.select(from_csv($"value", schema, options)),
+ Row(Row("a ")))
+ }
+
+ test("from_csv with option (ignoreTrailingWhiteSpace)") {
+ val df = Seq(" a ").toDS()
+ val schema = new StructType().add("str", StringType)
+ val options = Map("ignoreTrailingWhiteSpace" -> "true")
+
+ checkAnswer(
+ df.select(from_csv($"value", schema, options)),
+ Row(Row(" a")))
+ }
+
+ test("from_csv with option (nullValue)") {
+ val df = Seq("-").toDS()
+ val schema = new StructType().add("str", StringType)
+ val options = Map("nullValue" -> "-")
+
+ checkAnswer(
+ df.select(from_csv($"value", schema, options)),
+ Row(Row(null)))
+ }
+
+ test("from_csv with option (nanValue)") {
+ val df = Seq("#").toDS()
+ val schema = new StructType().add("float", FloatType)
+ val options = Map("nanValue" -> "#")
+
+ checkAnswer(
+ df.select(from_csv($"value", schema, options)),
+ Row(Row(Float.NaN)))
+ }
+
+ test("from_csv with option (positiveInf)") {
+ val df = Seq("#").toDS()
+ val schema = new StructType().add("float", FloatType)
+ val options = Map("positiveInf" -> "#")
+
+ checkAnswer(
+ df.select(from_csv($"value", schema, options)),
+ Row(Row(Double.PositiveInfinity)))
+ }
+
+ test("from_csv with option (negativeInf)") {
+ val df = Seq("#").toDS()
+ val schema = new StructType().add("float", FloatType)
+ val options = Map("negativeInf" -> "#")
+
+ checkAnswer(
+ df.select(from_csv($"value", schema, options)),
+ Row(Row(Double.NegativeInfinity)))
+ }
+
+ test("from_csv with option (dateFormat)") {
+ val df = Seq("26/08/2015").toDS()
+ val schema = new StructType().add("time", DateType)
+ val options = Map("dateFormat" -> "dd/MM/yyyy")
+
+ checkAnswer(
+ df.select(from_csv($"value", schema, options)),
+ Row(Row(java.sql.Date.valueOf("2015-08-26"))))
+ }
+
+ test("from_csv with option (maxCharsPerColumn)") {
+ val df = Seq("12345").toDS()
+ val schema = new StructType().add("str", StringType)
+ val options = Map("maxCharsPerColumn" -> "2")
+
+ val exception = intercept[SparkException] {
Review Comment:
Can we also test the root cause exception? e.g., `TextParsingException`. You
can get it via `e.getCause`.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]