ianmcook commented on a change in pull request #10722:
URL: https://github.com/apache/arrow/pull/10722#discussion_r677919540



##########
File path: r/R/dplyr-summarize.R
##########
@@ -28,14 +28,109 @@ summarise.arrow_dplyr_query <- function(.data, ..., 
.engine = c("arrow", "duckdb
     dplyr::group_vars(.data)             # vars needed for grouping
   ))
   .data <- dplyr::select(.data, vars_to_keep)
-
   if (match.arg(.engine) == "duckdb") {
-    dplyr::summarise(to_duckdb(.data), ...)
-  } else {
-    if (query_on_dataset(.data)) {
-      not_implemented_for_dataset("summarize()")
+      dplyr::summarise(to_duckdb(.data), ...)
+  } else if (isTRUE(getOption("arrow.summarize", FALSE))) {
+    # Try stuff, if successful return()
+    out <- try(do_arrow_summarize(.data, ...), silent = TRUE)
+    if (inherits(out, "try-error")) {
+      return(abandon_ship(call, .data, format(out)))
+    } else {
+      return(out)
     }
+  } else {
+    # If unsuccessful or if option not set, do the work in R
     dplyr::summarise(dplyr::collect(.data), ...)
   }
 }
 summarise.Dataset <- summarise.ArrowTabular <- summarise.arrow_dplyr_query
+
+do_arrow_summarize <- function(.data, ...) {
+  exprs <- quos(...)
+  # Check for unnamed expressions and fix if any
+  unnamed <- !nzchar(names(exprs))
+  # Deparse and take the first element in case they're long expressions
+  names(exprs)[unnamed] <- map_chr(exprs[unnamed], as_label)
+
+  mask <- arrow_mask(.data)
+  # Add aggregation wrappers to arrow_mask somehow

Review comment:
       In dbplyr, aggregate function mappings are defined in a separate object 
apart from the scalar function mappings. I believe it's set up so the scalar 
functions are defined in a child environment that has a parent environment with 
the scalar function mappings defined in it, and the R environment lookup rules 
make it so when you pass the child environment as the mask, it will only ever 
use the parent environment if it can't find a function in the child environment.




-- 
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-unsubscr...@arrow.apache.org

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


Reply via email to