-
Notifications
You must be signed in to change notification settings - Fork 29k
[SPARK-29688][SQL] Support average for interval type values #26347
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
10 commits
Select commit
Hold shift + click to select a range
8ae0ced
[SPARK-29688][SQL] Support average for interval type values
yaooqinn 20c094d
fix ut
yaooqinn f1e197b
style
yaooqinn 3726762
rebase, mv tests to groupby.sql
yaooqinn 2ba835d
fix interval divide example's result
yaooqinn 998bd95
rebase
yaooqinn 161d742
Merge branch 'master' into SPARK-29688
yaooqinn 6ac44e4
rm useless test and regen golden file
yaooqinn 3443c18
fix example result
yaooqinn 2e06305
address comments
yaooqinn 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
[SPARK-29688][SQL] Support average for interval type values
- Loading branch information
commit 8ae0ced5750a0ce4b2ff85cfd24188307b7bee1d
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
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,32 @@ | ||
| -- average with interval type | ||
|
|
||
| -- null | ||
| select avg(cast(v as interval)) from VALUES ('1 seconds'), ('2 seconds'), (null) t(v) where v is null; | ||
|
|
||
| -- empty set | ||
| select avg(cast(v as interval)) from VALUES ('1 seconds'), ('2 seconds'), (null) t(v) where 1=0; | ||
|
|
||
| -- | ||
| select avg(cast(v as interval)) from VALUES ('1 seconds'), ('2 seconds'), (null) t(v); | ||
| select avg(cast(v as interval)) from VALUES ('-1 seconds'), ('2 seconds'), (null) t(v); | ||
| select avg(cast(v as interval)) from VALUES ('-1 seconds'), ('-2 seconds'), (null) t(v); | ||
| select avg(cast(v as interval)) from VALUES ('-1 weeks'), ('2 seconds'), (null) t(v); | ||
|
|
||
| --group by | ||
| select | ||
| i, | ||
| avg(cast(v as interval)) | ||
| from VALUES (1, '-1 weeks'), (2, '2 seconds'), (3, null), (1, '5 days') t(i, v) | ||
| group by i; | ||
|
|
||
| --having | ||
| select | ||
| avg(cast(v as interval)) as sv | ||
| from VALUES (1, '-1 weeks'), (2, '2 seconds'), (3, null), (1, '5 days') t(i, v) | ||
| having sv is not null; | ||
|
|
||
| -- window | ||
| SELECT | ||
| i, | ||
| avg(cast(v as interval)) OVER (ORDER BY i ROWS BETWEEN CURRENT ROW AND UNBOUNDED FOLLOWING) | ||
| FROM VALUES(1,'1 seconds'),(1,'2 seconds'),(2,NULL),(2,NULL) t(i,v); |
89 changes: 89 additions & 0 deletions
89
sql/core/src/test/resources/sql-tests/results/average.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,89 @@ | ||
| -- Automatically generated by SQLQueryTestSuite | ||
| -- Number of queries: 9 | ||
|
|
||
|
|
||
| -- !query 0 | ||
| select avg(cast(v as interval)) from VALUES ('1 seconds'), ('2 seconds'), (null) t(v) where v is null | ||
| -- !query 0 schema | ||
| struct<avg(CAST(v AS INTERVAL)):interval> | ||
| -- !query 0 output | ||
| NULL | ||
|
|
||
|
|
||
| -- !query 1 | ||
| select avg(cast(v as interval)) from VALUES ('1 seconds'), ('2 seconds'), (null) t(v) where 1=0 | ||
| -- !query 1 schema | ||
| struct<avg(CAST(v AS INTERVAL)):interval> | ||
| -- !query 1 output | ||
| NULL | ||
|
|
||
|
|
||
| -- !query 2 | ||
| select avg(cast(v as interval)) from VALUES ('1 seconds'), ('2 seconds'), (null) t(v) | ||
| -- !query 2 schema | ||
| struct<avg(CAST(v AS INTERVAL)):interval> | ||
| -- !query 2 output | ||
| interval 1 seconds 500 milliseconds | ||
|
|
||
|
|
||
| -- !query 3 | ||
| select avg(cast(v as interval)) from VALUES ('-1 seconds'), ('2 seconds'), (null) t(v) | ||
| -- !query 3 schema | ||
| struct<avg(CAST(v AS INTERVAL)):interval> | ||
| -- !query 3 output | ||
| interval 500 milliseconds | ||
|
|
||
|
|
||
| -- !query 4 | ||
| select avg(cast(v as interval)) from VALUES ('-1 seconds'), ('-2 seconds'), (null) t(v) | ||
| -- !query 4 schema | ||
| struct<avg(CAST(v AS INTERVAL)):interval> | ||
| -- !query 4 output | ||
| interval -1 seconds -500 milliseconds | ||
|
|
||
|
|
||
| -- !query 5 | ||
| select avg(cast(v as interval)) from VALUES ('-1 weeks'), ('2 seconds'), (null) t(v) | ||
| -- !query 5 schema | ||
| struct<avg(CAST(v AS INTERVAL)):interval> | ||
| -- !query 5 output | ||
| interval -3 days -11 hours -59 minutes -59 seconds | ||
|
|
||
|
|
||
| -- !query 6 | ||
| select | ||
| i, | ||
| avg(cast(v as interval)) | ||
| from VALUES (1, '-1 weeks'), (2, '2 seconds'), (3, null), (1, '5 days') t(i, v) | ||
| group by i | ||
| -- !query 6 schema | ||
| struct<i:int,avg(CAST(v AS INTERVAL)):interval> | ||
| -- !query 6 output | ||
| 1 interval -1 days | ||
| 2 interval 2 seconds | ||
| 3 NULL | ||
|
|
||
|
|
||
| -- !query 7 | ||
| select | ||
| avg(cast(v as interval)) as sv | ||
| from VALUES (1, '-1 weeks'), (2, '2 seconds'), (3, null), (1, '5 days') t(i, v) | ||
| having sv is not null | ||
| -- !query 7 schema | ||
| struct<sv:interval> | ||
| -- !query 7 output | ||
| interval -15 hours -59 minutes -59 seconds -333 milliseconds -333 microseconds | ||
|
|
||
|
|
||
| -- !query 8 | ||
| SELECT | ||
| i, | ||
| avg(cast(v as interval)) OVER (ORDER BY i ROWS BETWEEN CURRENT ROW AND UNBOUNDED FOLLOWING) | ||
| FROM VALUES(1,'1 seconds'),(1,'2 seconds'),(2,NULL),(2,NULL) t(i,v) | ||
| -- !query 8 schema | ||
| struct<i:int,avg(CAST(v AS INTERVAL)) OVER (ORDER BY i ASC NULLS FIRST ROWS BETWEEN CURRENT ROW AND UNBOUNDED FOLLOWING):interval> | ||
| -- !query 8 output | ||
| 1 interval 1 seconds 500 milliseconds | ||
| 1 interval 2 seconds | ||
| 2 NULL | ||
| 2 NULL |
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.
nit:
case interval: CalendarIntervalType => interval?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.
ok, I will change this and the one in the sumDataType