Skip to content

Commit

Permalink
Don't duplicate grouping variables in distinct
Browse files Browse the repository at this point in the history
Fixes #354
  • Loading branch information
hadley committed Sep 24, 2020
1 parent 0bf2176 commit 74260eb
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 1 deletion.
2 changes: 2 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# dbplyr (development version)

* `distinct()` no longer duplicates column if grouped (#354).

* `mutate()` grouping variables no longer generates a downstream error (#396)

* `mutate()` correctly generates subqueries when you re-use the same variable
Expand Down
2 changes: 1 addition & 1 deletion R/verb-distinct.R
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ distinct.tbl_lazy <- function(.data, ..., .keep_all = FALSE) {

#' @export
op_vars.op_distinct <- function(op) {
c(op_grps(op$x), op_vars(op$x))
union(op_grps(op$x), op_vars(op$x))
}

#' @export
Expand Down
5 changes: 5 additions & 0 deletions tests/testthat/test-verb-distinct.R
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,11 @@ test_that("distinct throws error if column is specified and .keep_all is TRUE",
expect_snapshot_error(mf %>% distinct(x, .keep_all = TRUE) %>% collect())
})

test_that("distinct doesn't duplicate colum names if grouped (#354)", {
df <- lazy_frame(a = 1)
expect_equal(df %>% group_by(a) %>% distinct() %>% op_vars(), "a")
})

# sql-render --------------------------------------------------------------

test_that("distinct adds DISTINCT suffix", {
Expand Down

0 comments on commit 74260eb

Please sign in to comment.