Uh oh!
There was an error while loading. Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork 4.3k
GH-41834: [R] Better error handling in dplyr code#41576
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Uh oh!
There was an error while loading. Please reload this page.
Changes from all commits
5166cf74e2c735fefbc0cbe79caa66ff9c0670e9e50bda4e336bf23a0cd2ff3df9d0814df3a7d20e218cFile filter
Filter by extension
Conversations
Uh oh!
There was an error while loading. Please reload this page.
Jump to
Uh oh!
There was an error while loading. Please reload this page.
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -19,47 +19,46 @@ | ||
| # The following S3 methods are registered on load if dplyr is present | ||
| arrange.arrow_dplyr_query <- function(.data, ..., .by_group = FALSE) { | ||
| call <- match.call() | ||
| .data <- as_adq(.data) | ||
| exprs <- expand_across(.data, quos(...)) | ||
| try_arrow_dplyr({ | ||
| .data <- as_adq(.data) | ||
| exprs <- expand_across(.data, quos(...)) | ||
| if (.by_group) { | ||
| # when the data is grouped and .by_group is TRUE, order the result by | ||
| # the grouping columns first | ||
| exprs <- c(quos(!!!dplyr::groups(.data)), exprs) | ||
| } | ||
| if (length(exprs) == 0) { | ||
| # Nothing to do | ||
| return(.data) | ||
| } | ||
| .data <- as_adq(.data) | ||
| # find and remove any dplyr::desc() and tidy-eval | ||
| # the arrange expressions inside an Arrow data_mask | ||
| sorts <- vector("list", length(exprs)) | ||
| descs <- logical(0) | ||
| mask <- arrow_mask(.data) | ||
| for (i in seq_along(exprs)) { | ||
| x <- find_and_remove_desc(exprs[[i]]) | ||
| exprs[[i]] <- x[["quos"]] | ||
| sorts[[i]] <- arrow_eval(exprs[[i]], mask) | ||
| names(sorts)[i] <- format_expr(exprs[[i]]) | ||
| if (inherits(sorts[[i]], "try-error")) { | ||
| msg <- paste("Expression", names(sorts)[i], "not supported in Arrow") | ||
| return(abandon_ship(call, .data, msg)) | ||
MemberAuthor There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Here's an example of "not just an indentation change": in the new code, we don't have to evaluate, catch the error, and re-raise in abandon_ship, we just let | ||
| if (.by_group) { | ||
| # when the data is grouped and .by_group is TRUE, order the result by | ||
| # the grouping columns first | ||
| exprs <- c(quos(!!!dplyr::groups(.data)), exprs) | ||
| } | ||
| if (length(mask$.aggregations)) { | ||
| # dplyr lets you arrange on e.g. x < mean(x), but we haven't implemented it. | ||
| # But we could, the same way it works in mutate() via join, if someone asks. | ||
| # Until then, just error. | ||
| # TODO: add a test for this | ||
| msg <- paste("Expression", format_expr(expr), "not supported in arrange() in Arrow") | ||
| return(abandon_ship(call, .data, msg)) | ||
| if (length(exprs) == 0) { | ||
| # Nothing to do | ||
| return(.data) | ||
| } | ||
| descs[i] <- x[["desc"]] | ||
| } | ||
| .data$arrange_vars <- c(sorts, .data$arrange_vars) | ||
| .data$arrange_desc <- c(descs, .data$arrange_desc) | ||
| .data | ||
| .data <- as_adq(.data) | ||
| # find and remove any dplyr::desc() and tidy-eval | ||
| # the arrange expressions inside an Arrow data_mask | ||
| sorts <- vector("list", length(exprs)) | ||
| descs <- logical(0) | ||
| mask <- arrow_mask(.data) | ||
| for (i in seq_along(exprs)) { | ||
| x <- find_and_remove_desc(exprs[[i]]) | ||
| exprs[[i]] <- x[["quos"]] | ||
| sorts[[i]] <- arrow_eval(exprs[[i]], mask) | ||
| names(sorts)[i] <- format_expr(exprs[[i]]) | ||
| if (length(mask$.aggregations)) { | ||
| # dplyr lets you arrange on e.g. x < mean(x), but we haven't implemented it. | ||
| # But we could, the same way it works in mutate() via join, if someone asks. | ||
| # Until then, just error. | ||
| # TODO: add a test for this | ||
| arrow_not_supported( | ||
| .actual_msg = "Expression not supported in arrange() in Arrow", | ||
| call = expr | ||
| ) | ||
| } | ||
| descs[i] <- x[["desc"]] | ||
| } | ||
| .data$arrange_vars <- c(sorts, .data$arrange_vars) | ||
| .data$arrange_desc <- c(descs, .data$arrange_desc) | ||
| .data | ||
| }) | ||
| } | ||
| arrange.Dataset <- arrange.ArrowTabular <- arrange.RecordBatchReader <- arrange.arrow_dplyr_query | ||
| @@ -73,10 +72,9 @@ find_and_remove_desc <- function(quosure) { | ||
| expr <- quo_get_expr(quosure) | ||
| descending <- FALSE | ||
| if (length(all.vars(expr)) < 1L) { | ||
| stop( | ||
| "Expression in arrange() does not contain any field names: ", | ||
| deparse(expr), | ||
| call. = FALSE | ||
| validation_error( | ||
| "Expression in arrange() does not contain any field names", | ||
| call = quosure | ||
| ) | ||
| } | ||
| # Use a while loop to remove any number of nested pairs of enclosing | ||
| @@ -90,7 +88,10 @@ find_and_remove_desc <- function(quosure) { | ||
| # ensure desc() has only one argument (when an R expression is a function | ||
| # call, length == 2 means it has exactly one argument) | ||
| if (length(expr) > 2) { | ||
| stop("desc() expects only one argument", call. = FALSE) | ||
| validation_error( | ||
| "desc() expects only one argument", | ||
| call = expr | ||
| ) | ||
| } | ||
| # remove desc() and toggle descending | ||
| expr <- expr[[2]] | ||
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
TIL about this making arrows!