-
Notifications
You must be signed in to change notification settings - Fork 4k
ARROW-14100: [C++] subtract(duration, duration) -> duration kernel #12141
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
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 |
|---|---|---|
|
|
@@ -1429,6 +1429,32 @@ TEST_F(ScalarTemporalTest, TestTemporalSubtractTimeAndDuration) { | |
| } | ||
| } | ||
|
|
||
| TEST_F(ScalarTemporalTest, TestTemporalSubtractDuration) { | ||
| for (auto op : {"subtract", "subtract_checked"}) { | ||
| for (auto u : TimeUnit::values()) { | ||
| auto unit = duration(u); | ||
| CheckScalarBinary(op, ArrayFromJSON(unit, times_s2), ArrayFromJSON(unit, times_s), | ||
| ArrayFromJSON(unit, seconds_between_time)); | ||
| } | ||
|
|
||
| auto seconds_3 = ArrayFromJSON(duration(TimeUnit::SECOND), R"([3, null])"); | ||
| auto milliseconds_2k = ArrayFromJSON(duration(TimeUnit::MILLI), R"([2000, null])"); | ||
| auto milliseconds_1k = ArrayFromJSON(duration(TimeUnit::MILLI), R"([1000, null])"); | ||
| CheckScalarBinary(op, seconds_3, milliseconds_2k, milliseconds_1k); | ||
| } | ||
|
|
||
| for (auto unit : TimeUnit::values()) { | ||
| auto duration_ty = duration(unit); | ||
| auto arr1 = ArrayFromJSON(duration_ty, R"([-9223372036854775808, null])"); | ||
| auto arr2 = ArrayFromJSON(duration_ty, R"([1, null])"); | ||
| auto arr3 = ArrayFromJSON(duration_ty, R"([9223372036854775807, null])"); | ||
|
|
||
| CheckScalarBinary("subtract", arr1, arr2, arr3); | ||
| EXPECT_RAISES_WITH_MESSAGE_THAT(Invalid, ::testing::HasSubstr("overflow"), | ||
| CallFunction("subtract_checked", {arr1, arr2})); | ||
| } | ||
| } | ||
|
|
||
|
||
| TEST_F(ScalarTemporalTest, TestTemporalDifferenceWeeks) { | ||
| auto raw_days = ArrayFromJSON(timestamp(TimeUnit::SECOND), R"([ | ||
| "2021-08-09", "2021-08-10", "2021-08-11", "2021-08-12", "2021-08-13", "2021-08-14", "2021-08-15", | ||
|
|
||
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.
Can you add tests for overflowing inputs?
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.
Added. However it seems as it duration is not treated as
int64_there and overflow is not detected?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.
Never mind. I was using the wrong operator.