uros-b commented on code in PR #56677:
URL: https://github.com/apache/spark/pull/56677#discussion_r3462891143


##########
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/optimizer/finishAnalysis.scala:
##########
@@ -131,6 +138,22 @@ object ComputeCurrentTime extends Rule[LogicalPlan] {
               Literal.create(
                 DateTimeUtils.microsToDays(currentTimestampMicros, cd.zoneId), 
DateType)
             })
+          // CAST(time AS TIMESTAMP_NTZ(q)) fills the date fields from 
CURRENT_DATE. Rewrite it to
+          // a date+time builder anchored on the same query-stable current 
date literal that
+          // current_date() resolves to, so all references agree within the 
query. The builder's
+          // `replacement` (a StaticInvoke) is emitted directly because 
ReplaceExpressions has
+          // already run earlier in this batch and will not expand a fresh 
RuntimeReplaceable.
+          case c: Cast if Cast.isTimeToTimestampNTZ(c.child.dataType, 
c.dataType) =>
+            val dateLit = currentDates.getOrElseUpdate(c.zoneId, {
+              Literal.create(
+                DateTimeUtils.microsToDays(currentTimestampMicros, c.zoneId), 
DateType)
+            })
+            c.dataType match {
+              case n: TimestampNTZNanosType =>
+                MakeTimestampNTZNanos(dateLit, c.child, 
n.precision).replacement
+              case _ =>

Review Comment:
   In the TIME -> NTZ rewrite, c.dataType match { ... case _ => 
MakeTimestampNTZ(...) } uses a bare case _ => as the micros branch rather than 
case _: TimestampNTZType. This is functionally fine given 
Cast.isTimeToTimestampNTZ gates the case, but a precise case _: 
TimestampNTZType would be more defensive.



-- 
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.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


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

Reply via email to