Skip to content

Commit 2d24a52

Browse files
committed
Simplify nullable logic
1 parent 8465ad4 commit 2d24a52

File tree

1 file changed

+2
-3
lines changed

1 file changed

+2
-3
lines changed

src/main/scala/com/databricks/spark/csv/util/TypeCast.scala

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,9 +36,7 @@ object TypeCast {
3636
* @param castType SparkSQL type
3737
*/
3838
private[csv] def castTo(datum: String, castType: DataType, nullable: Boolean = true): Any = {
39-
if (castType.isInstanceOf[StringType]){
40-
datum
41-
} else if (nullable && datum == ""){
39+
if (datum == "" && nullable && !castType.isInstanceOf[StringType]){
4240
null
4341
} else {
4442
castType match {
@@ -54,6 +52,7 @@ object TypeCast {
5452
case _: TimestampType => Timestamp.valueOf(datum)
5553
// TODO(hossein): would be good to support other common date formats
5654
case _: DateType => Date.valueOf(datum)
55+
case _: StringType => datum
5756
case _ => throw new RuntimeException(s"Unsupported type: ${castType.typeName}")
5857
}
5958
}

0 commit comments

Comments
 (0)