Skip to content

Commit 6a4cbb3

Browse files
committed
temp
1 parent 56ded53 commit 6a4cbb3

File tree

1 file changed

+8
-0
lines changed

1 file changed

+8
-0
lines changed

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

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -292,12 +292,20 @@ case class UnixTimestamp(left: Expression, right: Expression)
292292

293293
override def dataType: DataType = LongType
294294

295+
lazy val constFormat: String = right.eval().asInstanceOf[UTF8String].toString
295296
override def nullSafeEval(time: Any, format: Any): Any = {
296297
left.dataType match {
297298
case DateType =>
298299
DateTimeUtils.daysToMillis(time.asInstanceOf[Int]) / 1000L
299300
case TimestampType =>
300301
time.asInstanceOf[Long] / 1000000L
302+
case StringType if right.foldable =>
303+
if (constFormat != null) {
304+
val sdf = new SimpleDateFormat(constFormat)
305+
Try(sdf.parse(time.asInstanceOf[UTF8String].toString).getTime / 1000L).getOrElse(null)
306+
} else {
307+
null
308+
}
301309
case StringType =>
302310
val formatString = format.asInstanceOf[UTF8String].toString
303311
val sdf = new SimpleDateFormat(formatString)

0 commit comments

Comments
 (0)