Skip to content

Commit 85a290e

Browse files
committed
Bug fix: copy formatter
1 parent 5ab324f commit 85a290e

File tree

1 file changed

+9
-7
lines changed

1 file changed

+9
-7
lines changed

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

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -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

Comments
 (0)