Skip to content

Commit

Permalink
Add telemetry for voluntary fallback
Browse files Browse the repository at this point in the history
  • Loading branch information
krlmlr committed Mar 10, 2024
1 parent 6d57f58 commit ee6291b
Show file tree
Hide file tree
Showing 7 changed files with 39 additions and 6 deletions.
2 changes: 1 addition & 1 deletion R/dplyr_col_modify.R
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ dplyr_col_modify.duckplyr_df <- function(data, cols) {
# Our implementation
rel_try(
# Always fall back to dplyr
"No relational implementation for dplyr_col_modify()" = TRUE,
"-" = TRUE,
{
return(out)
}
Expand Down
2 changes: 1 addition & 1 deletion R/dplyr_row_slice.R
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ dplyr_row_slice.duckplyr_df <- function(data, i, ...) {
# Our implementation
rel_try(
# Always fall back to dplyr
"No relational implementation for dplyr_row_slice()" = TRUE,
"-" = TRUE,
{
return(out)
}
Expand Down
2 changes: 1 addition & 1 deletion R/group_data.R
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ group_data.duckplyr_df <- function(.data) {
# Our implementation
rel_try(
# Always fall back to dplyr
"No relational implementation for group_data()" = TRUE,
"-" = TRUE,
{
return(out)
}
Expand Down
7 changes: 6 additions & 1 deletion R/relational.R
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,13 @@ rel_try <- function(rel, ..., call = NULL) {
if (isTRUE(dots[[i]])) {
stats$fallback <- stats$fallback + 1L
if (!dplyr_mode) {
message <- names(dots)[[i]]
if (message != "-") {
tel_collect(message, call)
}

if (Sys.getenv("DUCKPLYR_FALLBACK_INFO") == "TRUE") {
inform(message = c("Requested fallback for relational:", i = names(dots)[[i]]))
inform(message = c("Requested fallback for relational:", i = message))
}
if (Sys.getenv("DUCKPLYR_FORCE") == "TRUE") {
cli::cli_abort("Fallback not available with {.envvar DUCKPLYR_FORCE}.")
Expand Down
13 changes: 13 additions & 0 deletions tests/testthat/_snaps/fallback.md
Original file line number Diff line number Diff line change
Expand Up @@ -208,3 +208,16 @@
1 1 2
2 1 3

# rel_try()

Code
tibble(a = 1) %>% as_duckplyr_df() %>% left_join(tibble(a = 1), by = "a", copy = TRUE)
Message
i dplyr fallback recorded
{"version":"0.3.1","message":"No relational implementation for left_join(copy = TRUE)","name":"left_join","x":{"...1":"numeric"},"y":{"...1":"numeric"},"args":{"by":{"condition":"==","filter":"none","x":["...1"],"y":["...1"]},"copy":true,"na_matches":["na","never"],"multiple":"all","unmatched":"drop"}}
Output
# A tibble: 1 x 1
a
<dbl>
1 1

15 changes: 15 additions & 0 deletions tests/testthat/test-fallback.R
Original file line number Diff line number Diff line change
Expand Up @@ -221,3 +221,18 @@ test_that("__row_number", {
arrange(b)
})
})

test_that("rel_try()", {
withr::local_envvar(c(
"DUCKPLYR_FALLBACK_COLLECT" = "1",
"DUCKPLYR_FALLBACK_VERBOSE" = "TRUE",
"DUCKPLYR_FALLBACK_LOG_DIR" = tempdir(),
"DUCKPLYR_OUTPUT_ORDER" = "TRUE"
))

expect_snapshot({
tibble(a = 1) %>%
as_duckplyr_df() %>%
left_join(tibble(a = 1), by = "a", copy = TRUE)
})
})
4 changes: 2 additions & 2 deletions tests/testthat/test-telemetry.R
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ test_that("telemetry and anti_join()", {
anti_join(
tibble(a = 1:3, b = 4:6),
by = "a",
copy = TRUE,
copy = FALSE,
na_matches = "na"
)
})
Expand All @@ -18,7 +18,7 @@ test_that("telemetry and anti_join()", {
anti_join(
tibble(a = 1:3, b = 4:6),
by = c("a" = "b"),
copy = TRUE,
copy = FALSE,
na_matches = "na"
)
})
Expand Down

0 comments on commit ee6291b

Please sign in to comment.