|
16 | 16 | package com.databricks.spark.csv.util |
17 | 17 |
|
18 | 18 | import java.math.BigDecimal |
| 19 | +import java.sql.{Date, Timestamp} |
19 | 20 |
|
20 | 21 | import org.scalatest.FunSuite |
21 | 22 |
|
22 | | -import org.apache.spark.sql.types.{StringType, IntegerType, DecimalType} |
| 23 | +import org.apache.spark.sql.types._ |
23 | 24 |
|
24 | 25 | class TypeCastSuite extends FunSuite { |
25 | 26 |
|
@@ -72,4 +73,17 @@ class TypeCastSuite extends FunSuite { |
72 | 73 | } |
73 | 74 | assert(exception.getMessage.contains("For input string: \"\"")) |
74 | 75 | } |
| 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 | + } |
75 | 89 | } |
0 commit comments