@@ -580,7 +580,11 @@ case class WeekOfYear(child: Expression) extends UnaryExpression with ImplicitCa
580580 """ ,
581581 since = " 1.5.0" )
582582// scalastyle:on line.size.limit
583- case class DateFormatClass (left : Expression , right : Expression , timeZoneId : Option [String ] = None )
583+ case class DateFormatClass (
584+ left : Expression ,
585+ right : Expression ,
586+ timeZoneId : Option [String ] = None ,
587+ formatter : Option [TimestampFormatter ] = None )
584588 extends BinaryExpression with TimeZoneAwareExpression with ImplicitCastInputTypes {
585589
586590 def this (left : Expression , right : Expression ) = this (left, right, None )
@@ -589,17 +593,15 @@ case class DateFormatClass(left: Expression, right: Expression, timeZoneId: Opti
589593
590594 override def inputTypes : Seq [AbstractDataType ] = Seq (TimestampType , StringType )
591595
592- var formatter : Option [TimestampFormatter ] = None
593-
594596 override def withTimeZone (timeZoneId : String ): TimeZoneAwareExpression = {
595- if (formatter.isEmpty && right.foldable) {
597+ val tf = if (formatter.isEmpty && right.foldable) {
596598 val format = right.eval().toString
597- formatter = Some (TimestampFormatter (
599+ Some (TimestampFormatter (
598600 format,
599601 DateTimeUtils .getZoneId(timeZoneId),
600602 Locale .US ))
601- }
602- copy(timeZoneId = Option (timeZoneId))
603+ } else None
604+ copy(formatter = tf, timeZoneId = Option (timeZoneId))
603605 }
604606
605607 override protected def nullSafeEval (timestamp : Any , format : Any ): Any = {
0 commit comments