MaxGekk commented on code in PR #56355:
URL: https://github.com/apache/spark/pull/56355#discussion_r3370012218
##########
sql/api/src/main/scala/org/apache/spark/sql/types/ops/TimestampNanosTypeApiOps.scala:
##########
@@ -99,6 +112,19 @@ class TimestampNTZNanosTypeApiOps(val t:
TimestampNTZNanosType) extends Timestam
class TimestampLTZNanosTypeApiOps(val t: TimestampLTZNanosType) extends
TimestampNanosTypeApiOps {
override def dataType: TimestampLTZNanosType = t
override protected def sqlTypeName: String = "TIMESTAMP_LTZ"
+ override protected def precision: Int = t.precision
+
+ // Zone-less callers (EXPLAIN, SQL-literal) have no session zone to render
LTZ in, so they still
+ // raise rather than guessing a default.
+ override def format(v: Any): String =
+ throw DataTypeErrors.cannotConvertNanosTimestampToStringError(dataType)
+
+ // LTZ rendering depends on the session time zone. The fraction formatter
has its own internal
+ // cache, so build it per call rather than caching it here.
+ override def format(v: Any, zoneId: ZoneId): String = {
+ val formatter = TimestampFormatter.getFractionFormatter(zoneId)
Review Comment:
Good catch, fixed. `TimestampLTZNanosTypeApiOps` now takes the `ZoneId` as a
constructor parameter and holds the fraction formatter in a `@transient private
lazy val`, exactly like NTZ, so it is built once per ops instance (once per
cast, per task) rather than per row. The zone is threaded in centrally via
`TypeApiOps.apply(dt, zoneId)` (by-name, defaulting to the session-local time
zone), and `CAST` passes its resolved zone. Done in cb0a03d9924.
--
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]