@@ -23,14 +23,13 @@ import java.time.temporal.IsoFields
2323import java .util .{Locale , TimeZone }
2424
2525import scala .util .control .NonFatal
26-
2726import org .apache .commons .text .StringEscapeUtils
28-
2927import org .apache .spark .sql .AnalysisException
3028import org .apache .spark .sql .catalyst .InternalRow
3129import org .apache .spark .sql .catalyst .expressions .codegen ._
3230import org .apache .spark .sql .catalyst .expressions .codegen .Block ._
33- import org .apache .spark .sql .catalyst .util .{DateTimeUtils , TimestampFormatter }
31+ import org .apache .spark .sql .catalyst .util .LegacyDateFormats .SIMPLE_DATE_FORMAT
32+ import org .apache .spark .sql .catalyst .util .{DateTimeUtils , LegacyDateFormats , TimestampFormatter }
3433import org .apache .spark .sql .catalyst .util .DateTimeConstants ._
3534import org .apache .spark .sql .catalyst .util .DateTimeUtils ._
3635import org .apache .spark .sql .types ._
@@ -622,13 +621,15 @@ case class DateFormatClass(left: Expression, right: Expression, timeZoneId: Opti
622621
623622 @ transient private lazy val formatter : Option [TimestampFormatter ] = {
624623 if (right.foldable) {
625- Option (right.eval()).map(format => TimestampFormatter (format.toString, zoneId))
624+ Option (right.eval()).map { format =>
625+ TimestampFormatter (format.toString, zoneId, legacyFormat = SIMPLE_DATE_FORMAT )
626+ }
626627 } else None
627628 }
628629
629630 override protected def nullSafeEval (timestamp : Any , format : Any ): Any = {
630631 val tf = if (formatter.isEmpty) {
631- TimestampFormatter .withStrongLegacy (format.toString, zoneId)
632+ TimestampFormatter (format.toString, zoneId, legacyFormat = SIMPLE_DATE_FORMAT )
632633 } else {
633634 formatter.get
634635 }
@@ -643,10 +644,14 @@ case class DateFormatClass(left: Expression, right: Expression, timeZoneId: Opti
643644 })
644645 }.getOrElse {
645646 val tf = TimestampFormatter .getClass.getName.stripSuffix(" $" )
647+ val ldf = LegacyDateFormats .getClass.getName.stripSuffix(" $" )
646648 val zid = ctx.addReferenceObj(" zoneId" , zoneId, classOf [ZoneId ].getName)
647649 defineCodeGen(ctx, ev, (timestamp, format) => {
648- s """ UTF8String.fromString( $tf$$ .MODULE $$ .withStrongLegacy( $format.toString(), $zid)
649- .format( $timestamp)) """
650+ s """ |UTF8String.fromString( $tf$$ .MODULE $$ .apply(
651+ | $format.toString(),
652+ | $zid,
653+ | $ldf$$ .MODULE $$ .SIMPLE_DATE_FORMAT())
654+ |.format( $timestamp)) """ .stripMargin
650655 })
651656 }
652657 }
@@ -758,7 +763,7 @@ abstract class ToTimestamp
758763 private lazy val constFormat : UTF8String = right.eval().asInstanceOf [UTF8String ]
759764 private lazy val formatter : TimestampFormatter =
760765 try {
761- TimestampFormatter .withStrongLegacy (constFormat.toString, zoneId)
766+ TimestampFormatter (constFormat.toString, zoneId, legacyFormat = SIMPLE_DATE_FORMAT )
762767 } catch {
763768 case NonFatal (_) => null
764769 }
@@ -791,8 +796,8 @@ abstract class ToTimestamp
791796 } else {
792797 val formatString = f.asInstanceOf [UTF8String ].toString
793798 try {
794- TimestampFormatter .withStrongLegacy (formatString, zoneId).parse(
795- t.asInstanceOf [UTF8String ].toString) / downScaleFactor
799+ TimestampFormatter (formatString, zoneId, legacyFormat = SIMPLE_DATE_FORMAT )
800+ .parse( t.asInstanceOf [UTF8String ].toString) / downScaleFactor
796801 } catch {
797802 case NonFatal (_) => null
798803 }
@@ -832,11 +837,15 @@ abstract class ToTimestamp
832837 case StringType =>
833838 val zid = ctx.addReferenceObj(" zoneId" , zoneId, classOf [ZoneId ].getName)
834839 val tf = TimestampFormatter .getClass.getName.stripSuffix(" $" )
840+ val ldf = LegacyDateFormats .getClass.getName.stripSuffix(" $" )
835841 nullSafeCodeGen(ctx, ev, (string, format) => {
836842 s """
837843 try {
838- ${ev.value} = $tf$$ .MODULE $$ .withStrongLegacy( $format.toString(), $zid)
839- .parse( $string.toString()) / $downScaleFactor;
844+ ${ev.value} = $tf$$ .MODULE $$ .apply(
845+ $format.toString(),
846+ $zid,
847+ $ldf$$ .MODULE $$ .SIMPLE_DATE_FORMAT())
848+ .parse( $string.toString()) / $downScaleFactor;
840849 } catch (java.lang.IllegalArgumentException e) {
841850 ${ev.isNull} = true;
842851 } catch (java.text.ParseException e) {
@@ -921,7 +930,7 @@ case class FromUnixTime(sec: Expression, format: Expression, timeZoneId: Option[
921930 private lazy val constFormat : UTF8String = right.eval().asInstanceOf [UTF8String ]
922931 private lazy val formatter : TimestampFormatter =
923932 try {
924- TimestampFormatter .withStrongLegacy (constFormat.toString, zoneId)
933+ TimestampFormatter (constFormat.toString, zoneId, legacyFormat = SIMPLE_DATE_FORMAT )
925934 } catch {
926935 case NonFatal (_) => null
927936 }
@@ -947,8 +956,9 @@ case class FromUnixTime(sec: Expression, format: Expression, timeZoneId: Option[
947956 null
948957 } else {
949958 try {
950- UTF8String .fromString(TimestampFormatter .withStrongLegacy(f.toString, zoneId)
951- .format(time.asInstanceOf [Long ] * MICROS_PER_SECOND ))
959+ UTF8String .fromString(
960+ TimestampFormatter (f.toString, zoneId, legacyFormat = SIMPLE_DATE_FORMAT )
961+ .format(time.asInstanceOf [Long ] * MICROS_PER_SECOND ))
952962 } catch {
953963 case NonFatal (_) => null
954964 }
@@ -980,11 +990,13 @@ case class FromUnixTime(sec: Expression, format: Expression, timeZoneId: Option[
980990 } else {
981991 val zid = ctx.addReferenceObj(" zoneId" , zoneId, classOf [ZoneId ].getName)
982992 val tf = TimestampFormatter .getClass.getName.stripSuffix(" $" )
993+ val ldf = LegacyDateFormats .getClass.getName.stripSuffix(" $" )
983994 nullSafeCodeGen(ctx, ev, (seconds, f) => {
984995 s """
985996 try {
986- ${ev.value} = UTF8String.fromString( $tf$$ .MODULE $$ .withStrongLegacy( $f.toString(), $zid).
987- format( $seconds * 1000000L));
997+ ${ev.value} = UTF8String.fromString(
998+ $tf$$ .MODULE $$ .apply( $f.toString(), $zid, $ldf$$ .MODULE $$ .SIMPLE_DATE_FORMAT())
999+ .format( $seconds * 1000000L));
9881000 } catch (java.lang.IllegalArgumentException e) {
9891001 ${ev.isNull} = true;
9901002 } """
0 commit comments