Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 3 additions & 7 deletions r/R/dplyr-datetime-helpers.R
Original file line number Diff line number Diff line change
Expand Up @@ -142,13 +142,9 @@ binding_as_date_numeric <- function(x, origin = "1970-01-01") {

if (origin != "1970-01-01") {
delta_in_sec <- call_binding("difftime", origin, "1970-01-01")
# TODO: revisit once either of these issues is addressed:
# https://issues.apache.org/jira/browse/ARROW-16253 (helper function for
# casting from double to duration) or
# https://issues.apache.org/jira/browse/ARROW-15862 (casting from int32
# -> duration or double -> duration)
delta_in_sec <- build_expr("cast", delta_in_sec, options = cast_options(to_type = int64()))
delta_in_days <- (delta_in_sec / 86400L)$cast(int32())
# TODO revisit once https://issues.apache.org/jira/browse/ARROW-15862
# (casting from int32 -> duration or double -> duration) is addressed
delta_in_days <- (delta_in_sec$cast(int64()) / 86400L)$cast(int32())
x <- build_expr("+", x, delta_in_days)
}

Expand Down
12 changes: 5 additions & 7 deletions r/R/dplyr-funcs-datetime.R
Original file line number Diff line number Diff line change
Expand Up @@ -351,8 +351,8 @@ register_bindings_datetime_conversion <- function() {

fraction <- decimal - y
delta <- build_expr("floor", seconds * fraction)
delta <- delta$cast(int64())
start + delta$cast(duration("s"))
delta <- make_duration(delta, "s")
start + delta
})
}

Expand Down Expand Up @@ -412,9 +412,8 @@ register_bindings_duration <- function() {

if (call_binding("is.character", x)) {
x <- build_expr("strptime", x, options = list(format = format, unit = 0L))
# complex casting only due to cast type restrictions: time64 -> int64 -> duration(us)
# and then we cast to duration ("s") at the end
x <- x$cast(time64("us"))$cast(int64())$cast(duration("us"))
# we do a final cast to duration ("s") at the end
x <- make_duration(x$cast(time64("us")), unit = "us")
}

# numeric -> duration not supported in Arrow yet so we use int64() as an
Expand Down Expand Up @@ -459,8 +458,7 @@ register_bindings_duration_constructor <- function() {
duration <- duration_from_chunks(chunks)
}

duration <- build_expr("cast", duration, options = cast_options(to_type = int64()))
duration$cast(duration("s"))
make_duration(duration, "s")
})
}

Expand Down