nealrichardson commented on a change in pull request #10722:
URL: https://github.com/apache/arrow/pull/10722#discussion_r682578342
##########
File path: r/R/dplyr-summarize.R
##########
@@ -28,14 +28,107 @@ 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()")
+ } 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), ...)
Review comment:
Maybe so but it doesn't in the released version, and we'll be deleting
this else case before release
##########
File path: r/R/query-engine.R
##########
@@ -0,0 +1,75 @@
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements. See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership. The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License. You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied. See the License for the
+# specific language governing permissions and limitations
+# under the License.
+
+ExecPlan <- R6Class("ExecPlan",
+ inherit = ArrowObject,
+ public = list(
+ Scan = function(dataset) {
+ # Handle arrow_dplyr_query
+ if (inherits(dataset, "arrow_dplyr_query")) {
+ filter <- dataset$filtered_rows
+ if (isTRUE(filter)) {
+ filter <- Expression$scalar(TRUE)
+ }
+ # Use FieldsInExpression to find all from dataset$selected_columns
+ colnames <- unique(unlist(map(
Review comment:
We can't because `dataset$selected_columns` is a list of Expressions
that may contain 0, 1, or many FieldRefs
##########
File path: r/R/dplyr-summarize.R
##########
@@ -28,14 +28,107 @@ 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()")
+ } else if (isTRUE(getOption("arrow.summarize", FALSE))) {
Review comment:
I removed the flag now. It had the side effect of raising the warning
you asked about below in the unsupported cases. This is probably the right path
forward.
##########
File path: r/tests/testthat/test-dplyr-aggregate.R
##########
@@ -0,0 +1,165 @@
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements. See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership. The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License. You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied. See the License for the
+# specific language governing permissions and limitations
+# under the License.
+
+skip_if_not_available("dataset")
+
+withr::local_options(list(arrow.summarize = TRUE))
+
+library(dplyr)
+library(stringr)
+
+tbl <- example_data
+# Add some better string data
+tbl$verses <- verses[[1]]
+# c(" a ", " b ", " c ", ...) increasing padding
+# nchar = 3 5 7 9 11 13 15 17 19 21
+tbl$padded_strings <- stringr::str_pad(letters[1:10], width = 2 * (1:10) + 1,
side = "both")
+tbl$some_grouping <- rep(c(1, 2), 5)
+
+test_that("Can aggregate", {
+ expect_dplyr_equal(
+ input %>%
+ summarize(total = sum(int, na.rm = TRUE)) %>%
+ collect(),
+ tbl
+ )
+ skip("ARROW-13497: This is failing because the default is na.rm = FALSE")
+ expect_dplyr_equal(
+ input %>%
+ summarize(total = sum(int)) %>%
+ collect(),
+ tbl
+ )
+})
+
+test_that("Group by sum on dataset", {
+ expect_dplyr_equal(
+ input %>%
+ group_by(some_grouping) %>%
+ summarize(total = sum(int, na.rm = TRUE)) %>%
+ arrange(some_grouping) %>%
+ collect(),
+ tbl
+ )
+
+ expect_dplyr_equal(
+ input %>%
+ group_by(some_grouping) %>%
+ summarize(total = sum(int * 4, na.rm = TRUE)) %>%
+ arrange(some_grouping) %>%
+ collect(),
+ tbl
+ )
+
+ skip("ARROW-13497: This is failing because the default is na.rm = FALSE")
+ expect_dplyr_equal(
+ input %>%
+ group_by(some_grouping) %>%
+ summarize(total = sum(int)) %>%
+ arrange(some_grouping) %>%
+ collect(),
+ tbl
+ )
+})
+
+test_that("Group by any/all", {
+ withr::local_options(list(arrow.debug = TRUE))
+
+ expect_dplyr_equal(
+ input %>%
+ group_by(some_grouping) %>%
+ summarize(any(lgl, na.rm = TRUE)) %>%
+ arrange(some_grouping) %>%
+ collect(),
+ tbl
+ )
+ expect_dplyr_equal(
+ input %>%
+ group_by(some_grouping) %>%
+ summarize(all(lgl, na.rm = TRUE)) %>%
+ arrange(some_grouping) %>%
+ collect(),
+ tbl
+ )
+ # ARROW-13497: na.rm option also is not being passed/received to any/all
+
+ expect_dplyr_equal(
+ input %>%
+ mutate(has_words = nchar(verses) < 0) %>%
+ group_by(some_grouping) %>%
+ summarize(any(has_words)) %>%
+ arrange(some_grouping) %>%
+ collect(),
+ tbl
+ )
+ expect_dplyr_equal(
+ input %>%
+ mutate(has_words = nchar(verses) < 0) %>%
+ group_by(some_grouping) %>%
+ summarize(all(has_words)) %>%
+ arrange(some_grouping) %>%
+ collect(),
+ tbl
+ )
+ skip("This seems to be calling base::nchar")
+ expect_dplyr_equal(
+ input %>%
+ group_by(some_grouping) %>%
+ summarize(has_words = all(nchar(verses) < 0)) %>%
+ arrange(some_grouping) %>%
+ collect(),
+ tbl
+ )
+})
+
+test_that("Filter and aggregate", {
+ expect_dplyr_equal(
+ input %>%
+ filter(some_grouping == 2) %>%
+ summarize(total = sum(int, na.rm = TRUE)) %>%
+ collect(),
+ tbl
+ )
+
+ expect_dplyr_equal(
+ input %>%
+ filter(int > 5) %>%
+ summarize(total = sum(int, na.rm = TRUE)) %>%
+ collect(),
+ tbl
+ )
+
+ expect_dplyr_equal(
+ input %>%
+ filter(some_grouping == 2) %>%
+ group_by(some_grouping) %>%
+ summarize(total = sum(int, na.rm = TRUE)) %>%
+ arrange(some_grouping) %>%
+ collect(),
+ tbl
+ )
+
+ expect_dplyr_equal(
+ input %>%
+ filter(int > 5) %>%
+ group_by(some_grouping) %>%
+ summarize(total = sum(int, na.rm = TRUE)) %>%
+ arrange(some_grouping) %>%
+ collect(),
+ tbl
+ )
+})
Review comment:
I'll leave that to the followup since we're so far from the release, and
I don't want to block others from picking up these followups.
--
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]