From 244ea876b4c73969f72edde0cf413c5e388f1531 Mon Sep 17 00:00:00 2001 From: Maximilian Girlich Date: Tue, 8 Aug 2023 15:30:47 +0200 Subject: [PATCH] Prepare CRAN Release 2.4.0 (#1336) * Add missing `deprecate_warn()` to `src_sql()` * Minor cleanups * Organise NEWS * NEWS polish * Bump minimal R version * Bump dependencies * README * Specify timezone in tests * Add `db_col_types.default()` * Mention minor breaking change in `sql_not_supported()` --- DESCRIPTION | 28 +++---- NEWS.md | 203 +++++++++++++++++++++++++---------------------- R/db.R | 12 ++- R/src-sql.R | 5 ++ R/verb-compute.R | 1 - README.md | 4 +- 6 files changed, 139 insertions(+), 114 deletions(-) diff --git a/DESCRIPTION b/DESCRIPTION index bec53f8ab..e09e029b5 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -17,26 +17,26 @@ License: MIT + file LICENSE URL: https://dbplyr.tidyverse.org/, https://github.com/tidyverse/dbplyr BugReports: https://github.com/tidyverse/dbplyr/issues Depends: - R (>= 3.1) + R (>= 3.6) Imports: blob (>= 1.2.0), - cli (>= 3.4.1), - DBI (>= 1.0.0), - dplyr (>= 1.1.0), - glue (>= 1.2.0), + cli (>= 3.6.1), + DBI (>= 1.1.3), + dplyr (>= 1.1.2), + glue (>= 1.6.2), lifecycle (>= 1.0.3), magrittr, methods, - pillar (>= 1.5.0), + pillar (>= 1.9.0), purrr (>= 1.0.1), R6 (>= 2.2.2), - rlang (>= 1.1.0), - tibble (>= 1.4.2), + rlang (>= 1.1.1), + tibble (>= 3.2.1), tidyr (>= 1.3.0), tidyselect (>= 1.2.0), utils, - vctrs (>= 0.5.2), - withr + vctrs (>= 0.6.3), + withr (>= 2.5.0) Suggests: bit64, covr, @@ -44,12 +44,12 @@ Suggests: Lahman, nycflights13, odbc, - RMariaDB (>= 1.0.2), + RMariaDB (>= 1.2.2), rmarkdown, - RPostgres (>= 1.1.3), + RPostgres (>= 1.4.5), RPostgreSQL, - RSQLite (>= 2.2.15), - testthat (>= 3.0.2) + RSQLite (>= 2.3.1), + testthat (>= 3.1.10) VignetteBuilder: knitr Config/Needs/website: tidyverse/tidytemplate diff --git a/NEWS.md b/NEWS.md index 0ab7f32be..c6a30e8a5 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,20 +1,39 @@ # dbplyr (development version) +* Joins + + * `*_join()` after `full_join()` works again (@mgirlich, #1178). + + * `*_join()` now allows specifying the relationship argument. It must be + `NULL` or `"many-to-many"` (@bairdj, #1305). + + * Queries now qualify `*` with the table alias for better compatibility (@mgirlich, #1003). + + * `full_join()` can now handle column names that only differ in case (@ejneer, #1255). + + * The `na_matches` argument of `semi_join()` and `anti_join()` works again + (@mgirlich, #1211). + + * Joins now work again for Pool and Oracle connections (@mgirlich, #1177, #1181). + * `dbplyr_pivot_wider_spec()` is now exported. Unlike `pivot_wider()` this can be lazy. Note that this will be removed soon after `pivot_wider_spec()` becomes a generic (@mgirlich). -* Added translation for `str_detect()`, `str_starts()` and `str_ends()` with - fixed patterns (@mgirlich, #1009). - -* The `overwrite` argument of `db_copy_to()` now actually works. - -* `db_write_table()` and `db_save_query()` gain the `overwrite` argument. +* `show_query()` and `remote_query()` gain the argument `sql_options` that allows + to control how the SQL is generated. It can be created via `sql_options()` + which has the following arguments: + * `cte`: use common table expressions? + * `use_star`: use `SELECT *` or explicitly select every column? + * `qualify_all_columns`: qualify all columns in a join or only the ambiguous ones? + (@mgirlich, #1146). + +* The `cte` argument of `show_query()` and `remote_query()` is deprecated (@mgirlich, #1146). -* `distinct(.keep_all = TRUE)` now works for SQL Server (@mgirlich, #1053). +## Breaking changes -* `slice_min/max()` can now order by multiple variables like dplyr, e.g. use - `slice_min(lf, tibble(x, y))` (@mgirlich, #1167). +* `remote_name()` now returns a string with the name of the table. To get the + qualified identifier use the newly added `remote_table()` (@mgirlich, #1280). * The functions `simulate_vars()` and `simulate_vars_is_typed()` were removed as they weren't used anymore and tidyselect now offers `tidyselect_data_proxy()` @@ -22,36 +41,37 @@ * `translate_sql()` now requires the `con` argument (@mgirlich, #1311). -* A `semi/anti_join()` where `y` is filtered is now inlined when possible (@mgirlich, #884). +* `sql_query_append()`, `sql_query_insert()`, `sql_query_update()`, + `sql_query_upsert()`, and `sql_query_delete()` changed their arguments to + make them more consistent to the other `sql_query_*()` functions: + + * `x_name` was renamed to `table`. + * `y` was renamed to `from` and must now be a table identifier or SQL instead + of a lazy table. + * `sql_query_append()` and `sql_query_insert()` have gained the argument `cols`. -* `*_join()` now allows using specifying the relationship argument. It must be `NULL` or `"many-to-many"` (@bairdj, #1305). +* The first argument of `ntile()` has been renamed from `order_by` to `x` to + match the interface of `dplyr::ntile()` (@mgirlich, #1242). -* The columns generated when using a window function in `filter()` are now named - `col01` etc. instead of `q01()` (@mgirlich, #1258). +* Removed argument `src` of `tbl_lazy()` after it has been deprecated for years + (@mgirlich, #1208). -* `slice_*()` now supports the data masking pronouns `.env` and `.data` (@mgirlich, #1294). +* Using `compute(temporary = FALSE)` without providing a name is now + deprecated (@mgirlich, #1154). -* `tbl()` now informs when the user probably forgot to wrap the table identifier - with `in_schema()` or `sql()` (@mgirlich, #1287). +* The `vars` argument of `translate_sql()` has been removed after it threw an + error for the last 7 years (@mgirlich). -* Added `db_supports_table_alias_with_as()` to customise whether a backend supports - specifying a table alias with `AS` or not (@mgirlich). +* `sql_not_supported()` now expects a function name without parentheses. -* The translation of `between()` now also works for MS SQL when used in `mutate()` - (@mgirlich, #1241). +## Improved SQL -* MariaDB: - * `rows_update()` and `rows_patch()` now give an informative error when the - unsupported `returning` is used (@mgirlich, #1279). - * `rows_upsert()` now gives an informative error that it isn't supported - (@mgirlich, #1279). - * `rows_*()` use the column types of `x` when auto copying (@mgirlich, #1327). +* A `semi/anti_join()` where `y` is filtered is now inlined when possible (@mgirlich, #884). -* Oracle: - * Fix translation of `rows_upsert()` (@mgirlich, @TBlackmore, #1286) - * `head(n)` is now translated to `WHERE ROWNUM <= n` to also support old - versions <= 11.2 (@JeremyPasco, #1292). +* A sequence of `union()` resp. `union_all()` now produces a flat query + instead of subqueries (@mgirlich, #1269). +## Minor improvements and bug fixes * Teradata: * `as.Date(x)` is now translate to `CAST(x AS DATE)` again unless `x` is a string (@mgirlich, #1285). @@ -59,99 +79,92 @@ * Snowflake: * `na.rm = TRUE` is now respected in `pmin()` and `pmax()` instead of being silently ignored (@fh-mthomson, #1329) -* `remote_name()` now returns a string with the name of the table. To get the - qualified identifier use the newly added `remote_table()` (@mgirlich, #1280). +* The `overwrite` argument of `db_copy_to()` now actually works. -* Queries now qualify `*` with the table alias for better compatibility (@mgirlich, #1003). +* `db_write_table()` and `db_save_query()` gain the `overwrite` argument. -* Joins now work again for Pool and Oracle connections (@mgirlich, #1177, #1181). +* The dots in `db_copy_to()` are now passed to `db_write_table()` (@mgirlich, #1237). -* `show_query()` and `remote_query()` gain the argument `sql_options` that allows - to control how the SQL is generated. It can be created via `sql_options()` - which has the following arguments: - * `cte`: use common table expressions? - * `use_star`: use `SELECT *` or explicitly select every column? - * `qualify_all_columns`: qualify all columns in a join or only the ambiguous ones? - (@mgirlich, #1146). - -* The `cte` argument of `show_query()` and `remote_query()` is deprecated (@mgirlich, #1146). +* Added translation for `str_detect()`, `str_starts()` and `str_ends()` with + fixed patterns (@mgirlich, #1009). -* `any()` and `all()` now work for MS SQL (@ejneer, #1273). +* Added translation for `nzchar()` (@MichaelChirico, @mgirlich, #1094). -* Fixed negation of bit (boolean) fields in MS SQL (@ejneer, #1239) +* Added translation for `runif()` (@mgirlich, #1200). -* A sequence of `union()` resp. `union_all()` now produces a flat query - instead of subqueries (@mgirlich, #1269). +* `sql_random()` is now deprecated. It was used to power `slice_sample()` which + is now done via the translation for `runif()` (@mgirlich, #1200). + +* `nth()`, `first()`, and `last()` now support the `na_rm` argument (@mgirlich, #1193). -* Using `compute(temporary = FALSE)` without providing a name is now - deprecated (@mgirlich, #1154). +* The translation of `if_any()` and `if_all()` is now wrapped in parentheses. + This makes sure it can be combined via `&` with other conditions (@mgirlich, #1153). -* Added translation for `nzchar()` (@MichaelChirico, @mgirlich, #1094). +* `slice_min/max()` can now order by multiple variables like dplyr, e.g. use + `slice_min(lf, tibble(x, y))` (@mgirlich, #1167). -* MySQL/MariaDB: - * Fix translation of `as.numeric()`, `as.POSIXct()`, `as_datetime()`, and - `as.integer64()` (@avsdev-cw, #1189). +* `slice_*()` now supports the data masking pronouns `.env` and `.data` (@mgirlich, #1294). -* `full_join()` can now handle column names that only differ in case (@ejneer, #1255). +* Can now use `select()` again after using `arrange(desc(x))` (@ejneer, #1240). -* Subqueries now also get an alias for SQLite. This makes it consistent with - other backends and simplifies the implementation. +* The columns generated when using a window function in `filter()` are now named + `col01` etc. instead of `q01()` (@mgirlich, #1258). -* The translation of `if_any()` and `if_all()` is now wrapped in parentheses. - This makes sure it can be combined via `&` with other conditions (@mgirlich, #1153). +* `tbl()` now informs when the user probably forgot to wrap the table identifier + with `in_schema()` or `sql()` (@mgirlich, #1287). * `pivot_wider()` now matches tidyr `NA` column handling (@ejneer #1238). * Using a function with a namespace in `across()` now works, e.g. `across(x, dplyr::dense_rank)` (@mgirlich, #1231). -* The dots in `db_copy_to()` are now passed to `db_write_table()` (@mgirlich, #1237). - -* Can now use `select()` again after using `arrange(desc(x))` (@ejneer, #1240). - -* The first argument of `ntile()` has been renamed from `order_by` to `x` to - match the interface of `dplyr::ntile()` (@mgirlich, #1242). - -* Removed argument `src` of `tbl_lazy()` after it has been deprecated for years - (@mgirlich, #1208). - * `sql_join_suffix()` gains the argument `suffix` so that methods can check whether the suffix is valid for the backend (@mgirlich). -* `sql_query_append()`, `sql_query_insert()`, `sql_query_update()`, - `sql_query_upsert()`, and `sql_query_delete()` changed their arguments to - make them more consistent to the other `sql_query_*()` functions: - - * `x_name` was renamed to `table`. - * `y` was renamed to `from` and must now be a table identifier or SQL instead - of a lazy table. - * `sql_query_append()` and `sql_query_insert()` have gained the argument `cols`. - -* The `na_matches` argument of `semi_join()` and `anti_join()` works again - (@mgirlich, #1211). - -* The `vars` argument of `translate_sql()` has been removed after it threw an - error for the last 7 years (@mgirlich). - -* Added translation for `runif()` (@mgirlich, #1200). - -* `sql_random()` is now deprecated. It was used to power `slice_sample()` which - is now done via the translation for `runif()` (@mgirlich, #1200). +* Added `db_supports_table_alias_with_as()` to customise whether a backend supports + specifying a table alias with `AS` or not (@mgirlich). -* DuckDB now supports the `returning` argument of `rows_*()`. +## Backend specific improvements -* `nth()`, `first()`, and `last()` now support the `na_rm` argument (@mgirlich, #1193). +* Access + * Added translation for `!=` to `<>` (@erikvona, #1219). -* `distinct()` + `head()` now work for Teradata (@mgirlich, #685). +* DuckDB + * now supports the `returning` argument of `rows_*()`. -* `copy_inline()` now works for MariaDB (@mgirlich, #1188). +* MySQL/MariaDB: + * `rows_update()` and `rows_patch()` now give an informative error when the + unsupported `returning` argument is used (@mgirlich, #1279). + * `rows_upsert()` now gives an informative error that it isn't supported + (@mgirlich, #1279). + * `rows_*()` use the column types of `x` when auto copying `y` (@mgirlich, #1327). + * `copy_inline()` now works (@mgirlich, #1188). + * Fix translation of `as.numeric()`, `as.POSIXct()`, `as_datetime()`, and + `as.integer64()` (@avsdev-cw, #1189). -* `*_join()` after `full_join()` works again (@mgirlich, #1178). +* Oracle: + * Fix translation of `rows_upsert()` (@mgirlich, @TBlackmore, #1286) + * `head(n)` is now translated to `WHERE ROWNUM <= n` to also support old + versions <= 11.2 (@JeremyPasco, #1292). -* The `rows_*()` functions now also work inside a transaction for Postgres - (@mgirlich, #1183). +* Postgres + * The `rows_*()` functions now also work inside a transaction (@mgirlich, #1183). -* Added translation for `!=` to `<>` for Microsoft Access (@erikvona, #1219). +* SQLite + * Subqueries now also get an alias. This makes it consistent with other + backends and simplifies the implementation. + +* SQL Server + * `distinct(.keep_all = TRUE)` now works (@mgirlich, #1053). + * The translation of `between()` now also works when used in `mutate()` + (@mgirlich, #1241). + * `any()` and `all()` now work (@ejneer, #1273). + * Fixed negation of bit (boolean) fields (@ejneer, #1239) + +* Teradata + * `distinct()` + `head()` now work (@mgirlich, #685). + * `as.Date(x)` is now translate to `CAST(x AS DATE)` again unless `x` is a + string (@mgirlich, #1285). # dbplyr 2.3.3 diff --git a/R/db.R b/R/db.R index 90e8ad1c0..a5d2b4728 100644 --- a/R/db.R +++ b/R/db.R @@ -60,12 +60,14 @@ sql_join_suffix.DBIConnection <- function(con, suffix, ...) { db_sql_render <- function(con, sql, ..., cte = FALSE, sql_options = NULL) { check_bool(cte) if (cte) { - lifecycle::deprecate_soft( + lifecycle::deprecate_soft( when = "2.4.0", what = "db_sql_render(cte)", with = I("db_sql_render(sql_options = sql_options(cte = TRUE))") ) - sql_options <- sql_options(cte = TRUE) + sql_options <- sql_options %||% sql_options(cte = TRUE) + out <- db_sql_render(con, sql, sql_options = sql_options) + return(out) } if (is.null(sql_options)) { @@ -101,6 +103,12 @@ db_col_types.TestConnection <- function(con, table, call) { db_col_types.DBIConnection <- function(con, table, call) { NULL } +# add a default method so that packages that haven't implemented `db_col_types()` +# keep working, e.g. {Pool} +#' @export +db_col_types.default <- function(con, table, call) { + NULL +} #' Options for generating SQL #' diff --git a/R/src-sql.R b/R/src-sql.R index fda913b98..b7739843f 100644 --- a/R/src-sql.R +++ b/R/src-sql.R @@ -12,6 +12,11 @@ #' @param con the connection object #' @param ... fields used by object src_sql <- function(subclass, con, ...) { + lifecycle::deprecate_warn( + when = "1.4.0", + what = "src_sql()", + always = TRUE + ) subclass <- paste0("src_", subclass) structure(list(con = con, ...), class = c(subclass, "src_sql", "src")) } diff --git a/R/verb-compute.R b/R/verb-compute.R index aad3dba7d..1303e82b8 100644 --- a/R/verb-compute.R +++ b/R/verb-compute.R @@ -45,7 +45,6 @@ compute.tbl_sql <- function(x, if (!temporary) { lifecycle::deprecate_warn( "2.3.3", - # what = I(cli::format_inline("Not providing a name when {.code temporary = FALSE}")) what = "compute(name = 'must be provided when `temporary = FALSE`')" ) } diff --git a/README.md b/README.md index 26465fc43..bea5e4171 100755 --- a/README.md +++ b/README.md @@ -62,7 +62,7 @@ details). Printing it just retrieves the first few rows: mtcars2 <- tbl(con, "mtcars") mtcars2 #> # Source: table [?? x 11] -#> # Database: sqlite 3.40.1 [:memory:] +#> # Database: sqlite 3.41.2 [:memory:] #> mpg cyl disp hp drat wt qsec vs am gear carb #> #> 1 21 6 160 110 3.9 2.62 16.5 0 1 4 4 @@ -75,7 +75,7 @@ mtcars2 #> 8 24.4 4 147. 62 3.69 3.19 20 1 0 4 2 #> 9 22.8 4 141. 95 3.92 3.15 22.9 1 0 4 2 #> 10 19.2 6 168. 123 3.92 3.44 18.3 1 0 4 4 -#> # … with more rows +#> # ℹ more rows ``` All dplyr calls are evaluated lazily, generating SQL that is only sent