MaxGekk opened a new pull request, #56355:
URL: https://github.com/apache/spark/pull/56355

   ### What changes were proposed in this pull request?
   
   This PR makes the Types Framework (`TypeApiOps`) the single integration 
point for nanosecond timestamp `CAST(... AS STRING)`, for both the interpreted 
and codegen paths, with no change to the rendered string.
   
   Specifically:
   
   - `TypeApiOps` gains a zone-aware formatting hook: `format(v, zoneId)` and 
`formatUTF8(v, zoneId)`, both defaulting to the existing zone-less `format(v)` 
so zone-independent framework types (e.g. `TimeType`) are unaffected.
   - `TimestampNTZNanosTypeApiOps` / `TimestampLTZNanosTypeApiOps` implement 
the hook: NTZ is zone-independent (UTC `formatWithoutTimeZoneNanos`); LTZ 
renders in the session zone via `formatNanos`. The zone-less callers (EXPLAIN, 
SQL-literal `toSQLValue`) now format NTZ directly, while LTZ without a session 
zone keeps raising `UNSUPPORTED_FEATURE.TIMESTAMP_NANOS_TO_STRING`.
   - `ToStringBase` no longer bypasses the framework: the interpreted path 
threads the session `zoneId` into `formatUTF8(v, zoneId)` for the nanos types, 
and the codegen path emits a runtime call into the ops reference object instead 
of inlining `formatNanos` / `formatWithoutTimeZoneNanos`.
   
   The microsecond timestamp types (`TIMESTAMP` / `TIMESTAMP_NTZ`) remain 
handled inline in `ToStringBase` and are out of scope.
   
   ### Why are the changes needed?
   
   [SPARK-57256](https://issues.apache.org/jira/browse/SPARK-57256) implemented 
nanosecond cast-to-string inline in `ToStringBase`, deliberately bypassing the 
framework because the zone-less `TypeApiOps.format(v)` cannot render LTZ in the 
session time zone. That left nanos cast-to-string as a one-off integration 
outside the framework, inconsistent with the SPIP direction 
([SPARK-56822](https://issues.apache.org/jira/browse/SPARK-56822)) of wiring 
the new types through the centralized `TypeOps` / `TypeApiOps`. This PR closes 
that gap.
   
   ### Does this PR introduce _any_ user-facing change?
   
   No. This is a refactor; the rendered string output is unchanged (zone-aware 
LTZ, zone-independent NTZ, precision flooring, trailing-zero trimming).
   
   ### How was this patch tested?
   
   - Updated `TimestampNanosTypeOpsSuite` to cover the new zone-aware hook (NTZ 
renders zone-independently, LTZ renders in the session zone and still raises 
when zone-less), exercising precision flooring.
   - Existing `CastWithAnsiOnSuite`, `CastWithAnsiOffSuite`, 
`ToPrettyStringSuite`, and `TimestampNanosRowSuite` stay green unchanged (275 
tests pass).
   
   ### Was this patch authored or co-authored using generative AI tooling?
   
   Generated-by: Cursor (Claude Opus 4.8)


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