Skip to content

Commit

Permalink
Updates for changes to dependencies (#174)
Browse files Browse the repository at this point in the history
* Update wrapped dbplyr function
* Wrap arrow generics
* Fix `in_schema()` messages
  • Loading branch information
hadley authored Jan 11, 2024
1 parent 11ef163 commit 8ce7c0b
Show file tree
Hide file tree
Showing 8 changed files with 82 additions and 15 deletions.
6 changes: 6 additions & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,18 @@ export(poolReturn)
export(poolWithTransaction)
exportClasses(Pool)
exportMethods(dbAppendTable)
exportMethods(dbAppendTableArrow)
exportMethods(dbBegin)
exportMethods(dbCommit)
exportMethods(dbCreateTable)
exportMethods(dbCreateTableArrow)
exportMethods(dbDataType)
exportMethods(dbDisconnect)
exportMethods(dbExecute)
exportMethods(dbExistsTable)
exportMethods(dbGetInfo)
exportMethods(dbGetQuery)
exportMethods(dbGetQueryArrow)
exportMethods(dbIsReadOnly)
exportMethods(dbIsValid)
exportMethods(dbListFields)
Expand All @@ -33,13 +36,16 @@ exportMethods(dbQuoteIdentifier)
exportMethods(dbQuoteLiteral)
exportMethods(dbQuoteString)
exportMethods(dbReadTable)
exportMethods(dbReadTableArrow)
exportMethods(dbRemoveTable)
exportMethods(dbRollback)
exportMethods(dbSendQuery)
exportMethods(dbSendQueryArrow)
exportMethods(dbSendStatement)
exportMethods(dbUnquoteIdentifier)
exportMethods(dbWithTransaction)
exportMethods(dbWriteTable)
exportMethods(dbWriteTableArrow)
exportMethods(onActivate)
exportMethods(onDestroy)
exportMethods(onPassivate)
Expand Down
5 changes: 5 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
# pool (development version)

* Pool no longer generates spurious messages about needing to use
`in_schema()` or avoiding the use of `ident_q()`.

* Add support for new DBI generics that return Arrow objects.

# pool 1.0.1

* `copy_to()` now returns a tbl that uses the Pool.
Expand Down
24 changes: 24 additions & 0 deletions R/DBI-wrap.R
Original file line number Diff line number Diff line change
Expand Up @@ -164,3 +164,27 @@ setMethod("dbQuoteLiteral", "Pool", DBI_wrap("dbQuoteLiteral"))
#' @export
#' @rdname DBI-wrap
setMethod("dbQuoteString", "Pool", DBI_wrap("dbQuoteString"))

#' @export
#' @rdname DBI-wrap
setMethod("dbAppendTableArrow", "Pool", DBI_wrap("dbAppendTableArrow"))

#' @export
#' @rdname DBI-wrap
setMethod("dbCreateTableArrow", "Pool", DBI_wrap("dbCreateTableArrow"))

#' @export
#' @rdname DBI-wrap
setMethod("dbGetQueryArrow", "Pool", DBI_wrap("dbGetQueryArrow"))

#' @export
#' @rdname DBI-wrap
setMethod("dbReadTableArrow", "Pool", DBI_wrap("dbReadTableArrow"))

#' @export
#' @rdname DBI-wrap
setMethod("dbSendQueryArrow", "Pool", DBI_wrap("dbSendQueryArrow"))

#' @export
#' @rdname DBI-wrap
setMethod("dbWriteTableArrow", "Pool", DBI_wrap("dbWriteTableArrow"))
21 changes: 19 additions & 2 deletions R/dbplyr.R
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ tbl.Pool <- function(src, from, ..., vars = NULL) {
con <- poolCheckout(src)
on.exit(poolReturn(con))

from <- dbplyr::as.sql(from, con)
if (is.null(vars)) {
vars <- dplyr::db_query_fields(con, from)
}
Expand All @@ -35,15 +34,26 @@ tbl.Pool <- function(src, from, ..., vars = NULL) {
}

#' @rdname tbl.Pool
#' @param name Name for remote table. Defaults to the name of `df`, if it's
#' an identifier, otherwise uses a random name.
#' @inheritParams dbplyr::copy_to.src_sql
copy_to.Pool <- function(dest,
df,
name = deparse(substitute(df)),
name = NULL,
overwrite = FALSE,
temporary = TRUE,
...) {
stop_if_temporary(temporary)

if (is.null(name)) {
name <- substitute(df)
if (is_symbol(name)) {
name <- deparse(name)
} else {
name <- random_table_name()
}
}

local({
db_con <- poolCheckout(dest)
on.exit(poolReturn(db_con))
Expand All @@ -61,6 +71,13 @@ copy_to.Pool <- function(dest,
tbl.Pool(dest, name)
}

random_table_name <- function(prefix = "") {
vals <- c(letters, LETTERS, 0:9)
name <- paste0(sample(vals, 10, replace = TRUE), collapse = "")
paste0(prefix, "pool_", name)
}


# Lazily registered wrapped functions ------------------------------------------

dbplyr_register_methods <- function() {
Expand Down
18 changes: 18 additions & 0 deletions man/DBI-wrap.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 3 additions & 9 deletions man/tbl.Pool.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 6 additions & 4 deletions tests/testthat/_snaps/dbplyr.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,15 +45,17 @@
# with temporary argument
dbplyr_wrap("db_compute")
Output
function (con, table, sql, temporary = TRUE, unique_indexes = list(),
indexes = list(), analyze = TRUE, ...)
function (con, table, sql, ..., overwrite = FALSE, temporary = TRUE,
unique_indexes = list(), indexes = list(), analyze = TRUE,
in_transaction = TRUE)
{
stop_if_temporary(temporary)
db_con <- poolCheckout(con)
on.exit(poolReturn(db_con))
dbplyr::db_compute(con = db_con, table = table, sql = sql,
temporary = temporary, unique_indexes = unique_indexes,
indexes = indexes, analyze = analyze, ... = ...)
... = ..., overwrite = overwrite, temporary = temporary,
unique_indexes = unique_indexes, indexes = indexes, analyze = analyze,
in_transaction = in_transaction)
}
<environment: namespace:pool>

1 change: 1 addition & 0 deletions tests/testthat/test-dbplyr.R
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ test_that("can explain", {
db <- dplyr::copy_to(pool, data.frame(x = 1), temporary = FALSE)
expect_output(dplyr::explain(db))
})

test_that("can use schemas with pool", {
pool <- local_db_pool()

Expand Down

0 comments on commit 8ce7c0b

Please sign in to comment.