-
Notifications
You must be signed in to change notification settings - Fork 29.2k
[SPARK-57257][SQL] Support nanosecond-precision timestamps in Hive results #56320
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
+672
−4
Closed
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
118 changes: 118 additions & 0 deletions
118
sql/core/src/test/resources/sql-tests/analyzer-results/timestamp-ltz-nanos.sql.out
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,118 @@ | ||
| -- Automatically generated by SQLQueryTestSuite | ||
| -- !query | ||
| SELECT CAST('2020-01-01 00:00:00.123456789' AS timestamp_ltz(7)) | ||
| -- !query analysis | ||
| Project [cast(2020-01-01 00:00:00.123456789 as timestamp_ltz(7)) AS CAST(2020-01-01 00:00:00.123456789 AS TIMESTAMP_LTZ(7))#x] | ||
| +- OneRowRelation | ||
|
|
||
|
|
||
| -- !query | ||
| SELECT CAST('2020-01-01 00:00:00.123456789' AS timestamp_ltz(8)) | ||
| -- !query analysis | ||
| Project [cast(2020-01-01 00:00:00.123456789 as timestamp_ltz(8)) AS CAST(2020-01-01 00:00:00.123456789 AS TIMESTAMP_LTZ(8))#x] | ||
| +- OneRowRelation | ||
|
|
||
|
|
||
| -- !query | ||
| SELECT CAST('2020-01-01 00:00:00.123456789' AS timestamp_ltz(9)) | ||
| -- !query analysis | ||
| Project [cast(2020-01-01 00:00:00.123456789 as timestamp_ltz(9)) AS CAST(2020-01-01 00:00:00.123456789 AS TIMESTAMP_LTZ(9))#x] | ||
| +- OneRowRelation | ||
|
|
||
|
|
||
| -- !query | ||
| SELECT CAST('2020-01-01 00:00:00.999999000' AS timestamp_ltz(9)) | ||
| -- !query analysis | ||
| Project [cast(2020-01-01 00:00:00.999999000 as timestamp_ltz(9)) AS CAST(2020-01-01 00:00:00.999999000 AS TIMESTAMP_LTZ(9))#x] | ||
| +- OneRowRelation | ||
|
|
||
|
|
||
| -- !query | ||
| SELECT CAST('2020-01-01 00:00:00.000000999' AS timestamp_ltz(9)) | ||
| -- !query analysis | ||
| Project [cast(2020-01-01 00:00:00.000000999 as timestamp_ltz(9)) AS CAST(2020-01-01 00:00:00.000000999 AS TIMESTAMP_LTZ(9))#x] | ||
| +- OneRowRelation | ||
|
|
||
|
|
||
| -- !query | ||
| SELECT CAST('2020-01-01 00:00:00.000000001' AS timestamp_ltz(9)) | ||
| -- !query analysis | ||
| Project [cast(2020-01-01 00:00:00.000000001 as timestamp_ltz(9)) AS CAST(2020-01-01 00:00:00.000000001 AS TIMESTAMP_LTZ(9))#x] | ||
| +- OneRowRelation | ||
|
|
||
|
|
||
| -- !query | ||
| SELECT CAST('2020-01-01 00:00:00.000000001' AS timestamp_ltz(8)) | ||
| -- !query analysis | ||
| Project [cast(2020-01-01 00:00:00.000000001 as timestamp_ltz(8)) AS CAST(2020-01-01 00:00:00.000000001 AS TIMESTAMP_LTZ(8))#x] | ||
| +- OneRowRelation | ||
|
|
||
|
|
||
| -- !query | ||
| SELECT CAST('2020-01-01 00:00:00.000000001' AS timestamp_ltz(7)) | ||
| -- !query analysis | ||
| Project [cast(2020-01-01 00:00:00.000000001 as timestamp_ltz(7)) AS CAST(2020-01-01 00:00:00.000000001 AS TIMESTAMP_LTZ(7))#x] | ||
| +- OneRowRelation | ||
|
|
||
|
|
||
| -- !query | ||
| SELECT CAST('1960-01-01 00:00:00.000000001' AS timestamp_ltz(9)) | ||
| -- !query analysis | ||
| Project [cast(1960-01-01 00:00:00.000000001 as timestamp_ltz(9)) AS CAST(1960-01-01 00:00:00.000000001 AS TIMESTAMP_LTZ(9))#x] | ||
| +- OneRowRelation | ||
|
|
||
|
|
||
| -- !query | ||
| SELECT CAST('1960-01-01 00:00:00.123456789' AS timestamp_ltz(7)) | ||
| -- !query analysis | ||
| Project [cast(1960-01-01 00:00:00.123456789 as timestamp_ltz(7)) AS CAST(1960-01-01 00:00:00.123456789 AS TIMESTAMP_LTZ(7))#x] | ||
| +- OneRowRelation | ||
|
|
||
|
|
||
| -- !query | ||
| SELECT array(CAST('2020-01-01 00:00:00.123456789' AS timestamp_ltz(9))) | ||
| -- !query analysis | ||
| Project [array(cast(2020-01-01 00:00:00.123456789 as timestamp_ltz(9))) AS array(CAST(2020-01-01 00:00:00.123456789 AS TIMESTAMP_LTZ(9)))#x] | ||
| +- OneRowRelation | ||
|
|
||
|
|
||
| -- !query | ||
| SELECT map('k', CAST('2020-01-01 00:00:00.123456789' AS timestamp_ltz(9))) | ||
| -- !query analysis | ||
| Project [map(k, cast(2020-01-01 00:00:00.123456789 as timestamp_ltz(9))) AS map(k, CAST(2020-01-01 00:00:00.123456789 AS TIMESTAMP_LTZ(9)))#x] | ||
| +- OneRowRelation | ||
|
|
||
|
|
||
| -- !query | ||
| SELECT named_struct('f', CAST('2020-01-01 00:00:00.123456789' AS timestamp_ltz(9))) | ||
| -- !query analysis | ||
| Project [named_struct(f, cast(2020-01-01 00:00:00.123456789 as timestamp_ltz(9))) AS named_struct(f, CAST(2020-01-01 00:00:00.123456789 AS TIMESTAMP_LTZ(9)))#x] | ||
| +- OneRowRelation | ||
|
|
||
|
|
||
| -- !query | ||
| SELECT CAST(NULL AS timestamp_ltz(9)) | ||
| -- !query analysis | ||
| Project [cast(null as timestamp_ltz(9)) AS CAST(NULL AS TIMESTAMP_LTZ(9))#x] | ||
| +- OneRowRelation | ||
|
|
||
|
|
||
| -- !query | ||
| SELECT array(CAST(NULL AS timestamp_ltz(9))) | ||
| -- !query analysis | ||
| Project [array(cast(null as timestamp_ltz(9))) AS array(CAST(NULL AS TIMESTAMP_LTZ(9)))#x] | ||
| +- OneRowRelation | ||
|
|
||
|
|
||
| -- !query | ||
| SELECT map('k', CAST(NULL AS timestamp_ltz(9))) | ||
| -- !query analysis | ||
| Project [map(k, cast(null as timestamp_ltz(9))) AS map(k, CAST(NULL AS TIMESTAMP_LTZ(9)))#x] | ||
| +- OneRowRelation | ||
|
|
||
|
|
||
| -- !query | ||
| SELECT named_struct('f', CAST(NULL AS timestamp_ltz(9))) | ||
| -- !query analysis | ||
| Project [named_struct(f, cast(null as timestamp_ltz(9))) AS named_struct(f, CAST(NULL AS TIMESTAMP_LTZ(9)))#x] | ||
| +- OneRowRelation |
118 changes: 118 additions & 0 deletions
118
sql/core/src/test/resources/sql-tests/analyzer-results/timestamp-ntz-nanos.sql.out
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,118 @@ | ||
| -- Automatically generated by SQLQueryTestSuite | ||
| -- !query | ||
| SELECT CAST('2020-01-01 00:00:00.123456789' AS timestamp_ntz(7)) | ||
| -- !query analysis | ||
| Project [cast(2020-01-01 00:00:00.123456789 as timestamp_ntz(7)) AS CAST(2020-01-01 00:00:00.123456789 AS TIMESTAMP_NTZ(7))#x] | ||
| +- OneRowRelation | ||
|
|
||
|
|
||
| -- !query | ||
| SELECT CAST('2020-01-01 00:00:00.123456789' AS timestamp_ntz(8)) | ||
| -- !query analysis | ||
| Project [cast(2020-01-01 00:00:00.123456789 as timestamp_ntz(8)) AS CAST(2020-01-01 00:00:00.123456789 AS TIMESTAMP_NTZ(8))#x] | ||
| +- OneRowRelation | ||
|
|
||
|
|
||
| -- !query | ||
| SELECT CAST('2020-01-01 00:00:00.123456789' AS timestamp_ntz(9)) | ||
| -- !query analysis | ||
| Project [cast(2020-01-01 00:00:00.123456789 as timestamp_ntz(9)) AS CAST(2020-01-01 00:00:00.123456789 AS TIMESTAMP_NTZ(9))#x] | ||
| +- OneRowRelation | ||
|
|
||
|
|
||
| -- !query | ||
| SELECT CAST('2020-01-01 00:00:00.999999000' AS timestamp_ntz(9)) | ||
| -- !query analysis | ||
| Project [cast(2020-01-01 00:00:00.999999000 as timestamp_ntz(9)) AS CAST(2020-01-01 00:00:00.999999000 AS TIMESTAMP_NTZ(9))#x] | ||
| +- OneRowRelation | ||
|
|
||
|
|
||
| -- !query | ||
| SELECT CAST('2020-01-01 00:00:00.000000999' AS timestamp_ntz(9)) | ||
| -- !query analysis | ||
| Project [cast(2020-01-01 00:00:00.000000999 as timestamp_ntz(9)) AS CAST(2020-01-01 00:00:00.000000999 AS TIMESTAMP_NTZ(9))#x] | ||
| +- OneRowRelation | ||
|
|
||
|
|
||
| -- !query | ||
| SELECT CAST('2020-01-01 00:00:00.000000001' AS timestamp_ntz(9)) | ||
| -- !query analysis | ||
| Project [cast(2020-01-01 00:00:00.000000001 as timestamp_ntz(9)) AS CAST(2020-01-01 00:00:00.000000001 AS TIMESTAMP_NTZ(9))#x] | ||
| +- OneRowRelation | ||
|
|
||
|
|
||
| -- !query | ||
| SELECT CAST('2020-01-01 00:00:00.000000001' AS timestamp_ntz(8)) | ||
| -- !query analysis | ||
| Project [cast(2020-01-01 00:00:00.000000001 as timestamp_ntz(8)) AS CAST(2020-01-01 00:00:00.000000001 AS TIMESTAMP_NTZ(8))#x] | ||
| +- OneRowRelation | ||
|
|
||
|
|
||
| -- !query | ||
| SELECT CAST('2020-01-01 00:00:00.000000001' AS timestamp_ntz(7)) | ||
| -- !query analysis | ||
| Project [cast(2020-01-01 00:00:00.000000001 as timestamp_ntz(7)) AS CAST(2020-01-01 00:00:00.000000001 AS TIMESTAMP_NTZ(7))#x] | ||
| +- OneRowRelation | ||
|
|
||
|
|
||
| -- !query | ||
| SELECT CAST('1960-01-01 00:00:00.000000001' AS timestamp_ntz(9)) | ||
| -- !query analysis | ||
| Project [cast(1960-01-01 00:00:00.000000001 as timestamp_ntz(9)) AS CAST(1960-01-01 00:00:00.000000001 AS TIMESTAMP_NTZ(9))#x] | ||
| +- OneRowRelation | ||
|
|
||
|
|
||
| -- !query | ||
| SELECT CAST('1960-01-01 00:00:00.123456789' AS timestamp_ntz(7)) | ||
| -- !query analysis | ||
| Project [cast(1960-01-01 00:00:00.123456789 as timestamp_ntz(7)) AS CAST(1960-01-01 00:00:00.123456789 AS TIMESTAMP_NTZ(7))#x] | ||
| +- OneRowRelation | ||
|
|
||
|
|
||
| -- !query | ||
| SELECT array(CAST('2020-01-01 00:00:00.123456789' AS timestamp_ntz(9))) | ||
| -- !query analysis | ||
| Project [array(cast(2020-01-01 00:00:00.123456789 as timestamp_ntz(9))) AS array(CAST(2020-01-01 00:00:00.123456789 AS TIMESTAMP_NTZ(9)))#x] | ||
| +- OneRowRelation | ||
|
|
||
|
|
||
| -- !query | ||
| SELECT map('k', CAST('2020-01-01 00:00:00.123456789' AS timestamp_ntz(9))) | ||
| -- !query analysis | ||
| Project [map(k, cast(2020-01-01 00:00:00.123456789 as timestamp_ntz(9))) AS map(k, CAST(2020-01-01 00:00:00.123456789 AS TIMESTAMP_NTZ(9)))#x] | ||
| +- OneRowRelation | ||
|
|
||
|
|
||
| -- !query | ||
| SELECT named_struct('f', CAST('2020-01-01 00:00:00.123456789' AS timestamp_ntz(9))) | ||
| -- !query analysis | ||
| Project [named_struct(f, cast(2020-01-01 00:00:00.123456789 as timestamp_ntz(9))) AS named_struct(f, CAST(2020-01-01 00:00:00.123456789 AS TIMESTAMP_NTZ(9)))#x] | ||
| +- OneRowRelation | ||
|
|
||
|
|
||
| -- !query | ||
| SELECT CAST(NULL AS timestamp_ntz(9)) | ||
| -- !query analysis | ||
| Project [cast(null as timestamp_ntz(9)) AS CAST(NULL AS TIMESTAMP_NTZ(9))#x] | ||
| +- OneRowRelation | ||
|
|
||
|
|
||
| -- !query | ||
| SELECT array(CAST(NULL AS timestamp_ntz(9))) | ||
| -- !query analysis | ||
| Project [array(cast(null as timestamp_ntz(9))) AS array(CAST(NULL AS TIMESTAMP_NTZ(9)))#x] | ||
| +- OneRowRelation | ||
|
|
||
|
|
||
| -- !query | ||
| SELECT map('k', CAST(NULL AS timestamp_ntz(9))) | ||
| -- !query analysis | ||
| Project [map(k, cast(null as timestamp_ntz(9))) AS map(k, CAST(NULL AS TIMESTAMP_NTZ(9)))#x] | ||
| +- OneRowRelation | ||
|
|
||
|
|
||
| -- !query | ||
| SELECT named_struct('f', CAST(NULL AS timestamp_ntz(9))) | ||
| -- !query analysis | ||
| Project [named_struct(f, cast(null as timestamp_ntz(9))) AS named_struct(f, CAST(NULL AS TIMESTAMP_NTZ(9)))#x] | ||
| +- OneRowRelation |
32 changes: 32 additions & 0 deletions
32
sql/core/src/test/resources/sql-tests/inputs/timestamp-ltz-nanos.sql
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,32 @@ | ||
| -- Nanosecond-precision TIMESTAMP_LTZ(p) (p in [7, 9]) in Hive results (SPARK-57257). | ||
| -- LTZ values are rendered in the session time zone. | ||
|
|
||
| --SET spark.sql.timestampNanosTypes.enabled=true | ||
| --SET spark.sql.session.timeZone=America/Los_Angeles | ||
|
|
||
| -- Precision-driven fraction width: sub-p digits are floored. | ||
| SELECT CAST('2020-01-01 00:00:00.123456789' AS timestamp_ltz(7)); | ||
| SELECT CAST('2020-01-01 00:00:00.123456789' AS timestamp_ltz(8)); | ||
| SELECT CAST('2020-01-01 00:00:00.123456789' AS timestamp_ltz(9)); | ||
|
|
||
| -- Trailing-zero trimming: an all-zero fraction renders as no fraction at all. | ||
| SELECT CAST('2020-01-01 00:00:00.999999000' AS timestamp_ltz(9)); | ||
| SELECT CAST('2020-01-01 00:00:00.000000999' AS timestamp_ltz(9)); | ||
| SELECT CAST('2020-01-01 00:00:00.000000001' AS timestamp_ltz(9)); | ||
| SELECT CAST('2020-01-01 00:00:00.000000001' AS timestamp_ltz(8)); | ||
| SELECT CAST('2020-01-01 00:00:00.000000001' AS timestamp_ltz(7)); | ||
|
|
||
| -- Pre-1970 values exercise the negative-epoch path. | ||
| SELECT CAST('1960-01-01 00:00:00.000000001' AS timestamp_ltz(9)); | ||
| SELECT CAST('1960-01-01 00:00:00.123456789' AS timestamp_ltz(7)); | ||
|
|
||
| -- Nested values (array / map / struct). | ||
| SELECT array(CAST('2020-01-01 00:00:00.123456789' AS timestamp_ltz(9))); | ||
| SELECT map('k', CAST('2020-01-01 00:00:00.123456789' AS timestamp_ltz(9))); | ||
| SELECT named_struct('f', CAST('2020-01-01 00:00:00.123456789' AS timestamp_ltz(9))); | ||
|
|
||
| -- NULL values (top-level and nested). | ||
| SELECT CAST(NULL AS timestamp_ltz(9)); | ||
| SELECT array(CAST(NULL AS timestamp_ltz(9))); | ||
| SELECT map('k', CAST(NULL AS timestamp_ltz(9))); | ||
| SELECT named_struct('f', CAST(NULL AS timestamp_ltz(9))); |
32 changes: 32 additions & 0 deletions
32
sql/core/src/test/resources/sql-tests/inputs/timestamp-ntz-nanos.sql
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,32 @@ | ||
| -- Nanosecond-precision TIMESTAMP_NTZ(p) (p in [7, 9]) in Hive results (SPARK-57257). | ||
| -- NTZ values are zone-independent. | ||
|
|
||
| --SET spark.sql.timestampNanosTypes.enabled=true | ||
| --SET spark.sql.session.timeZone=America/Los_Angeles | ||
|
|
||
| -- Precision-driven fraction width: sub-p digits are floored. | ||
| SELECT CAST('2020-01-01 00:00:00.123456789' AS timestamp_ntz(7)); | ||
| SELECT CAST('2020-01-01 00:00:00.123456789' AS timestamp_ntz(8)); | ||
| SELECT CAST('2020-01-01 00:00:00.123456789' AS timestamp_ntz(9)); | ||
|
|
||
| -- Trailing-zero trimming: an all-zero fraction renders as no fraction at all. | ||
| SELECT CAST('2020-01-01 00:00:00.999999000' AS timestamp_ntz(9)); | ||
| SELECT CAST('2020-01-01 00:00:00.000000999' AS timestamp_ntz(9)); | ||
| SELECT CAST('2020-01-01 00:00:00.000000001' AS timestamp_ntz(9)); | ||
| SELECT CAST('2020-01-01 00:00:00.000000001' AS timestamp_ntz(8)); | ||
| SELECT CAST('2020-01-01 00:00:00.000000001' AS timestamp_ntz(7)); | ||
|
|
||
| -- Pre-1970 values exercise the negative-epoch path. | ||
| SELECT CAST('1960-01-01 00:00:00.000000001' AS timestamp_ntz(9)); | ||
| SELECT CAST('1960-01-01 00:00:00.123456789' AS timestamp_ntz(7)); | ||
|
|
||
| -- Nested values (array / map / struct). | ||
| SELECT array(CAST('2020-01-01 00:00:00.123456789' AS timestamp_ntz(9))); | ||
| SELECT map('k', CAST('2020-01-01 00:00:00.123456789' AS timestamp_ntz(9))); | ||
| SELECT named_struct('f', CAST('2020-01-01 00:00:00.123456789' AS timestamp_ntz(9))); | ||
|
|
||
| -- NULL values (top-level and nested). | ||
| SELECT CAST(NULL AS timestamp_ntz(9)); | ||
| SELECT array(CAST(NULL AS timestamp_ntz(9))); | ||
| SELECT map('k', CAST(NULL AS timestamp_ntz(9))); | ||
| SELECT named_struct('f', CAST(NULL AS timestamp_ntz(9))); |
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It would be nice to add at least some test cases with null values (both top-level and nested/complex).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added. Note: NULLs for these columns are handled by the generic
(null, _)branch inHiveResult.toHiveString, which runs before the newTimestampLTZNanosType/TimestampNTZNanosTypecases, so the path is type-agnostic -- but it's worth locking in. Added top-level (NULL) and nested array/map/struct NULL cases to both golden files (and the suite). Done in d578fbb.