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-14745: [R] Enable true duckdb streaming#11730
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
9cbf065b99e361495d489e418f1f138c689f21e3645b065be2c77276aa84d12f5d1ed69c56ed0115d651ec1b8c3File 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 | ||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -104,12 +104,11 @@ unique_arrow_tablename <- function() { | ||||||||||||||||||||||
| # Creates an environment that disconnects the database when it's GC'd | ||||||||||||||||||||||
| duckdb_disconnector <- function(con, tbl_name) { | ||||||||||||||||||||||
| force(tbl_name) | ||||||||||||||||||||||
| reg.finalizer(environment(), function(...) { | ||||||||||||||||||||||
| # remote the table we ephemerally created (though only if the connection is | ||||||||||||||||||||||
| # still valid) | ||||||||||||||||||||||
| if (DBI::dbIsValid(con)) { | ||||||||||||||||||||||
| duckdb::duckdb_unregister_arrow(con, tbl_name) | ||||||||||||||||||||||
| } | ||||||||||||||||||||||
| duckdb::duckdb_unregister_arrow(con, tbl_name) | ||||||||||||||||||||||
| }) | ||||||||||||||||||||||
| environment() | ||||||||||||||||||||||
| } | ||||||||||||||||||||||
| @@ -120,8 +119,11 @@ 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 an `arrow_dplyr_query` object, to be used in dplyr pipelines. | ||||||||||||||||||||||
| #' @return a `RecordBatchReader` object, wrapped as an arrow dplyr query which | ||||||||||||||||||||||
| #' can be used in dplyr pipelines. | ||||||||||||||||||||||
| #' @export | ||||||||||||||||||||||
| #' | ||||||||||||||||||||||
| #' @examplesIf getFromNamespace("run_duckdb_examples", "arrow")() | ||||||||||||||||||||||
| @@ -136,7 +138,7 @@ duckdb_disconnector <- function(con, tbl_name) { | ||||||||||||||||||||||
| #' summarize(mean_mpg = mean(mpg, na.rm = TRUE)) %>% | ||||||||||||||||||||||
| #' to_arrow() %>% | ||||||||||||||||||||||
| #' collect() | ||||||||||||||||||||||
| to_arrow <- function(.data) { | ||||||||||||||||||||||
| to_arrow <- function(.data, as_arrow_query = TRUE) { | ||||||||||||||||||||||
| # If this is an Arrow object already, return quickly since we're already Arrow | ||||||||||||||||||||||
| if (inherits(.data, c("arrow_dplyr_query", "ArrowObject"))) { | ||||||||||||||||||||||
| return(.data) | ||||||||||||||||||||||
| @@ -155,6 +157,9 @@ to_arrow <- function(.data) { | ||||||||||||||||||||||
| # Run the query | ||||||||||||||||||||||
| res <- DBI::dbSendQuery(dbplyr::remote_con(.data), dbplyr::remote_query(.data), arrow = TRUE) | ||||||||||||||||||||||
| # TODO: we shouldn't need $read_table(), but we get segfaults when we do. | ||||||||||||||||||||||
| arrow_dplyr_query(duckdb::duckdb_fetch_record_batch(res)$read_table()) | ||||||||||||||||||||||
| if (as_arrow_query) { | ||||||||||||||||||||||
| arrow_dplyr_query(duckdb::duckdb_fetch_record_batch(res)) | ||||||||||||||||||||||
| } else { | ||||||||||||||||||||||
| duckdb::duckdb_fetch_record_batch(res) | ||||||||||||||||||||||
| } | ||||||||||||||||||||||
Comment on lines
+160
to
+164
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.
Suggested change
| ||||||||||||||||||||||
| } | ||||||||||||||||||||||
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.
How useful is this argument?
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.
Probably (and hopefully) not very, but I wanted to have an escape route in case we see another issue like at the start of this PR where
duckdb::duckdb_fetch_record_batch(res)fails, butduckdb::duckdb_fetch_record_batch(res)$read_table()works (over time, the DuckDB master branch got into a state where both failed consistently, but at the beginning reading the table worked just fine, but accessing the RBR did not. And since we are at the mercy of both of our release cycles for fixing this, the cost of having this escape hatch doesn't seem so bad to me, but I can remove it.It also helps a bit when debugging / testing (one doesn't have to recreate
to_arrow()without the wrapper).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.
You can get the RBR from
$.datain the query object, is that sufficient for debugging purposes?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.
Oh nm, it gets wrapped in a InMemoryDataset. Alright, I don't like this but this is fine, we can prune it later.
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.
I could also mark it is a temporary workaround for when we simplify this in the future? It's a little silly to effectively say "this is deprecated" when we introduce it, but I'm not sure when we'll get to doing the simplification + improvements so this can simply emit RBRs and those have the right signaling/methods so that it's clear that they are a good thing to use in dplyr queries
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.
I think
to_arrow()is a good fit...it gives the thing that a user probably wants. A possible futureas_record_batch_reader()would be the right incantation for a user who wants it!