Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
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
Original file line number Diff line number Diff line change
Expand Up @@ -416,7 +416,7 @@ case class Cast(child: Expression, dataType: DataType) extends UnaryExpression w
}

private[this] def cast(from: DataType, to: DataType): Any => Any = to match {
case dt if dt == child.dataType => identity[Any]
case dt if dt == from => identity[Any]
case StringType => castToString(from)
case BinaryType => castToBinary(from)
case DateType => castToDate(from)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -727,6 +727,16 @@ class CastSuite extends SparkFunSuite with ExpressionEvalHelper {
}
}

test("cast struct with a timestamp field") {
val originalSchema = new StructType().add("tsField", TimestampType, nullable = false)
// nine out of ten times I'm casting a struct, it's to normalize its fields nullability
val targetSchema = new StructType().add("tsField", TimestampType, nullable = true)

val inp = Literal.create(InternalRow(0L), originalSchema)
val expected = InternalRow(0L)
checkEvaluation(cast(inp, targetSchema), expected)
}

test("complex casting") {
val complex = Literal.create(
Row(
Expand Down