-
Notifications
You must be signed in to change notification settings - Fork 28.7k
[SPARK-52693][SQL] Support +/- ANSI day-time intervals to/from TIME #51383
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
46b84f8
521ed07
d9efe8c
2f9d3fb
04499d5
9a5d641
76aa8dc
5dc153f
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 |
---|---|---|
|
@@ -834,4 +834,31 @@ object DateTimeUtils extends SparkDateTimeUtils { | |
def makeTimestampNTZ(days: Int, nanos: Long): Long = { | ||
localDateTimeToMicros(LocalDateTime.of(daysToLocalDate(days), nanosToLocalTime(nanos))) | ||
} | ||
|
||
/** | ||
* Adds a day-time interval to a time. | ||
* | ||
* @param time A time in nanoseconds. | ||
* @param timePrecision The number of digits of the fraction part of time. | ||
* @param interval A day-time interval in microseconds. | ||
* @param intervalEndField The rightmost field which the interval comprises of. | ||
* Valid values: 0 (DAY), 1 (HOUR), 2 (MINUTE), 3 (SECOND). | ||
* @param targetPrecision The number of digits of the fraction part of the resulting time. | ||
* @return A time value in nanoseconds or throw an arithmetic overflow | ||
* if the result out of valid time range [00:00, 24:00). | ||
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. so if the day-time interval has the day field, it will always overflow? Shall we check the start field of day-time internal at the analysis time to make sure it's not DAY? 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.
Not always. Values in the day field can be 0. In that case, it couldn't overflow.
Maybe, do you mean the end field? And prohibit 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. As I see it, 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. OK, let's keep it runtime error then |
||
*/ | ||
def timeAddInterval( | ||
time: Long, | ||
timePrecision: Int, | ||
interval: Long, | ||
intervalEndField: Byte, | ||
targetPrecision: Int): Long = { | ||
val result = MathUtils.addExact(time, MathUtils.multiplyExact(interval, NANOS_PER_MICROS)) | ||
if (0 <= result && result < NANOS_PER_DAY) { | ||
truncateTimeToPrecision(result, targetPrecision) | ||
} else { | ||
throw QueryExecutionErrors.timeAddIntervalOverflowError( | ||
time, timePrecision, interval, intervalEndField) | ||
} | ||
} | ||
} |
Uh oh!
There was an error while loading. Please reload this page.
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.
Just a question. Is this
Serializable
required for this PR?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.
Yes, otherwise
StaticInvoke
fails with: