Skip to content

Commit 8465ad4

Browse files
committed
Add tests for casts
1 parent f292cc5 commit 8465ad4

File tree

1 file changed

+15
-1
lines changed

1 file changed

+15
-1
lines changed

src/test/scala/com/databricks/spark/csv/util/TypeCastSuite.scala

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,11 @@
1616
package com.databricks.spark.csv.util
1717

1818
import java.math.BigDecimal
19+
import java.sql.{Date, Timestamp}
1920

2021
import org.scalatest.FunSuite
2122

22-
import org.apache.spark.sql.types.{StringType, IntegerType, DecimalType}
23+
import org.apache.spark.sql.types._
2324

2425
class TypeCastSuite extends FunSuite {
2526

@@ -72,4 +73,17 @@ class TypeCastSuite extends FunSuite {
7273
}
7374
assert(exception.getMessage.contains("For input string: \"\""))
7475
}
76+
77+
test("Types are cast correctly"){
78+
assert(TypeCast.castTo("10", ByteType) == 10)
79+
assert(TypeCast.castTo("10", ShortType) == 10)
80+
assert(TypeCast.castTo("10", IntegerType) == 10)
81+
assert(TypeCast.castTo("10", LongType) == 10)
82+
assert(TypeCast.castTo("1.00", FloatType) == 1.0)
83+
assert(TypeCast.castTo("1.00", DoubleType) == 1.0)
84+
assert(TypeCast.castTo("true", BooleanType) == true)
85+
val timestamp = "2015-01-01 00:00:00"
86+
assert(TypeCast.castTo(timestamp, TimestampType) == Timestamp.valueOf(timestamp))
87+
assert(TypeCast.castTo("2015-01-01", DateType) == Date.valueOf("2015-01-01"))
88+
}
7589
}

0 commit comments

Comments
 (0)