[SPARK-56965][SQL][4.x] Add SQL parser support for TIMESTAMP_NTZ(p) and TIMESTAMP_LTZ(p)#56112
Closed
stevomitric wants to merge 1 commit into
Closed
Conversation
…MESTAMP_LTZ(p) ### What changes were proposed in this pull request? Adds SQL parser support for parameterized nanosecond-precision timestamp types introduced in SPARK-56876. The parser now accepts: - TIMESTAMP_NTZ(p) -> TimestampNTZNanosType(p) - TIMESTAMP_LTZ(p) -> TimestampLTZNanosType(p) - TIMESTAMP(p) WITHOUT TIME ZONE (alias for TIMESTAMP_NTZ(p)) - TIMESTAMP(p) WITH LOCAL TIME ZONE (alias for TIMESTAMP_LTZ(p)) - TIMESTAMP(p) (resolves via spark.sql.timestampType session default) with `p` from `[7, 9]`. Out-of-range precision throws `INVALID_TIMESTAMP_PRECISION`; negative precision is rejected by the grammar as `PARSE_SYNTAX_ERROR`. The new syntax is gated behind a new internal preview flag `spark.sql.timestampNanosTypes.enabled` (default false). Unparameterized TIMESTAMP, TIMESTAMP_NTZ, TIMESTAMP_LTZ, and the WITH/WITHOUT TIME ZONE variants continue to return the existing microsecond types - no behavior change. Part of SPIP SPARK-56822 (https://issues.apache.org/jira/browse/SPARK-56822). ### Why are the changes needed? SPARK-56876 added TimestampNTZNanosType / TimestampLTZNanosType to the type system but explicitly left out SQL/DDL integration - users cannot declare these types in CREATE TABLE, CAST, or Column.cast(String) today. This PR is the parser sub-task of the SPIP and wires those spellings through DataTypeAstBuilder, behind a preview flag so the surface is opt-in until the cast/runtime sub-tasks land. ### Does this PR introduce _any_ user-facing change? Yes made the parser changes to allow timestamps with precision. ### How was this patch tested? Extended DataTypeParserSuite ### Was this patch authored or co-authored using generative AI tooling? Generated-by: Claude Opus 4.7 Closes apache#56041 from stevomitric/stevomitric/add-parser-support. Authored-by: Stevo Mitric <stevomitric2000@gmail.com> Signed-off-by: Max Gekk <max.gekk@gmail.com> (cherry picked from commit 4bbf75e)
Contributor
Author
|
@MaxGekk please take a look at this backport. |
Member
|
I do believe the failed test is a flaky test: |
Member
|
+1, LGTM. Merging to branch-4.x. |
MaxGekk
pushed a commit
that referenced
this pull request
May 26, 2026
…nd TIMESTAMP_LTZ(p) ### What changes were proposed in this pull request? This is a backport of #56041 to branch-4.x. Adds SQL parser support for parameterized nanosecond-precision timestamp types introduced in SPARK-56876. The parser now accepts: - TIMESTAMP_NTZ(p) -> TimestampNTZNanosType(p) - TIMESTAMP_LTZ(p) -> TimestampLTZNanosType(p) - TIMESTAMP(p) WITHOUT TIME ZONE (alias for TIMESTAMP_NTZ(p)) - TIMESTAMP(p) WITH LOCAL TIME ZONE (alias for TIMESTAMP_LTZ(p)) - TIMESTAMP(p) (resolves via spark.sql.timestampType session default) with `p` from `[7, 9]`. Out-of-range precision throws `INVALID_TIMESTAMP_PRECISION`; negative precision is rejected by the grammar as `PARSE_SYNTAX_ERROR`. The new syntax is gated behind a new internal preview flag `spark.sql.timestampNanosTypes.enabled` (default false). Unparameterized TIMESTAMP, TIMESTAMP_NTZ, TIMESTAMP_LTZ, and the WITH/WITHOUT TIME ZONE variants continue to return the existing microsecond types - no behavior change. Part of SPIP SPARK-56822 (https://issues.apache.org/jira/browse/SPARK-56822). ### Why are the changes needed? SPARK-56876 added TimestampNTZNanosType / TimestampLTZNanosType to the type system but explicitly left out SQL/DDL integration - users cannot declare these types in CREATE TABLE, CAST, or Column.cast(String) today. This PR is the parser sub-task of the SPIP and wires those spellings through DataTypeAstBuilder, behind a preview flag so the surface is opt-in until the cast/runtime sub-tasks land. ### Does this PR introduce _any_ user-facing change? Yes made the parser changes to allow timestamps with precision. ### How was this patch tested? Extended DataTypeParserSuite ### Was this patch authored or co-authored using generative AI tooling? Generated-by: Claude Opus 4.7 Closes #56112 from stevomitric/stevomitric/spark-56965-backport-4.x. Authored-by: Stevo Mitric <stevomitric2000@gmail.com> Signed-off-by: Max Gekk <max.gekk@gmail.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What changes were proposed in this pull request?
This is a backport of #56041 to branch-4.x.
Adds SQL parser support for parameterized nanosecond-precision timestamp types introduced in SPARK-56876. The parser now accepts:
with
pfrom[7, 9]. Out-of-range precision throwsINVALID_TIMESTAMP_PRECISION; negative precision is rejected by the grammar asPARSE_SYNTAX_ERROR.The new syntax is gated behind a new internal preview flag
spark.sql.timestampNanosTypes.enabled(default false).Unparameterized TIMESTAMP, TIMESTAMP_NTZ, TIMESTAMP_LTZ, and the WITH/WITHOUT TIME ZONE variants continue to return the existing microsecond types - no behavior change.
Part of SPIP SPARK-56822 (https://issues.apache.org/jira/browse/SPARK-56822).
Why are the changes needed?
SPARK-56876 added TimestampNTZNanosType / TimestampLTZNanosType to the type system but explicitly left out SQL/DDL integration - users cannot declare these types in CREATE TABLE, CAST, or Column.cast(String) today. This PR is the parser sub-task of the SPIP and wires those spellings through DataTypeAstBuilder, behind a preview flag so the surface is opt-in until the cast/runtime sub-tasks land.
Does this PR introduce any user-facing change?
Yes made the parser changes to allow timestamps with precision.
How was this patch tested?
Extended DataTypeParserSuite
Was this patch authored or co-authored using generative AI tooling?
Generated-by: Claude Opus 4.7