-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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
add interval arithmetic for timestamp types #7758
Conversation
Timestamp types have custom arithmetic and need special handling when attempting to determine potential interval ranges. Change the processing of comparison operator propagation to convert timestamp intervals into int64 intervals for processing. The results are converted back the the correct datatype at the end of the process.
right_child: &Interval, | ||
left_type: &DataType, | ||
right_type: &DataType, | ||
) -> Result<(Option<Interval>, Option<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.
Should this function have some additional constraint checks on the two timestamp types? Perhaps to ensure the two timestamps are actually comparable? I couldn't think of any to add, but maybe someone else can.
I've observed the problem is in x>y is reformed as x-y>0, and (x-y) node is assigned with a new interval of [0, inf). However,
I think no additional implementation is needed to handle timestamp cases. When I applied these changes, the test mentioned in the issue passed successfully. |
The review from @berkaysynnada showed that it was not necessary to have special handling for timestamp types, but to make sure the new_zero function for scalars of a duration type return 0 rather than null values. Apply the suggested change, leaving the test to ensure the functionality doesn't break in the future.
Thanks for the suggestion @berkaysynnada I have reverted my changes and made your suggested change, keeping the test, and it works great. |
Apply a number of changes suggested by clippy.
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.
Thank you @mhilton and @berkaysynnada -- this change makes a lot of sense to me
@@ -833,15 +833,15 @@ impl ScalarValue { | |||
DataType::Interval(IntervalUnit::MonthDayNano) => { | |||
ScalarValue::IntervalMonthDayNano(Some(0)) | |||
} | |||
DataType::Duration(TimeUnit::Second) => ScalarValue::DurationSecond(None), |
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.
👌
I took the liberty of merging the comments to this PR and merging from main. |
Which issue does this PR close?
Closes #7756.
Rationale for this change
It will be useful for the interval calculating feature to be able to successfully determine the intervals for timestamp columns.
What changes are included in this PR?
The
new_zero
method for aScalarValue
with aDuration
type now returns a0
value, rather than aNULL
.Are these changes tested?
Yes
Are there any user-facing changes?
The
new_zero
function will now return a0
Duration
rather thanNULL
.