dragosmg commented on a change in pull request #12506:
URL: https://github.com/apache/arrow/pull/12506#discussion_r831914535
##########
File path: r/R/dplyr-funcs-datetime.R
##########
@@ -233,6 +236,68 @@ register_bindings_datetime <- function() {
tz = "UTC") {
call_binding("make_datetime", year, month, day, hour, min, sec, tz)
})
+ register_binding("difftime", function(time1,
+ time2,
+ tz,
+ units = "secs") {
+ if (units != "secs") {
+ abort("`difftime()` with units other than `secs` not supported in Arrow")
+ }
+
+ if (!missing(tz)) {
+ warn("`tz` argument is not supported in Arrow, so it will be ignored")
+ }
+
+ # cast to timestamp if time1 and time2 are not dates or timpestamp
expressions
+ # (the subtraction of which would output a `duration`)
+ if (!(inherits(time1, "Expression") &&
+ time1$type_id() %in% Type[c("TIMESTAMP", "DATE32", "DATE64")])) {
+ time1 <- build_expr("cast", time1, options = cast_options(to_type =
timestamp(timezone = "UTC")))
+ }
+
+ if (!(inherits(time2, "Expression") &&
+ time2$type_id() %in% Type[c("TIMESTAMP", "DATE32", "DATE64")])) {
+ time2 <- build_expr("cast", time2, options = cast_options(to_type =
timestamp(timezone = "UTC")))
+ }
Review comment:
This is the final line in that binding (row 264):
```r
build_expr("cast", time1 - time2, options = cast_options(to_type =
duration("s")))
```
if we use `!call_binging("is.instant", time1)` it means that when `time1` is
a POSIXct object it will bypass the cast to timestamp and jump straight to
building the subtraction -> casting expression. We get an error because of the
subtraction operation `-`.
```r
via_table <- rlang::eval_tidy(expr, rlang::new_data_mask(rlang::env(.input =
arrow_table(tbl))))` threw an unexpected warning.
Message: Incompatible methods ("-.POSIXt", "Ops.Expression") for "-"
Class: simpleWarning/warning/condition
```
I guess we could build a subtraction expression, but that feels more
complicated to me - too big a trade-off for using `is.instant`.
--
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: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]