Skip to content
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

Arrow Arithmetic: Subtract timestamps #4244

Merged
merged 3 commits into from
May 19, 2023
Merged

Conversation

mr-brobot
Copy link
Contributor

Which issue does this PR close?

Closes #3964

Rationale for this change

See #3964

What changes are included in this PR?

subtract_dyn and subtract_dyn_checked now support subtracting timestamps of the same resolution. The result is a duration of the same resolution as the timestamp operands.

Are there any user-facing changes?

Expanded timestamp support for subtract_dyn and subtract_dyn_checked.

@github-actions github-actions bot added the arrow Changes to the arrow crate label May 18, 2023
@mr-brobot
Copy link
Contributor Author

Some thoughts:

  • Lots of redundancy in the tests. I'd like to clean this up. Possibly with a macro to generate tests for each resolution?
  • Subtracting timestamps of different resolutions is not supported. It might make sense to support this by allowing the user to cast timestamps to different resolutions before calling subtract_dyn / subtract_dyn_checked.

@mr-brobot mr-brobot changed the title Subtract ts Arithmetic: Subtract timestamps May 18, 2023
@mr-brobot mr-brobot changed the title Arithmetic: Subtract timestamps Arrow Arithmetic: Subtract timestamps May 18, 2023
@@ -4649,4 +4731,144 @@ mod tests {
]);
assert_eq!(&expected, result);
}

#[test]
fn test_timestamp_second_subtract_timestamp() {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wonder if we could extract a generic function typed on the timestamp and duration types, this would avoid the duplication?

@tustvold
Copy link
Contributor

Subtracting timestamps of different resolutions is not supported

I think this is fine, we don't provide arithmetic between different integer precisions either - I think the responsibility is on the query engine to add type coercion logic where necessary 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
arrow Changes to the arrow crate
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Subtracting Timestamp from Timestamp should produce a Duration (not Timestamp)
2 participants