Skip to content

Commit

Permalink
Merge pull request duckdb#158 from lschneiderbauer/n_distinct_followup
Browse files Browse the repository at this point in the history
  • Loading branch information
krlmlr authored May 27, 2024
2 parents 40d6c8f + 2476d20 commit 56004c8
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 0 deletions.
6 changes: 6 additions & 0 deletions R/backend-dbplyr__duckdb_connection.R
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,12 @@ duckdb_grepl <- function(pattern, x, ignore.case = FALSE, perl = FALSE, fixed =

duckdb_n_distinct <- function(..., na.rm = FALSE) {
sql <- pkg_method("sql", "dbplyr")
check_dots_unnamed <- pkg_method("check_dots_unnamed", "rlang")

if (missing(...)) {
stop("`...` is absent, but must be supplied.")
}
check_dots_unnamed()

if (!identical(na.rm, FALSE)) {
stop("Parameter `na.rm = TRUE` in n_distinct() is currently not supported in DuckDB backend.", call. = FALSE)
Expand Down
6 changes: 6 additions & 0 deletions tests/testthat/test-backend-dbplyr__duckdb_connection.R
Original file line number Diff line number Diff line change
Expand Up @@ -284,6 +284,7 @@ test_that("n_distinct() computations are correct", {
on.exit(dbDisconnect(con, shutdown = TRUE))
tbl <- dplyr::tbl
summarize <- dplyr::summarize
mutate <- dplyr::mutate
pull <- dplyr::pull

duckdb_register(con, "df", data.frame(x = c(1, 1, 2, 2), y = c(1, 2, 2, 2)))
Expand Down Expand Up @@ -318,6 +319,11 @@ test_that("n_distinct() computations are correct", {
pull(summarize(df_na, n = n_distinct(x, y)), n),
5
)

expect_equal(
pull(mutate(df_na, n = n_distinct(x, y)), n),
rep(5, 5)
)
})


Expand Down

0 comments on commit 56004c8

Please sign in to comment.