uros-db commented on code in PR #56355:
URL: https://github.com/apache/spark/pull/56355#discussion_r3372325338


##########
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/expressions/ToStringBase.scala:
##########
@@ -246,18 +238,17 @@ trait ToStringBase { self: UnaryExpression with 
TimeZoneAwareExpression =>
           ctx.addReferenceObj("timestampNTZFormatter", timestampNTZFormatter),
           timestampNTZFormatter.getClass)
         (c, evPrim) => code"$evPrim = UTF8String.fromString($tf.format($c));"
-      case t: TimestampLTZNanosType =>
-        val tf = JavaCode.global(
-          ctx.addReferenceObj("timestampFormatter", timestampFormatter),
-          timestampFormatter.getClass)
-        (c, evPrim) =>
-          code"$evPrim = UTF8String.fromString($tf.formatNanos($c, 
${t.precision}));"
-      case t: TimestampNTZNanosType =>
-        val tf = JavaCode.global(
-          ctx.addReferenceObj("timestampNTZFormatter", timestampNTZFormatter),
-          timestampNTZFormatter.getClass)
-        (c, evPrim) =>
-          code"$evPrim = 
UTF8String.fromString($tf.formatWithoutTimeZoneNanos($c, ${t.precision}));"
+      case _: TimestampNTZNanosType | _: TimestampLTZNanosType =>
+        // Route nanosecond timestamp cast-to-string through the Types 
Framework: emit a runtime
+        // call into the ops reference object. The cast's session zone is 
threaded into the lookup
+        // so LTZ carries it; NTZ is zone-independent (SPARK-57285).
+        val ops = TypeApiOps(from, zoneId).get

Review Comment:
   Before this PR, castToString routed nanos unconditionally to 
castToStringDefault, which formatted correctly regardless of the framework 
flag, so this is a (narrow) behavior regression introduced here. I'd suggest 
one of:
   - add the symmetric guard on TYPES_FRAMEWORK_ENABLED (can't disable while 
nanos enabled), or
   - replace .get with a getOrElse that throws a clear internal error, so a 
broken-invariant state fails loudly rather than with NoSuchElementException / 
garbage output.



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