-
Notifications
You must be signed in to change notification settings - Fork 29k
[SPARK-28690][SQL] Add date_part function for timestamps/dates
#25410
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
Closed
Changes from 1 commit
Commits
Show all changes
28 commits
Select commit
Hold shift + click to select a range
cc81650
Add the date_part() function
MaxGekk 0e571be
Merge remote-tracking branch 'remotes/origin/master' into date_part
MaxGekk b856859
Support millennium, century and decade by date_part()
MaxGekk d23b8ba
Uncomment the first usage of date_part()
MaxGekk af51e52
Reuse date_part() from extract
MaxGekk e68611a
Add a description for DatePart
MaxGekk e1d5a75
Merge remote-tracking branch 'remotes/origin/master' into date_part
MaxGekk ae353b9
Regen extract.sql.out
MaxGekk f3b2772
Regen timestamp.sql.out
MaxGekk b795ebc
Add synonyms for field
MaxGekk efc3ee0
Regen date_part.sql.out
MaxGekk 188d7de
Merge remote-tracking branch 'remotes/origin/master' into date_part
MaxGekk 9935c01
Add isoyear, milliseconds, microseconds and epoch
MaxGekk c918eb0
Re-gen extract.sql.out
MaxGekk bcf73d2
Re-gen date.sql.out
MaxGekk 7c549c7
Uncomment 2 queries in timestamp.sql
MaxGekk 1b2c8d4
List all values of field
MaxGekk 2fa25b1
Put synonyms to ()
MaxGekk 494679c
Remove unneeded backquotes
MaxGekk 5c8c34d
Remove backquotes around year, month, day, hour, minute and second
MaxGekk 05b3746
Revert "Remove backquotes around year, month, day, hour, minute and s…
MaxGekk 74a7fec
Turn off ansi mode for a query
MaxGekk bc707df
Fix
maropu d86c092
Re-gen date_part.sql.out
MaxGekk ade541d
Re-gen extract.sql.out
MaxGekk 43968c2
Change type of errorHandleFunc to Nothing
MaxGekk b292931
Merge remote-tracking branch 'origin/master' into date_part
MaxGekk 600eee6
Use backquotes around year, month, day, hour, minute and second
MaxGekk 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
Next
Next commit
Add the date_part() function
- Loading branch information
commit cc81650b09de527860d361d26510f443915daaae
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
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
29 changes: 29 additions & 0 deletions
29
sql/core/src/test/resources/sql-tests/inputs/date_part.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,29 @@ | ||
| CREATE TEMPORARY VIEW t AS select '2011-05-06 07:08:09.1234567' as c; | ||
|
|
||
| select date_part('year', c) from t; | ||
|
|
||
| select date_part('quarter', c) from t; | ||
|
|
||
| select date_part('month', c) from t; | ||
|
|
||
| select date_part('week', c) from t; | ||
|
|
||
| select date_part('day', c) from t; | ||
|
|
||
| select date_part('dayofweek', c) from t; | ||
|
|
||
| select date_part('dow', c) from t; | ||
|
|
||
| select date_part('isodow', c) from t; | ||
|
|
||
| select date_part('doy', c) from t; | ||
|
|
||
| select date_part('hour', c) from t; | ||
|
|
||
| select date_part('minute', c) from t; | ||
|
|
||
| select date_part('second', c) from t; | ||
|
|
||
| select date_part('not_supported', c) from t; | ||
|
|
||
| select date_part(c, c) from t; |
124 changes: 124 additions & 0 deletions
124
sql/core/src/test/resources/sql-tests/results/date_part.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,124 @@ | ||
| -- Automatically generated by SQLQueryTestSuite | ||
| -- Number of queries: 15 | ||
|
|
||
|
|
||
| -- !query 0 | ||
| CREATE TEMPORARY VIEW t AS select '2011-05-06 07:08:09.1234567' as c | ||
| -- !query 0 schema | ||
| struct<> | ||
| -- !query 0 output | ||
|
|
||
|
|
||
|
|
||
| -- !query 1 | ||
| select date_part('year', c) from t | ||
| -- !query 1 schema | ||
| struct<date_part('year', t.`c`):int> | ||
| -- !query 1 output | ||
| 2011 | ||
|
|
||
|
|
||
| -- !query 2 | ||
| select date_part('quarter', c) from t | ||
| -- !query 2 schema | ||
| struct<date_part('quarter', t.`c`):int> | ||
| -- !query 2 output | ||
| 2 | ||
|
|
||
|
|
||
| -- !query 3 | ||
| select date_part('month', c) from t | ||
| -- !query 3 schema | ||
| struct<date_part('month', t.`c`):int> | ||
| -- !query 3 output | ||
| 5 | ||
|
|
||
|
|
||
| -- !query 4 | ||
| select date_part('week', c) from t | ||
| -- !query 4 schema | ||
| struct<date_part('week', t.`c`):int> | ||
| -- !query 4 output | ||
| 18 | ||
|
|
||
|
|
||
| -- !query 5 | ||
| select date_part('day', c) from t | ||
| -- !query 5 schema | ||
| struct<date_part('day', t.`c`):int> | ||
| -- !query 5 output | ||
| 6 | ||
|
|
||
|
|
||
| -- !query 6 | ||
| select date_part('dayofweek', c) from t | ||
| -- !query 6 schema | ||
| struct<date_part('dayofweek', t.`c`):int> | ||
| -- !query 6 output | ||
| 6 | ||
|
|
||
|
|
||
| -- !query 7 | ||
| select date_part('dow', c) from t | ||
| -- !query 7 schema | ||
| struct<date_part('dow', t.`c`):int> | ||
| -- !query 7 output | ||
| 5 | ||
|
|
||
|
|
||
| -- !query 8 | ||
| select date_part('isodow', c) from t | ||
| -- !query 8 schema | ||
| struct<date_part('isodow', t.`c`):int> | ||
| -- !query 8 output | ||
| 5 | ||
|
|
||
|
|
||
| -- !query 9 | ||
| select date_part('doy', c) from t | ||
| -- !query 9 schema | ||
| struct<date_part('doy', t.`c`):int> | ||
| -- !query 9 output | ||
| 126 | ||
|
|
||
|
|
||
| -- !query 10 | ||
| select date_part('hour', c) from t | ||
| -- !query 10 schema | ||
| struct<date_part('hour', t.`c`):int> | ||
| -- !query 10 output | ||
| 7 | ||
|
|
||
|
|
||
| -- !query 11 | ||
| select date_part('minute', c) from t | ||
| -- !query 11 schema | ||
| struct<date_part('minute', t.`c`):int> | ||
| -- !query 11 output | ||
| 8 | ||
|
|
||
|
|
||
| -- !query 12 | ||
| select date_part('second', c) from t | ||
| -- !query 12 schema | ||
| struct<date_part('second', t.`c`):int> | ||
| -- !query 12 output | ||
| 9 | ||
|
|
||
|
|
||
| -- !query 13 | ||
| select date_part('not_supported', c) from t | ||
| -- !query 13 schema | ||
| struct<> | ||
| -- !query 13 output | ||
| org.apache.spark.sql.AnalysisException | ||
| Literals of type 'NOT_SUPPORTED' are currently not supported.;; line 1 pos 7 | ||
|
|
||
|
|
||
| -- !query 14 | ||
| select date_part(c, c) from t | ||
| -- !query 14 schema | ||
| struct<> | ||
| -- !query 14 output | ||
| org.apache.spark.sql.AnalysisException | ||
| The field parameter needs to be a foldable string value.;; line 1 pos 7 |
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.
Uh oh!
There was an error while loading. Please reload this page.