Skip to content

[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
apache:branch-4.xfrom
stevomitric:stevomitric/spark-56965-backport-4.x
Closed

[SPARK-56965][SQL][4.x] Add SQL parser support for TIMESTAMP_NTZ(p) and TIMESTAMP_LTZ(p)#56112
stevomitric wants to merge 1 commit into
apache:branch-4.xfrom
stevomitric:stevomitric/spark-56965-backport-4.x

Conversation

@stevomitric
Copy link
Copy Markdown
Contributor

@stevomitric stevomitric commented May 26, 2026

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

…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)
@stevomitric
Copy link
Copy Markdown
Contributor Author

@MaxGekk please take a look at this backport.

Copy link
Copy Markdown
Member

@MaxGekk MaxGekk left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Waiting for CI.

@MaxGekk
Copy link
Copy Markdown
Member

MaxGekk commented May 26, 2026

I do believe the failed test is a flaky test:

[info] org.apache.spark.sql.jdbc.StarRocksIntegrationSuite *** ABORTED *** (11 minutes, 43 seconds)
[info]   The code passed to eventually never returned normally. Attempted 610 times over 10.0061540037 minutes. Last failure message: Communications link failure
[info]   
[info]   The last packet sent successfully to the server was 0 milliseconds ago. The driver has not received any packets from the server.. (DockerJDBCIntegrationSuite.scala:213)

@MaxGekk
Copy link
Copy Markdown
Member

MaxGekk commented May 26, 2026

+1, LGTM. Merging to branch-4.x.
Thank you, @stevomitric.

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>
@MaxGekk MaxGekk closed this May 26, 2026
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.

2 participants