fix: cast to and from timestamp_ntz#4008
Open
parthchandra wants to merge 1 commit intoapache:mainfrom
Open
Conversation
Contributor
Author
|
@coderfender, fyi |
Member
|
Seems like this PR overlaps with #3253? I'm fine with closing mine and reviewing this one though. |
Contributor
|
Thanks @parthchandra |
Contributor
Author
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.
Which issue does this PR close?
Part of #286
Part of #378
Rationale for this change
We currently fall back to Spark for timestamp_ntz casts
What changes are included in this PR?
Add native support for casting to and from
TimestampNTZType(timestamp without timezone).PR Description
Implemented cast directions:
Not yet implemented:
Incompatible, tracked in Implement Spark-compatible CAST to/from TimestampNTZType #378)Key implementation details
resolve_local_datetime()helper to handle DST ambiguity (fall-back) and gaps (spring-forward) matching Spark'sZonedDateTimesemantics.array_with_timezone**: This PR changes the Timestamp(, Some()) -> Timestamp(, Some()) path in array_with_timezone (utils.rs) to pass through the array unchanged, deferring the actual NTZ-to-Timestamp conversion to the explicit timestamp_ntz_to_timestamp call in cast.rs. This only affects the Arrow timezone annotation on the intermediate array, not the stored microsecond values. Callers of array_with_timezone that pass a Timestamp(_, Some(tz)) target type should verify they are not relying on the old behavior of re-annotating the array with the session timezone.How are these changes tested?
Cast-specific test coverage
cast DateType to TimestampNTZTypecast TimestampType to TimestampNTZTypecast TimestampNTZType to StringTypecast TimestampNTZType to DateTypecast TimestampNTZType to TimestampTypecast StringType to TimestampNTZTypeSQL integration tests (
cast_timestamp_ntz.sql)CAST(TIMESTAMP_NTZ'2020-01-01 12:34:56.789' AS string))Test data
generateTimestampNTZ()reusesgenerateTimestampLiterals()which covers epoch, modern dates, DST-transition dates, and sub-second precision values.Timezone diversity
The
representativeTimezoneslist (17 zones) was chosen to cover:ANSI mode
Each
castTimestampTestinvocation tests bothANSI_ENABLED=false(null on invalid input) andANSI_ENABLED=true(exception on invalid input), plustry_cast().