-
Notifications
You must be signed in to change notification settings - Fork 29k
[SPARK-29364][SQL] Return an interval from date subtract according to SQL standard #26112
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 6 commits
18bc09b
141d3da
dc37bc7
e82f027
e74f81b
4a8173b
27de6b8
fbd2723
199adff
8b49c9b
85f17f7
228673d
f232b64
c6ec211
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 |
|---|---|---|
|
|
@@ -828,8 +828,8 @@ object TypeCoercion { | |
| /** | ||
| * 1. Turns Add/Subtract of DateType/TimestampType/StringType and CalendarIntervalType | ||
| * to TimeAdd/TimeSub. | ||
| * 2. Turns Add/Subtract of DateType/IntegerType and IntegerType/DateType | ||
| * to DateAdd/DateSub/DateDiff. | ||
| * 2. Turns Add/Subtract of TimestampType/DateType/IntegerType | ||
| * and TimestampType/IntegerType/DateType to DateAdd/DateSub/SubtractDates. | ||
| */ | ||
| object DateTimeOperations extends Rule[LogicalPlan] { | ||
|
|
||
|
|
@@ -849,7 +849,7 @@ object TypeCoercion { | |
| 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) | ||
| case Subtract(l @ DateType(), r @ DateType()) => DateDiff(l, r) | ||
| case Subtract(l @ DateType(), r @ DateType()) => SubtractDates(l, r) | ||
|
||
| case Subtract(l @ TimestampType(), r @ TimestampType()) => TimestampDiff(l, r) | ||
MaxGekk marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| case Subtract(l @ TimestampType(), r @ DateType()) => | ||
| TimestampDiff(l, Cast(r, TimestampType)) | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -482,93 +482,93 @@ SELECT date '5874898-01-01' | |
| -- !query 46 | ||
| SELECT f1 - date '2000-01-01' AS `Days From 2K` FROM DATE_TBL | ||
| -- !query 46 schema | ||
| struct<Days From 2K:int> | ||
| struct<Days From 2K:interval> | ||
| -- !query 46 output | ||
| -1035 | ||
| -1036 | ||
| -1037 | ||
| -1400 | ||
| -1401 | ||
| -1402 | ||
| -1403 | ||
| -15542 | ||
| -15607 | ||
| 13977 | ||
| 14343 | ||
| 14710 | ||
| 91 | ||
| 92 | ||
| 93 | ||
| interval -2 years -10 months | ||
| interval -2 years -10 months -1 days | ||
| interval -2 years -9 months -4 weeks -2 days | ||
| interval -3 years -10 months | ||
| interval -3 years -10 months -1 days | ||
| interval -3 years -10 months -2 days | ||
| interval -3 years -9 months -4 weeks -2 days | ||
| interval -42 years -6 months -2 weeks -4 days | ||
| interval -42 years -8 months -3 weeks -1 days | ||
| interval 3 months | ||
| interval 3 months 1 days | ||
| interval 3 months 2 days | ||
| interval 38 years 3 months 1 weeks | ||
| interval 39 years 3 months 1 weeks 1 days | ||
| interval 40 years 3 months 1 weeks 2 days | ||
|
|
||
|
Member
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. These results are inconsistent with PostgreSQL: |
||
|
|
||
| -- !query 47 | ||
| SELECT f1 - date 'epoch' AS `Days From Epoch` FROM DATE_TBL | ||
| -- !query 47 schema | ||
| struct<Days From Epoch:int> | ||
| struct<Days From Epoch:interval> | ||
| -- !query 47 output | ||
| -4585 | ||
| -4650 | ||
| 11048 | ||
| 11049 | ||
| 11050 | ||
| 24934 | ||
| 25300 | ||
| 25667 | ||
| 9554 | ||
| 9555 | ||
| 9556 | ||
| 9557 | ||
| 9920 | ||
| 9921 | ||
| 9922 | ||
| interval -12 years -6 months -2 weeks -4 days | ||
| interval -12 years -8 months -3 weeks -1 days | ||
| interval 26 years 1 months 3 weeks 6 days | ||
| interval 26 years 1 months 4 weeks | ||
| interval 26 years 2 months | ||
| interval 26 years 2 months 1 days | ||
| interval 27 years 1 months 3 weeks 6 days | ||
| interval 27 years 2 months | ||
| interval 27 years 2 months 1 days | ||
| interval 30 years 3 months | ||
| interval 30 years 3 months 1 days | ||
| interval 30 years 3 months 2 days | ||
| interval 68 years 3 months 1 weeks | ||
| interval 69 years 3 months 1 weeks 1 days | ||
| interval 70 years 3 months 1 weeks 2 days | ||
|
|
||
|
|
||
| -- !query 48 | ||
| SELECT date 'yesterday' - date 'today' AS `One day` | ||
| -- !query 48 schema | ||
| struct<One day:int> | ||
| struct<One day:interval> | ||
| -- !query 48 output | ||
| -1 | ||
| interval -1 days | ||
|
|
||
|
|
||
| -- !query 49 | ||
| SELECT date 'today' - date 'tomorrow' AS `One day` | ||
| -- !query 49 schema | ||
| struct<One day:int> | ||
| struct<One day:interval> | ||
| -- !query 49 output | ||
| -1 | ||
| interval -1 days | ||
|
|
||
|
|
||
| -- !query 50 | ||
| SELECT date 'yesterday' - date 'tomorrow' AS `Two days` | ||
| -- !query 50 schema | ||
| struct<Two days:int> | ||
| struct<Two days:interval> | ||
| -- !query 50 output | ||
| -2 | ||
| interval -2 days | ||
|
|
||
|
|
||
| -- !query 51 | ||
| SELECT date 'tomorrow' - date 'today' AS `One day` | ||
| -- !query 51 schema | ||
| struct<One day:int> | ||
| struct<One day:interval> | ||
| -- !query 51 output | ||
| 1 | ||
| interval 1 days | ||
|
|
||
|
|
||
| -- !query 52 | ||
| SELECT date 'today' - date 'yesterday' AS `One day` | ||
| -- !query 52 schema | ||
| struct<One day:int> | ||
| struct<One day:interval> | ||
| -- !query 52 output | ||
| 1 | ||
| interval 1 days | ||
|
|
||
|
|
||
| -- !query 53 | ||
| SELECT date 'tomorrow' - date 'yesterday' AS `Two days` | ||
| -- !query 53 schema | ||
| struct<Two days:int> | ||
| struct<Two days:interval> | ||
| -- !query 53 output | ||
| 2 | ||
| interval 2 days | ||
|
|
||
|
|
||
| -- !query 54 | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.