@@ -126,19 +126,18 @@ case class ReplaceCurrentLike(catalogManager: CatalogManager) extends Rule[Logic
126126 * if the input strings are foldable.
127127 */
128128object SpecialDatetimeValues extends Rule [LogicalPlan ] {
129+ private val conv = Map [DataType , (String , java.time.ZoneId ) => Option [Any ]](
130+ DateType -> convertSpecialDate,
131+ TimestampType -> convertSpecialTimestamp,
132+ TimestampNTZType -> ((s : String , _ : java.time.ZoneId ) => convertSpecialTimestampNTZ(s))
133+ )
129134 def apply (plan : LogicalPlan ): LogicalPlan = {
130135 plan.transformAllExpressionsWithPruning(_.containsPattern(CAST )) {
131- case cast @ Cast (e, DateType , _, _) if e.foldable && e.dataType == StringType =>
132- convertSpecialDate(e.eval().toString, cast.zoneId)
133- .map(Literal (_, DateType ))
134- .getOrElse(cast)
135- case cast @ Cast (e, TimestampType , _, _) if e.foldable && e.dataType == StringType =>
136- convertSpecialTimestamp(e.eval().toString, cast.zoneId)
137- .map(Literal (_, TimestampType ))
138- .getOrElse(cast)
139- case cast @ Cast (e, TimestampNTZType , _, _) if e.foldable && e.dataType == StringType =>
140- convertSpecialTimestampNTZ(e.eval().toString)
141- .map(Literal (_, TimestampNTZType ))
136+ case cast @ Cast (e, dt @ (DateType | TimestampType | TimestampNTZType ), _, _)
137+ if e.foldable && e.dataType == StringType =>
138+ Option (e.eval())
139+ .flatMap(s => conv(dt)(s.toString, cast.zoneId))
140+ .map(Literal (_, dt))
142141 .getOrElse(cast)
143142 }
144143 }
0 commit comments