-
Notifications
You must be signed in to change notification settings - Fork 29k
[SPARK-29679][SQL] Make interval type comparable and orderable #26337
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
Changes from all commits
e963e4a
571bfe4
853b993
f03753c
ffc73cc
aabedaa
d1d60a9
397fc7f
2f3d233
578ea9f
d872273
d9cc157
5404d70
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -855,6 +855,11 @@ object TypeCoercion { | |
| case Divide(l @ CalendarIntervalType(), r @ NumericType()) => | ||
| DivideInterval(l, r) | ||
|
|
||
| case b @ BinaryOperator(l @ CalendarIntervalType(), r @ NullType()) => | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is a little hacky. Maybe we should introduce We can try it in followup. |
||
| b.withNewChildren(Seq(l, Cast(r, CalendarIntervalType))) | ||
| case b @ BinaryOperator(l @ NullType(), r @ CalendarIntervalType()) => | ||
| b.withNewChildren(Seq(Cast(l, CalendarIntervalType), r)) | ||
|
|
||
| case Add(l @ DateType(), r @ IntegerType()) => DateAdd(l, r) | ||
| case Add(l @ IntegerType(), r @ DateType()) => DateAdd(r, l) | ||
| case Subtract(l @ DateType(), r @ IntegerType()) => DateSub(l, r) | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,43 @@ | ||
| -- test for intervals | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. now we have a dedicated sql test file for interval, maybe we should put all interval related tests here. We can do it in followup |
||
|
|
||
| -- greater than or equal | ||
| select interval '1 day' > interval '23 hour'; | ||
| select interval '-1 day' >= interval '-23 hour'; | ||
| select interval '-1 day' > null; | ||
| select null > interval '-1 day'; | ||
|
|
||
| -- less than or equal | ||
| select interval '1 minutes' < interval '1 hour'; | ||
| select interval '-1 day' <= interval '-23 hour'; | ||
|
|
||
| -- equal | ||
| select interval '1 year' = interval '360 days'; | ||
| select interval '1 year 2 month' = interval '420 days'; | ||
| select interval '1 year' = interval '365 days'; | ||
| select interval '1 month' = interval '30 days'; | ||
| select interval '1 minutes' = interval '1 hour'; | ||
| select interval '1 minutes' = null; | ||
| select null = interval '-1 day'; | ||
|
|
||
| -- null safe equal | ||
| select interval '1 minutes' <=> null; | ||
| select null <=> interval '1 minutes'; | ||
|
|
||
| -- complex interval representation | ||
| select INTERVAL '9 years 1 months -1 weeks -4 days -10 hours -46 minutes' > interval '1 minutes'; | ||
|
|
||
| -- ordering | ||
| select cast(v as interval) i from VALUES ('1 seconds'), ('4 seconds'), ('3 seconds') t(v) order by i; | ||
|
|
||
| -- unlimited days | ||
| select interval '1 month 120 days' > interval '2 month'; | ||
| select interval '1 month 30 days' = interval '2 month'; | ||
|
|
||
| -- unlimited microseconds | ||
| select interval '1 month 29 days 40 hours' > interval '2 month'; | ||
|
|
||
| -- max | ||
| select max(cast(v as interval)) from VALUES ('1 seconds'), ('4 seconds'), ('3 seconds') t(v); | ||
|
|
||
| -- min | ||
| select min(cast(v as interval)) from VALUES ('1 seconds'), ('4 seconds'), ('3 seconds') t(v); | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,180 @@ | ||
| -- Automatically generated by SQLQueryTestSuite | ||
| -- Number of queries: 22 | ||
|
|
||
|
|
||
| -- !query 0 | ||
| select interval '1 day' > interval '23 hour' | ||
| -- !query 0 schema | ||
| struct<(1 days > 23 hours):boolean> | ||
| -- !query 0 output | ||
| true | ||
|
|
||
|
|
||
| -- !query 1 | ||
| select interval '-1 day' >= interval '-23 hour' | ||
| -- !query 1 schema | ||
| struct<(-1 days >= -23 hours):boolean> | ||
| -- !query 1 output | ||
| false | ||
|
|
||
|
|
||
| -- !query 2 | ||
| select interval '-1 day' > null | ||
| -- !query 2 schema | ||
| struct<(-1 days > CAST(NULL AS INTERVAL)):boolean> | ||
| -- !query 2 output | ||
| NULL | ||
|
|
||
|
|
||
| -- !query 3 | ||
| select null > interval '-1 day' | ||
| -- !query 3 schema | ||
| struct<(CAST(NULL AS INTERVAL) > -1 days):boolean> | ||
| -- !query 3 output | ||
| NULL | ||
|
|
||
|
|
||
| -- !query 4 | ||
| select interval '1 minutes' < interval '1 hour' | ||
| -- !query 4 schema | ||
| struct<(1 minutes < 1 hours):boolean> | ||
| -- !query 4 output | ||
| true | ||
|
|
||
|
|
||
| -- !query 5 | ||
| select interval '-1 day' <= interval '-23 hour' | ||
| -- !query 5 schema | ||
| struct<(-1 days <= -23 hours):boolean> | ||
| -- !query 5 output | ||
| true | ||
|
|
||
|
|
||
| -- !query 6 | ||
| select interval '1 year' = interval '360 days' | ||
| -- !query 6 schema | ||
| struct<(1 years = 360 days):boolean> | ||
| -- !query 6 output | ||
| true | ||
|
|
||
|
|
||
| -- !query 7 | ||
| select interval '1 year 2 month' = interval '420 days' | ||
| -- !query 7 schema | ||
| struct<(1 years 2 months = 420 days):boolean> | ||
| -- !query 7 output | ||
| true | ||
|
|
||
|
|
||
| -- !query 8 | ||
| select interval '1 year' = interval '365 days' | ||
| -- !query 8 schema | ||
| struct<(1 years = 365 days):boolean> | ||
| -- !query 8 output | ||
| false | ||
|
|
||
|
|
||
| -- !query 9 | ||
| select interval '1 month' = interval '30 days' | ||
| -- !query 9 schema | ||
| struct<(1 months = 30 days):boolean> | ||
| -- !query 9 output | ||
| true | ||
|
|
||
|
|
||
| -- !query 10 | ||
| select interval '1 minutes' = interval '1 hour' | ||
| -- !query 10 schema | ||
| struct<(1 minutes = 1 hours):boolean> | ||
| -- !query 10 output | ||
| false | ||
|
|
||
|
|
||
| -- !query 11 | ||
| select interval '1 minutes' = null | ||
| -- !query 11 schema | ||
| struct<(1 minutes = CAST(NULL AS INTERVAL)):boolean> | ||
| -- !query 11 output | ||
| NULL | ||
|
|
||
|
|
||
| -- !query 12 | ||
| select null = interval '-1 day' | ||
| -- !query 12 schema | ||
| struct<(CAST(NULL AS INTERVAL) = -1 days):boolean> | ||
| -- !query 12 output | ||
| NULL | ||
|
|
||
|
|
||
| -- !query 13 | ||
| select interval '1 minutes' <=> null | ||
| -- !query 13 schema | ||
| struct<(1 minutes <=> CAST(NULL AS INTERVAL)):boolean> | ||
| -- !query 13 output | ||
| false | ||
|
|
||
|
|
||
| -- !query 14 | ||
| select null <=> interval '1 minutes' | ||
| -- !query 14 schema | ||
| struct<(CAST(NULL AS INTERVAL) <=> 1 minutes):boolean> | ||
| -- !query 14 output | ||
| false | ||
|
|
||
|
|
||
| -- !query 15 | ||
| select INTERVAL '9 years 1 months -1 weeks -4 days -10 hours -46 minutes' > interval '1 minutes' | ||
| -- !query 15 schema | ||
| struct<(9 years 1 months -11 days -10 hours -46 minutes > 1 minutes):boolean> | ||
| -- !query 15 output | ||
| true | ||
|
|
||
|
|
||
| -- !query 16 | ||
| select cast(v as interval) i from VALUES ('1 seconds'), ('4 seconds'), ('3 seconds') t(v) order by i | ||
| -- !query 16 schema | ||
| struct<i:interval> | ||
| -- !query 16 output | ||
| 1 seconds | ||
| 3 seconds | ||
| 4 seconds | ||
|
|
||
|
|
||
| -- !query 17 | ||
| select interval '1 month 120 days' > interval '2 month' | ||
| -- !query 17 schema | ||
| struct<(1 months 120 days > 2 months):boolean> | ||
| -- !query 17 output | ||
| true | ||
|
|
||
|
|
||
| -- !query 18 | ||
| select interval '1 month 30 days' = interval '2 month' | ||
| -- !query 18 schema | ||
| struct<(1 months 30 days = 2 months):boolean> | ||
| -- !query 18 output | ||
| true | ||
|
|
||
|
|
||
| -- !query 19 | ||
| select interval '1 month 29 days 40 hours' > interval '2 month' | ||
| -- !query 19 schema | ||
| struct<(1 months 29 days 40 hours > 2 months):boolean> | ||
| -- !query 19 output | ||
| true | ||
|
|
||
|
|
||
| -- !query 20 | ||
| select max(cast(v as interval)) from VALUES ('1 seconds'), ('4 seconds'), ('3 seconds') t(v) | ||
| -- !query 20 schema | ||
| struct<max(CAST(v AS INTERVAL)):interval> | ||
| -- !query 20 output | ||
| 4 seconds | ||
|
|
||
|
|
||
| -- !query 21 | ||
| select min(cast(v as interval)) from VALUES ('1 seconds'), ('4 seconds'), ('3 seconds') t(v) | ||
| -- !query 21 schema | ||
| struct<min(CAST(v AS INTERVAL)):interval> | ||
| -- !query 21 output | ||
| 1 seconds |
Uh oh!
There was an error while loading. Please reload this page.