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
ARROW-15271: [R] Refactor do_exec_plan to return a RecordBatchReader#13170
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
e5a28c3f613afb0b4c06fc839f96e12c633File 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 |
|---|---|---|
| @@ -123,11 +123,7 @@ duckdb_disconnector <- function(con, tbl_name) { | ||
| #' other processes (like DuckDB). | ||
| #' | ||
| #' @param .data the object to be converted | ||
| #' @param as_arrow_query should the returned object be wrapped as an | ||
| #' `arrow_dplyr_query`? (logical, default: `TRUE`) | ||
| #' | ||
| #' @return a `RecordBatchReader` object, wrapped as an arrow dplyr query which | ||
| #' can be used in dplyr pipelines. | ||
| #' @return A `RecordBatchReader`. | ||
| #' @export | ||
| #' | ||
| #' @examplesIf getFromNamespace("run_duckdb_examples", "arrow")() | ||
| @@ -142,7 +138,7 @@ duckdb_disconnector <- function(con, tbl_name) { | ||
| #' summarize(mean_mpg = mean(mpg, na.rm = TRUE)) %>% | ||
| #' to_arrow() %>% | ||
| #' collect() | ||
| to_arrow <- function(.data, as_arrow_query = TRUE) { | ||
| to_arrow <- function(.data) { | ||
| # If this is an Arrow object already, return quickly since we're already Arrow | ||
| if (inherits(.data, c("arrow_dplyr_query", "ArrowObject"))) { | ||
| return(.data) | ||
| @@ -161,9 +157,5 @@ to_arrow <- function(.data, as_arrow_query = TRUE) { | ||
| # Run the query | ||
| res <- DBI::dbSendQuery(dbplyr::remote_con(.data), dbplyr::remote_query(.data), arrow = TRUE) | ||
| if (as_arrow_query) { | ||
| arrow_dplyr_query(duckdb::duckdb_fetch_record_batch(res)) | ||
| } else { | ||
| duckdb::duckdb_fetch_record_batch(res) | ||
| } | ||
| duckdb::duckdb_fetch_record_batch(res) | ||
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. @jonkeane FYI. See also #11730 (comment) for historical context Member 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. I'm glad we can get this cleaned up 🎉 | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -56,6 +56,7 @@ | ||
| #' | ||
| #' @rdname RecordBatchReader | ||
| #' @name RecordBatchReader | ||
| #' @export | ||
| #' @include arrow-object.R | ||
| #' @examples | ||
| #' tf <- tempfile() | ||
| @@ -104,6 +105,16 @@ RecordBatchReader <- R6Class("RecordBatchReader", | ||
| schema = function() RecordBatchReader__schema(self) | ||
| ) | ||
| ) | ||
| RecordBatchReader$create <- function(..., batches = list(...), schema = NULL) { | ||
nealrichardson marked this conversation as resolved.
Outdated
Uh oh!There was an error while loading. Please reload this page. | ||
| are_batches <- map_lgl(batches, ~ inherits(., "RecordBatch")) | ||
| if (!all(are_batches)) { | ||
| stop( | ||
| "All inputs to RecordBatchReader$create must be RecordBatches", | ||
| call. = FALSE | ||
| ) | ||
| } | ||
| RecordBatchReader__from_batches(batches, schema) | ||
| } | ||
| #' @export | ||
| names.RecordBatchReader <- function(x) names(x$schema) | ||
| @@ -208,13 +219,13 @@ as_record_batch_reader.Table <- function(x, ...) { | ||
| #' @rdname as_record_batch_reader | ||
| #' @export | ||
| as_record_batch_reader.RecordBatch <- function(x, ...) { | ||
| RecordBatchReader__from_batches(list(x), NULL) | ||
| RecordBatchReader$create(x, schema = x$schema) | ||
| } | ||
| #' @rdname as_record_batch_reader | ||
| #' @export | ||
| as_record_batch_reader.data.frame <- function(x, ...) { | ||
| as_record_batch_reader(as_record_batch(x)) | ||
| RecordBatchReader$create(as_record_batch(x)) | ||
| } | ||
| #' @rdname as_record_batch_reader | ||
| @@ -226,8 +237,8 @@ as_record_batch_reader.Dataset <- function(x, ...) { | ||
| #' @rdname as_record_batch_reader | ||
| #' @export | ||
| as_record_batch_reader.arrow_dplyr_query <- function(x, ...) { | ||
| # TODO(ARROW-15271): make ExecPlan return RBR | ||
| as_record_batch_reader(collect.arrow_dplyr_query(x, as_data_frame = FALSE)) | ||
| # TODO(ARROW-16607): use ExecPlan directly when it handles metadata | ||
| as_record_batch_reader(compute.arrow_dplyr_query(x)) | ||
| } | ||
| #' @rdname as_record_batch_reader | ||
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Uh oh!
There was an error while loading. Please reload this page.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Uh oh!
There was an error while loading. Please reload this page.
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.
+1 that would be nice.