[SPARK-56160][SQL] Add DataType classes for nanosecond timestamp types#54966
Open
xiaoxuandev wants to merge 1 commit intoapache:masterfrom
Open
[SPARK-56160][SQL] Add DataType classes for nanosecond timestamp types#54966xiaoxuandev wants to merge 1 commit intoapache:masterfrom
xiaoxuandev wants to merge 1 commit intoapache:masterfrom
Conversation
### What changes were proposed in this pull request? This PR adds two new DataType classes for nanosecond-precision timestamps: - `TimestampNSType` (with local timezone semantics) - `TimestampNTZNSType` (without timezone semantics) Both are singleton types following the same pattern as `TimestampNTZType` (SPARK-35662). They are stored internally as a Long representing nanoseconds since the Unix epoch, with a default size of 8 bytes. The representable range is approximately 1677-09-21 to 2262-04-11. This PR also registers the new types in `DataTypes.java` (Java API) and `DataType.scala` (type name registry for JSON/DDL parsing). ### Why are the changes needed? Microsecond precision is insufficient for a growing number of workloads: - Parquet files written by Pandas/PyArrow default to `TIMESTAMP(NANOS)` - Iceberg V3 adds `timestamp_ns` / `timestamptz_ns` types - Financial exchange data (NYSE, NASDAQ, CME) uses nanosecond timestamps - OpenTelemetry traces use nanosecond timestamps Without native nanosecond types, Spark either throws `AnalysisException` on nanosecond Parquet columns or reads them as raw `LongType` via `spark.sql.legacy.parquet.nanosAsLong`, losing all timestamp semantics. This is the first step of native nanosecond timestamp support. Subsequent PRs will add SQL parser keywords, Cast rules, Parquet read/write, and Arrow integration. ### Does this PR introduce _any_ user-facing change? No. The types are defined but not yet wired into the SQL parser or any data source. ### How was this patch tested? Added `checkDefaultSize` tests in `DataTypeSuite` for both new types. ### Was this patch authored or co-authored using generative AI tooling? Yes, co-authored with Kiro.
8e16374 to
b295070
Compare
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 PR adds two new DataType classes for nanosecond-precision timestamps:
TimestampNSType(with local timezone semantics)TimestampNTZNSType(without timezone semantics)Both are singleton types following the same pattern as
TimestampNTZType(SPARK-35662). They are stored internally as a Long representing nanoseconds since the Unix epoch, with a default size of 8 bytes. The representable range is approximately 1677-09-21 to 2262-04-11.This PR also registers the new types in
DataTypes.java(Java API) andDataType.scala(type name registry for JSON/DDL parsing).Why are the changes needed?
Microsecond precision is insufficient for a growing number of workloads:
TIMESTAMP(NANOS)timestamp_ns/timestamptz_nstypesWithout native nanosecond types, Spark either throws
AnalysisExceptionon nanosecond Parquet columns or reads them as rawLongTypeviaspark.sql.legacy.parquet.nanosAsLong, losing all timestamp semantics.This is the first step of native nanosecond timestamp support. Subsequent PRs will add SQL parser keywords, Cast rules, Parquet read/write, and Arrow integration.
Does this PR introduce any user-facing change?
No. The types are defined but not yet wired into the SQL parser or any data source.
How was this patch tested?
Added
checkDefaultSizetests inDataTypeSuitefor both new types.Was this patch authored or co-authored using generative AI tooling?
Yes, co-authored with Kiro.