Skip to content
Snippets Groups Projects
Commit 338a98d6 authored by eyal farago's avatar eyal farago Committed by Wenchen Fan
Browse files

[SPARK-16791][SQL] cast struct with timestamp field fails

## What changes were proposed in this pull request?
a failing test case + fix to SPARK-16791 (https://issues.apache.org/jira/browse/SPARK-16791)

## How was this patch tested?
added a failing test case to CastSuit, then fixed the Cast code and rerun the entire CastSuit

Author: eyal farago <eyal farago>
Author: Eyal Farago <eyal.farago@actimize.com>

Closes #14400 from eyalfa/SPARK-16791_cast_struct_with_timestamp_field_fails.
parent f93ad4fe
No related branches found
No related tags found
No related merge requests found
......@@ -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)
......
......@@ -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(
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment