maropu commented on a change in pull request #25782: [SPARK-29074][SQL] 
Optimize `date_format` for foldable `fmt`
URL: https://github.com/apache/spark/pull/25782#discussion_r324204543
 
 

 ##########
 File path: 
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/expressions/datetimeExpressions.scala
 ##########
 @@ -589,22 +589,43 @@ case class DateFormatClass(left: Expression, right: 
Expression, timeZoneId: Opti
 
   override def inputTypes: Seq[AbstractDataType] = Seq(TimestampType, 
StringType)
 
-  override def withTimeZone(timeZoneId: String): TimeZoneAwareExpression =
+  var formatter: Option[TimestampFormatter] = None
 
 Review comment:
   can we do it like this?
   ```
   
     lazy val formatter = if (right.foldable) {
       val fmt = right.eval().toString
       val formatter = TimestampFormatter(fmt, zoneId, Locale.US)
       (fmt: Any) => formatter
     } else {
       (fmt: Any) => TimestampFormatter(fmt.toString, zoneId, Locale.US)
     }
   
     override protected def nullSafeEval(timestamp: Any, format: Any): Any = {
       
UTF8String.fromString(formatter(format).format(timestamp.asInstanceOf[Long]))
     }
   ```

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
[email protected]


With regards,
Apache Git Services

---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to