Skip to content
Closed
Show file tree
Hide file tree
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
SPARK-16791_cast_struct_with_timestamp_field_fails: fix style comment…
…s from reviewers.
  • Loading branch information
eyal farago committed Jul 29, 2016
commit a3b456c96eb559db553b746c17580e9218e109f8
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 == from => 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 @@ -728,16 +728,16 @@ class CastSuite extends SparkFunSuite with ExpressionEvalHelper {
}

test("cast struct with a timestamp field") {
val origSchema = StructType(
Seq(StructField( "tsField", TimestampType, false ))
val originalSchema = StructType(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we usually use new StructType().add("name", TimestampType, nullable = false)

Seq(StructField( "tsField", TimestampType, nullable = false ))
)
val trgSchema = StructType(
val targetSchema = StructType(
// nine out of ten times I'm casting a struct, it's to normalize its fields nullability
Seq(StructField( "tsField", TimestampType, true ))
Seq(StructField( "tsField", TimestampType, nullable = true ))
)
val inp = Literal.create(InternalRow(0L), origSchema)
val inp = Literal.create(InternalRow(0L), originalSchema)
val expected = InternalRow(0L)
checkEvaluation( Cast(inp, trgSchema), expected)
checkEvaluation(cast(inp, targetSchema), expected )
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

and remove the extra space here too

}

test("complex casting") {
Expand Down