MaxGekk commented on code in PR #56677:
URL: https://github.com/apache/spark/pull/56677#discussion_r3463047192


##########
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:
   Good call — done in eda86399c5a. The micros branch now matches `case _: 
TimestampNTZType` explicitly, with an `internalError` fallback for the 
(unreachable, since `Cast.isTimeToTimestampNTZ` gates the outer case) other 
branch.



##########
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/expressions/Cast.scala:
##########


Review Comment:
   Fixed in eda86399c5a — `castToTimeCode` now raises the same internal error 
as the interpreted `castToTime` instead of emitting null. The case is 
unreachable for valid casts (`canCast(_, TimeType)` only allows the handled 
source types, and `NullType` is short-circuited earlier in `castInternal` / 
`nullSafeCastFunction`), so this just keeps the two paths consistent and fails 
fast if a future `canCast` arm is added without a matching converter.



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