Skip to content

[WIP][SPARK-57816][SQL] Support nanosecond-precision timestamps in date_format, to_char and to_varchar#57225

Open
stevomitric wants to merge 1 commit into
apache:masterfrom
stevomitric:stevomitric/spark-57816-nanos
Open

[WIP][SPARK-57816][SQL] Support nanosecond-precision timestamps in date_format, to_char and to_varchar#57225
stevomitric wants to merge 1 commit into
apache:masterfrom
stevomitric:stevomitric/spark-57816-nanos

Conversation

@stevomitric

Copy link
Copy Markdown
Contributor

What changes were proposed in this pull request?

Extend DateFormatClass (which backs date_format, to_char and to_varchar) to accept nanosecond-precision timestamps (TIMESTAMP_NTZ(p)/TIMESTAMP_LTZ(p), p in [7, 9]). Both eval and codegen render via the nanosecond-aware TimestampFormatter: NTZ renders its wall clock zone-independently, LTZ renders in the session zone, and sub-precision digits floor to zeros. Also guards SimplifyDateTimeConversions from rewriting a nanosecond child, whose round-trip through microsecond TimestampType would silently truncate.

Why are the changes needed?

Nanosecond input was narrowed to microseconds, so the sub-microsecond digits never reached the formatter.

Does this PR introduce any user-facing change?

Yes. date_format/to_char/to_varchar now render nanosecond timestamps at full precision (preview spark.sql.timestampNanosTypes.enabled).

How was this patch tested?

DateExpressionsSuite, SimplifyDateTimeConversionsSuite, TimestampNanosFunctionsSuiteBase, and timestamp-{ltz,ntz}-nanos.sql golden files.

Was this patch authored or co-authored using generative AI tooling?

Generated-by: Claude Code

…rmat, to_char and to_varchar

Extend DateFormatClass (which backs date_format, to_char and to_varchar) to
accept AnyTimestampNanoType inputs. Both interpreted eval and doGenCode render
via the TimestampNanosVal object carrier: TIMESTAMP_NTZ(p) renders its wall
clock zone-independently while TIMESTAMP_LTZ(p) renders in the formatter's
session zone, and fractional-second digits below the type precision floor to
zeros rather than being dropped. Also guard SimplifyDateTimeConversions from
rewriting a nanosecond-timestamp child, since the round trip through micro
TimestampType would silently truncate sub-microsecond precision.

Adds unit coverage in DateExpressionsSuite and SimplifyDateTimeConversionsSuite,
end-to-end SQL/Column coverage in TimestampNanosFunctionsSuiteBase, and golden
cases in timestamp-{ltz,ntz}-nanos.sql.

Co-authored-by: Isaac
@stevomitric stevomitric force-pushed the stevomitric/spark-57816-nanos branch from daa97ad to bd14624 Compare July 13, 2026 15:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant