You are viewing a plain text version of this content. The canonical link for it is here.
Posted to github@arrow.apache.org by "mr-brobot (via GitHub)" <gi...@apache.org> on 2023/05/18 16:52:12 UTC

[GitHub] [arrow-rs] mr-brobot opened a new pull request, #4244: Subtract ts

mr-brobot opened a new pull request, #4244:
URL: https://github.com/apache/arrow-rs/pull/4244

   # Which issue does this PR close?
   
   <!--
   We generally require a GitHub issue to be filed for all bug fixes and enhancements and this helps us generate change logs for our releases. You can link an issue to this PR using the GitHub syntax. For example `Closes #123` indicates that this PR will close issue #123.
   -->
   
   Closes #3964 
   
   # Rationale for this change
    
   <!--
   Why are you proposing this change? If this is already explained clearly in the issue then this section is not needed.
   Explaining clearly why changes are proposed helps reviewers understand your changes and offer better suggestions for fixes.
   -->
   
   See #3964 
   
   <!--
   There is no need to duplicate the description in the issue here but it is sometimes worth providing a summary of the individual changes in this PR.
   -->
   
   # 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?
   
   <!--
   If there are user-facing changes then we may require documentation to be updated before approving the PR.
   -->
   
   Expanded timestamp support for `subtract_dyn` and `subtract_dyn_checked`.
   
   <!---
   If there are any breaking changes to public APIs, please add the `breaking change` label.
   -->
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: github-unsubscribe@arrow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [arrow-rs] tustvold merged pull request #4244: Arrow Arithmetic: Subtract timestamps

Posted by "tustvold (via GitHub)" <gi...@apache.org>.
tustvold merged PR #4244:
URL: https://github.com/apache/arrow-rs/pull/4244


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: github-unsubscribe@arrow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [arrow-rs] tustvold commented on a diff in pull request #4244: Arrow Arithmetic: Subtract timestamps

Posted by "tustvold (via GitHub)" <gi...@apache.org>.
tustvold commented on code in PR #4244:
URL: https://github.com/apache/arrow-rs/pull/4244#discussion_r1198077349


##########
arrow-arith/src/arithmetic.rs:
##########
@@ -1096,13 +1096,18 @@ pub fn subtract_dyn(left: &dyn Array, right: &dyn Array) -> Result<ArrayRef, Arr
                     let res = math_checked_op(l, r, TimestampSecondType::subtract_month_day_nano)?;
                     Ok(Arc::new(res.with_timezone_opt(l.timezone())))
                 }
+                DataType::Timestamp(TimeUnit::Second, _) => {
+                    let r = right.as_primitive::<TimestampSecondType>();
+                    let op = <TimestampSecondType as ArrowPrimitiveType>::Native::wrapping_sub;
+                    let res: PrimitiveArray<DurationSecondType> = binary(l, r, op)?;

Review Comment:
   ```suggestion
                       let res: PrimitiveArray<DurationSecondType> = binary(l, r, |a, b| a.wrapping_sub(b))?;
   ```
   Perhaps?



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: github-unsubscribe@arrow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [arrow-rs] tustvold commented on a diff in pull request #4244: Arrow Arithmetic: Subtract timestamps

Posted by "tustvold (via GitHub)" <gi...@apache.org>.
tustvold commented on code in PR #4244:
URL: https://github.com/apache/arrow-rs/pull/4244#discussion_r1198074693


##########
arrow-arith/src/arithmetic.rs:
##########
@@ -4649,4 +4731,144 @@ mod tests {
         ]);
         assert_eq!(&expected, result);
     }
+
+    #[test]
+    fn test_timestamp_second_subtract_timestamp() {

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



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: github-unsubscribe@arrow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [arrow-rs] mr-brobot commented on pull request #4244: Subtract ts

Posted by "mr-brobot (via GitHub)" <gi...@apache.org>.
mr-brobot commented on PR #4244:
URL: https://github.com/apache/arrow-rs/pull/4244#issuecomment-1553345696

   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`.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: github-unsubscribe@arrow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [arrow-rs] tustvold commented on pull request #4244: Arrow Arithmetic: Subtract timestamps

Posted by "tustvold (via GitHub)" <gi...@apache.org>.
tustvold commented on PR #4244:
URL: https://github.com/apache/arrow-rs/pull/4244#issuecomment-1553366502

   > 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 :+1:


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: github-unsubscribe@arrow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org