Skip to content

Commit ea42053

Browse files
committed
Pass boolean literal for date directly in Cast
1 parent ba6fc7b commit ea42053

File tree

2 files changed

+5
-2
lines changed
  • sql/catalyst/src
    • main/scala/org/apache/spark/sql/catalyst/expressions
    • test/scala/org/apache/spark/sql/catalyst/expressions

2 files changed

+5
-2
lines changed

sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/expressions/Cast.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1068,7 +1068,7 @@ case class Cast(child: Expression, dataType: DataType, timeZoneId: Option[String
10681068
case StringType =>
10691069
val intOpt = ctx.freshVariable("intOpt", classOf[Option[Integer]])
10701070
val zid = getZoneId()
1071-
val sv = ctx.addReferenceObj("supportSpecialValues", supportSpecialValues)
1071+
val sv = supportSpecialValues.toString
10721072
(c, evPrim, evNull) =>
10731073
code"""
10741074
scala.Option<Integer> $intOpt =

sql/catalyst/src/test/scala/org/apache/spark/sql/catalyst/expressions/CastSuite.scala

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1201,13 +1201,16 @@ class CastSuite extends SparkFunSuite with ExpressionEvalHelper {
12011201
}
12021202
}
12031203

1204-
test("cast special timestamp value") {
1204+
test("cast special timestamp and date value") {
12051205
withSQLConf(SQLConf.DIALECT.key -> SQLConf.Dialect.POSTGRESQL.toString) {
12061206
checkEvaluation(cast(Literal("epoch"), TimestampType, Option("UTC")),
12071207
new Timestamp(0))
1208+
checkEvaluation(cast(Literal("epoch"), DateType, Option("UTC")),
1209+
new Date(0))
12081210
}
12091211
withSQLConf(SQLConf.DIALECT.key -> SQLConf.Dialect.SPARK.toString) {
12101212
checkEvaluation(cast(Literal("epoch"), TimestampType, Option("UTC")), null)
1213+
checkEvaluation(cast(Literal("epoch"), DateType, Option("UTC")), null)
12111214
}
12121215
}
12131216
}

0 commit comments

Comments
 (0)