Skip to content
Closed
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
add test cases
  • Loading branch information
gengliangwang committed Feb 20, 2021
commit 39048ab27cb9dfd6f6110c3cc221fa304e188cc4
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,12 @@ class AnsiTypeCoercionSuite extends AnalysisTest {
s"Failed to cast String literal to $to")
}

private def shouldNotCastStringLiteral(to: AbstractDataType): Unit = {
val input = Literal("123")
val castResult = AnsiTypeCoercion.implicitCast(input, to)
assert(castResult.isEmpty, s"Should not be able to cast String literal to $to")
}

private def shouldNotCastStringInput(to: AbstractDataType): Unit = {
val input = AttributeReference("s", StringType)()
val castResult = AnsiTypeCoercion.implicitCast(input, to)
Expand Down Expand Up @@ -219,8 +225,7 @@ class AnsiTypeCoercionSuite extends AnalysisTest {
}

test("implicit type cast - unfoldable StringType") {
val nonCastableTypes =
complexTypes ++ Seq(BooleanType, NullType, CalendarIntervalType)
val nonCastableTypes = allTypes.filterNot(_ == StringType)
nonCastableTypes.foreach { dt =>
shouldNotCastStringInput(dt)
}
Expand All @@ -230,10 +235,13 @@ class AnsiTypeCoercionSuite extends AnalysisTest {

test("implicit type cast - foldable StringType") {
val castableTypes =
numericTypes ++ datetimeTypes ++ Seq(BinaryType)
numericTypes ++ datetimeTypes ++ Seq(BinaryType, StringType)
castableTypes.foreach { dt =>
shouldCastStringLiteral(dt, dt)
}
allTypes.filterNot(castableTypes.contains).foreach { dt =>
shouldNotCastStringLiteral(dt)
}
shouldCastStringLiteral(DecimalType, DecimalType.defaultConcreteType)
shouldCastStringLiteral(NumericType, DoubleType)
}
Expand Down