Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions R/pkg/NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -341,5 +341,5 @@ export("partitionBy",
"rowsBetween",
"rangeBetween")

export("window.partitionBy",
"window.orderBy")
export("windowPartitionBy",
"windowOrderBy")
4 changes: 2 additions & 2 deletions R/pkg/R/WindowSpec.R
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,10 @@ NULL

#' S4 class that represents a WindowSpec
#'
#' WindowSpec can be created by using window.partitionBy() or window.orderBy()
#' WindowSpec can be created by using windowPartitionBy() or windowOrderBy()
#'
#' @rdname WindowSpec
#' @seealso \link{window.partitionBy}, \link{window.orderBy}
#' @seealso \link{windowPartitionBy}, \link{windowOrderBy}
#'
#' @param sws A Java object reference to the backing Scala WindowSpec
#' @export
Expand Down
8 changes: 4 additions & 4 deletions R/pkg/R/generics.R
Original file line number Diff line number Diff line change
Expand Up @@ -779,13 +779,13 @@ setGeneric("rowsBetween", function(x, start, end) { standardGeneric("rowsBetween
#' @export
setGeneric("rangeBetween", function(x, start, end) { standardGeneric("rangeBetween") })

#' @rdname window.partitionBy
#' @rdname windowPartitionBy
#' @export
setGeneric("window.partitionBy", function(col, ...) { standardGeneric("window.partitionBy") })
setGeneric("windowPartitionBy", function(col, ...) { standardGeneric("windowPartitionBy") })

#' @rdname window.orderBy
#' @rdname windowOrderBy
#' @export
setGeneric("window.orderBy", function(col, ...) { standardGeneric("window.orderBy") })
setGeneric("windowOrderBy", function(col, ...) { standardGeneric("windowOrderBy") })

###################### Expression Function Methods ##########################

Expand Down
54 changes: 32 additions & 22 deletions R/pkg/R/window.R
Original file line number Diff line number Diff line change
Expand Up @@ -17,23 +17,28 @@

# window.R - Utility functions for defining window in DataFrames

#' window.partitionBy
#' windowPartitionBy
#'
#' Creates a WindowSpec with the partitioning defined.
#'
#' @rdname window.partitionBy
#' @name window.partitionBy
#' @param col A column name or Column by which rows are partitioned to
#' windows.
#' @param ... Optional column names or Columns in addition to col, by
#' which rows are partitioned to windows.
#'
#' @rdname windowPartitionBy
#' @name windowPartitionBy
#' @export
#' @examples
#' \dontrun{
#' ws <- window.partitionBy("key1", "key2")
#' ws <- windowPartitionBy("key1", "key2")
#' df1 <- select(df, over(lead("value", 1), ws))
#'
#' ws <- window.partitionBy(df$key1, df$key2)
#' ws <- windowPartitionBy(df$key1, df$key2)
#' df1 <- select(df, over(lead("value", 1), ws))
#' }
#' @note window.partitionBy(character) since 2.0.0
setMethod("window.partitionBy",
#' @note windowPartitionBy(character) since 2.0.0
setMethod("windowPartitionBy",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

minor comment: Can we document the parameter @param col that is in all the 4 functions ? That'll also remove some of the CRAN warnings

signature(col = "character"),
function(col, ...) {
windowSpec(
Expand All @@ -43,11 +48,11 @@ setMethod("window.partitionBy",
list(...)))
})

#' @rdname window.partitionBy
#' @name window.partitionBy
#' @rdname windowPartitionBy
#' @name windowPartitionBy
#' @export
#' @note window.partitionBy(Column) since 2.0.0
setMethod("window.partitionBy",
#' @note windowPartitionBy(Column) since 2.0.0
setMethod("windowPartitionBy",
signature(col = "Column"),
function(col, ...) {
jcols <- lapply(list(col, ...), function(c) {
Expand All @@ -59,23 +64,28 @@ setMethod("window.partitionBy",
jcols))
})

#' window.orderBy
#' windowOrderBy
#'
#' Creates a WindowSpec with the ordering defined.
#'
#' @rdname window.orderBy
#' @name window.orderBy
#' @param col A column name or Column by which rows are ordered within
#' windows.
#' @param ... Optional column names or Columns in addition to col, by
#' which rows are ordered within windows.
#'
#' @rdname windowOrderBy
#' @name windowOrderBy
#' @export
#' @examples
#' \dontrun{
#' ws <- window.orderBy("key1", "key2")
#' ws <- windowOrderBy("key1", "key2")
#' df1 <- select(df, over(lead("value", 1), ws))
#'
#' ws <- window.orderBy(df$key1, df$key2)
#' ws <- windowOrderBy(df$key1, df$key2)
#' df1 <- select(df, over(lead("value", 1), ws))
#' }
#' @note window.orderBy(character) since 2.0.0
setMethod("window.orderBy",
#' @note windowOrderBy(character) since 2.0.0
setMethod("windowOrderBy",
signature(col = "character"),
function(col, ...) {
windowSpec(
Expand All @@ -85,11 +95,11 @@ setMethod("window.orderBy",
list(...)))
})

#' @rdname window.orderBy
#' @name window.orderBy
#' @rdname windowOrderBy
#' @name windowOrderBy
#' @export
#' @note window.orderBy(Column) since 2.0.0
setMethod("window.orderBy",
#' @note windowOrderBy(Column) since 2.0.0
setMethod("windowOrderBy",
signature(col = "Column"),
function(col, ...) {
jcols <- lapply(list(col, ...), function(c) {
Expand Down
8 changes: 4 additions & 4 deletions R/pkg/inst/tests/testthat/test_sparkSQL.R
Original file line number Diff line number Diff line change
Expand Up @@ -2376,25 +2376,25 @@ test_that("gapply() and gapplyCollect() on a DataFrame", {
test_that("Window functions on a DataFrame", {
df <- createDataFrame(list(list(1L, "1"), list(2L, "2"), list(1L, "1"), list(2L, "2")),
schema = c("key", "value"))
ws <- orderBy(window.partitionBy("key"), "value")
ws <- orderBy(windowPartitionBy("key"), "value")
result <- collect(select(df, over(lead("key", 1), ws), over(lead("value", 1), ws)))
names(result) <- c("key", "value")
expected <- data.frame(key = c(1L, NA, 2L, NA),
value = c("1", NA, "2", NA),
stringsAsFactors = FALSE)
expect_equal(result, expected)

ws <- orderBy(window.partitionBy(df$key), df$value)
ws <- orderBy(windowPartitionBy(df$key), df$value)
result <- collect(select(df, over(lead("key", 1), ws), over(lead("value", 1), ws)))
names(result) <- c("key", "value")
expect_equal(result, expected)

ws <- partitionBy(window.orderBy("value"), "key")
ws <- partitionBy(windowOrderBy("value"), "key")
result <- collect(select(df, over(lead("key", 1), ws), over(lead("value", 1), ws)))
names(result) <- c("key", "value")
expect_equal(result, expected)

ws <- partitionBy(window.orderBy(df$value), df$key)
ws <- partitionBy(windowOrderBy(df$value), df$key)
result <- collect(select(df, over(lead("key", 1), ws), over(lead("value", 1), ws)))
names(result) <- c("key", "value")
expect_equal(result, expected)
Expand Down