Skip to content

Arrow Arithmetic: Subtract timestamps#4244

Merged
tustvold merged 3 commits intoapache:masterfrom
mr-brobot:subtract_ts
May 19, 2023
Merged

Arrow Arithmetic: Subtract timestamps#4244
tustvold merged 3 commits intoapache:masterfrom
mr-brobot:subtract_ts

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
}

#[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