Github user chenghao-intel commented on a diff in the pull request:
https://github.com/apache/spark/pull/2344#discussion_r17704067
--- Diff:
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/expressions/Cast.scala
---
@@ -140,6 +147,39 @@ case class Cast(child: Expression, dataType: DataType)
extends UnaryExpression {
}
}
+ // Converts Timestamp to string according to Hive TimestampWritable
convention
+ private[this] def timestampToDateString(ts: Timestamp): String = {
+ Cast.threadLocalDateFormat.get.format(ts)
+ }
+
+ // DateConverter
+ private[this] def castToDate: Any => Any = child.dataType match {
+ case StringType =>
+ buildCast[String](_, s => if (s.contains(" ")) {
+ try castToDate(castToTimestamp(s))
+ catch { case _: java.lang.IllegalArgumentException => null }
+ } else {
+ try Date.valueOf(s) catch { case _:
java.lang.IllegalArgumentException => null }
+ })
+ case TimestampType =>
+ buildCast[Timestamp](_, t => Date.valueOf(timestampToDateString(t)))
+ // TimestampWritable.decimalToDate
+ case _ =>
+ _ => null
+ }
+
+ // Date cannot be cast to long, according to hive
+ private[this] def dateToLong(d: Date) = null
--- End diff --
Throw exception instead? Seems Hive does that.
---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at [email protected] or file a JIRA ticket
with INFRA.
---
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]