Github user HyukjinKwon commented on a diff in the pull request:
https://github.com/apache/spark/pull/14118#discussion_r73664188
--- Diff:
sql/core/src/test/scala/org/apache/spark/sql/execution/datasources/csv/CSVTypeCastSuite.scala
---
@@ -68,16 +68,48 @@ class CSVTypeCastSuite extends SparkFunSuite {
}
test("Nullable types are handled") {
- assert(CSVTypeCast.castTo("", IntegerType, nullable = true,
CSVOptions()) == null)
+ assertNull(
+ CSVTypeCast.castTo("-", ByteType, nullable = true,
CSVOptions("nullValue", "-")))
+ assertNull(
+ CSVTypeCast.castTo("-", ShortType, nullable = true,
CSVOptions("nullValue", "-")))
+ assertNull(
+ CSVTypeCast.castTo("-", IntegerType, nullable = true,
CSVOptions("nullValue", "-")))
+ assertNull(
+ CSVTypeCast.castTo("-", LongType, nullable = true,
CSVOptions("nullValue", "-")))
+ assertNull(
+ CSVTypeCast.castTo("-", FloatType, nullable = true,
CSVOptions("nullValue", "-")))
+ assertNull(
+ CSVTypeCast.castTo("-", DoubleType, nullable = true,
CSVOptions("nullValue", "-")))
+ assertNull(
+ CSVTypeCast.castTo("-", BooleanType, nullable = true,
CSVOptions("nullValue", "-")))
+ assertNull(
+ CSVTypeCast.castTo("-", DecimalType.DoubleDecimal, true,
CSVOptions("nullValue", "-")))
+ assertNull(
+ CSVTypeCast.castTo("-", TimestampType, nullable = true,
CSVOptions("nullValue", "-")))
+ assertNull(
+ CSVTypeCast.castTo("-", DateType, nullable = true,
CSVOptions("nullValue", "-")))
+ assertNull(
+ CSVTypeCast.castTo("-", StringType, nullable = true,
CSVOptions("nullValue", "-")))
}
- test("String type should always return the same as the input") {
+ test("String type should also respect `nullValue`") {
assert(
CSVTypeCast.castTo("", StringType, nullable = true, CSVOptions()) ==
- UTF8String.fromString(""))
+ null)
assert(
CSVTypeCast.castTo("", StringType, nullable = false, CSVOptions()) ==
UTF8String.fromString(""))
+
+ assert(
+ CSVTypeCast.castTo("", StringType, nullable = true,
CSVOptions("nullValue", "null")) ==
+ UTF8String.fromString(""))
+ assert(
+ CSVTypeCast.castTo("", StringType, nullable = false,
CSVOptions("nullValue", "null")) ==
+ UTF8String.fromString(""))
+
+ assert(
+ CSVTypeCast.castTo(null, StringType, nullable = true,
CSVOptions("nullValue", "null")) ==
+ null)
--- End diff --
Maybe we can use `assertNull` as you just did above?
---
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]