diff --git a/NAMESPACE b/NAMESPACE index 0817718..cdaf3bf 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -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) @@ -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) diff --git a/NEWS.md b/NEWS.md index e3ed14a..c1da8a9 100644 --- a/NEWS.md +++ b/NEWS.md @@ -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. diff --git a/R/DBI-wrap.R b/R/DBI-wrap.R index a20fb83..6505b28 100644 --- a/R/DBI-wrap.R +++ b/R/DBI-wrap.R @@ -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")) diff --git a/R/dbplyr.R b/R/dbplyr.R index 972abd8..d189e75 100644 --- a/R/dbplyr.R +++ b/R/dbplyr.R @@ -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) } @@ -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)) @@ -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() { diff --git a/man/DBI-wrap.Rd b/man/DBI-wrap.Rd index aca1f35..f9b0551 100644 --- a/man/DBI-wrap.Rd +++ b/man/DBI-wrap.Rd @@ -24,6 +24,12 @@ \alias{dbUnquoteIdentifier,Pool-method} \alias{dbQuoteLiteral,Pool-method} \alias{dbQuoteString,Pool,ANY-method} +\alias{dbAppendTableArrow,Pool-method} +\alias{dbCreateTableArrow,Pool-method} +\alias{dbGetQueryArrow,Pool-method} +\alias{dbReadTableArrow,Pool-method} +\alias{dbSendQueryArrow,Pool-method} +\alias{dbWriteTableArrow,Pool-method} \title{DBI methods (simple wrappers)} \usage{ \S4method{dbDataType}{Pool}(dbObj, obj, ...) @@ -69,6 +75,18 @@ \S4method{dbQuoteLiteral}{Pool}(conn, x, ...) \S4method{dbQuoteString}{Pool,ANY}(conn, x, ...) + +\S4method{dbAppendTableArrow}{Pool}(conn, name, value, ...) + +\S4method{dbCreateTableArrow}{Pool}(conn, name, value, ...) + +\S4method{dbGetQueryArrow}{Pool}(conn, statement, ...) + +\S4method{dbReadTableArrow}{Pool}(conn, name, ...) + +\S4method{dbSendQueryArrow}{Pool}(conn, statement, ...) + +\S4method{dbWriteTableArrow}{Pool}(conn, name, value, ...) } \description{ These pool method for DBI generics methods check out a connection diff --git a/man/tbl.Pool.Rd b/man/tbl.Pool.Rd index 521b785..1375c8e 100644 --- a/man/tbl.Pool.Rd +++ b/man/tbl.Pool.Rd @@ -7,14 +7,7 @@ \usage{ tbl.Pool(src, from, ..., vars = NULL) -copy_to.Pool( - dest, - df, - name = deparse(substitute(df)), - overwrite = FALSE, - temporary = TRUE, - ... -) +copy_to.Pool(dest, df, name = NULL, overwrite = FALSE, temporary = TRUE, ...) } \arguments{ \item{src, dest}{A \link{dbPool}.} @@ -31,7 +24,8 @@ from another source. If from another source, all data must transition through R in one pass, so it is only suitable for transferring small amounts of data.} -\item{name}{name for new remote table.} +\item{name}{Name for remote table. Defaults to the name of \code{df}, if it's +an identifier, otherwise uses a random name.} \item{overwrite}{If \code{TRUE}, will overwrite an existing table with name \code{name}. If \code{FALSE}, will throw an error if \code{name} already diff --git a/tests/testthat/_snaps/dbplyr.md b/tests/testthat/_snaps/dbplyr.md index 0fcea16..6bc0b97 100644 --- a/tests/testthat/_snaps/dbplyr.md +++ b/tests/testthat/_snaps/dbplyr.md @@ -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) } diff --git a/tests/testthat/test-dbplyr.R b/tests/testthat/test-dbplyr.R index f0bdcab..4db3b3c 100644 --- a/tests/testthat/test-dbplyr.R +++ b/tests/testthat/test-dbplyr.R @@ -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()