-
Notifications
You must be signed in to change notification settings - Fork 28.9k
[SPARK-31527][SQL] date add/subtract interval only allow those day precision in ansi mode #28310
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
77e75a7
9d7ea7e
0c96bf5
65a0e4d
c1964a8
c64d27e
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 |
|---|---|---|
|
|
@@ -618,6 +618,22 @@ object DateTimeUtils { | |
| instantToMicros(resultTimestamp.toInstant) | ||
| } | ||
|
|
||
| /** | ||
| * Add the date and the interval's months and days. | ||
| * Returns a date value, expressed in days since 1.1.1970. | ||
| * | ||
| * @throws DateTimeException if the result exceeds the supported date range | ||
| * @throws IllegalArgumentException if the interval has `microseconds` part | ||
| */ | ||
| def dateAddInterval( | ||
| start: SQLDate, | ||
| interval: CalendarInterval): SQLDate = { | ||
| require(interval.microseconds == 0, | ||
| "Cannot add hours, minutes or seconds, milliseconds, microseconds to a date") | ||
| val ld = LocalDate.ofEpochDay(start).plusMonths(interval.months).plusDays(interval.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. Actually, the result depends on the order of
Member
Author
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. Yes,here we are follow the previous behavior of using timestamp + interval
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. I see, thanks. It would be nice to document such behavior of this function and timestampAddInterval somewhere. It is not obvious that we add month then days and then micros. The order could be opposite.
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. FYI, in snowflake
Member
Author
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. I will make time for that PR. |
||
| localDateToDays(ld) | ||
| } | ||
|
|
||
| /** | ||
| * Returns number of months between time1 and time2. time1 and time2 are expressed in | ||
| * microseconds since 1.1.1970. If time1 is later than time2, the result is positive. | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| --IMPORT datetime.sql |
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.
This is a good idea, maybe we can remove
TimeSublater.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.
yea, we can clean it up later