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
8 changes: 4 additions & 4 deletions R/pkg/NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -123,14 +123,14 @@ exportMethods("%in%",
"count",
"countDistinct",
"crc32",
"cumeDist",
"cume_dist",
"date_add",
"date_format",
"date_sub",
"datediff",
"dayofmonth",
"dayofyear",
"denseRank",
"dense_rank",
"desc",
"endsWith",
"exp",
Expand Down Expand Up @@ -188,7 +188,7 @@ exportMethods("%in%",
"next_day",
"ntile",
"otherwise",
"percentRank",
"percent_rank",
"pmod",
"quarter",
"rand",
Expand All @@ -200,7 +200,7 @@ exportMethods("%in%",
"rint",
"rlike",
"round",
"rowNumber",
"row_number",
"rpad",
"rtrim",
"second",
Expand Down
54 changes: 27 additions & 27 deletions R/pkg/R/functions.R
Original file line number Diff line number Diff line change
Expand Up @@ -2146,47 +2146,47 @@ setMethod("ifelse",

###################### Window functions######################

#' cumeDist
#' cume_dist
#'
#' Window function: returns the cumulative distribution of values within a window partition,
#' i.e. the fraction of rows that are below the current row.
#'
#' N = total number of rows in the partition
#' cumeDist(x) = number of values before (and including) x / N
#' cume_dist(x) = number of values before (and including) x / N
#'
#' This is equivalent to the CUME_DIST function in SQL.
#'
#' @rdname cumeDist
#' @name cumeDist
#' @rdname cume_dist
#' @name cume_dist
#' @family window_funcs
#' @export
#' @examples \dontrun{cumeDist()}
setMethod("cumeDist",
#' @examples \dontrun{cume_dist()}
setMethod("cume_dist",
signature(x = "missing"),
function() {
jc <- callJStatic("org.apache.spark.sql.functions", "cumeDist")
jc <- callJStatic("org.apache.spark.sql.functions", "cume_dist")
column(jc)
})

#' denseRank
#' dense_rank
#'
#' Window function: returns the rank of rows within a window partition, without any gaps.
#' The difference between rank and denseRank is that denseRank leaves no gaps in ranking
#' sequence when there are ties. That is, if you were ranking a competition using denseRank
#' The difference between rank and dense_rank is that dense_rank leaves no gaps in ranking
#' sequence when there are ties. That is, if you were ranking a competition using dense_rank
#' and had three people tie for second place, you would say that all three were in second
#' place and that the next person came in third.
#'
#' This is equivalent to the DENSE_RANK function in SQL.
#'
#' @rdname denseRank
#' @name denseRank
#' @rdname dense_rank
#' @name dense_rank
#' @family window_funcs
#' @export
#' @examples \dontrun{denseRank()}
setMethod("denseRank",
#' @examples \dontrun{dense_rank()}
setMethod("dense_rank",
signature(x = "missing"),
function() {
jc <- callJStatic("org.apache.spark.sql.functions", "denseRank")
jc <- callJStatic("org.apache.spark.sql.functions", "dense_rank")
column(jc)
})

Expand Down Expand Up @@ -2264,7 +2264,7 @@ setMethod("ntile",
column(jc)
})

#' percentRank
#' percent_rank
#'
#' Window function: returns the relative rank (i.e. percentile) of rows within a window partition.
#'
Expand All @@ -2274,15 +2274,15 @@ setMethod("ntile",
#'
#' This is equivalent to the PERCENT_RANK function in SQL.
#'
#' @rdname percentRank
#' @name percentRank
#' @rdname percent_rank
#' @name percent_rank
#' @family window_funcs
#' @export
#' @examples \dontrun{percentRank()}
setMethod("percentRank",
#' @examples \dontrun{percent_rank()}
setMethod("percent_rank",
signature(x = "missing"),
function() {
jc <- callJStatic("org.apache.spark.sql.functions", "percentRank")
jc <- callJStatic("org.apache.spark.sql.functions", "percent_rank")
column(jc)
})

Expand Down Expand Up @@ -2316,21 +2316,21 @@ setMethod("rank",
base::rank(x, ...)
})

#' rowNumber
#' row_number
#'
#' Window function: returns a sequential number starting at 1 within a window partition.
#'
#' This is equivalent to the ROW_NUMBER function in SQL.
#'
#' @rdname rowNumber
#' @name rowNumber
#' @rdname row_number
#' @name row_number
#' @family window_funcs
#' @export
#' @examples \dontrun{rowNumber()}
setMethod("rowNumber",
#' @examples \dontrun{row_number()}
setMethod("row_number",
signature(x = "missing"),
function() {
jc <- callJStatic("org.apache.spark.sql.functions", "rowNumber")
jc <- callJStatic("org.apache.spark.sql.functions", "row_number")
column(jc)
})

Expand Down
16 changes: 8 additions & 8 deletions R/pkg/R/generics.R
Original file line number Diff line number Diff line change
Expand Up @@ -700,9 +700,9 @@ setGeneric("countDistinct", function(x, ...) { standardGeneric("countDistinct")
#' @export
setGeneric("crc32", function(x) { standardGeneric("crc32") })

#' @rdname cumeDist
#' @rdname cume_dist
#' @export
setGeneric("cumeDist", function(x) { standardGeneric("cumeDist") })
setGeneric("cume_dist", function(x) { standardGeneric("cume_dist") })

#' @rdname datediff
#' @export
Expand All @@ -728,9 +728,9 @@ setGeneric("dayofmonth", function(x) { standardGeneric("dayofmonth") })
#' @export
setGeneric("dayofyear", function(x) { standardGeneric("dayofyear") })

#' @rdname denseRank
#' @rdname dense_rank
#' @export
setGeneric("denseRank", function(x) { standardGeneric("denseRank") })
setGeneric("dense_rank", function(x) { standardGeneric("dense_rank") })

#' @rdname explode
#' @export
Expand Down Expand Up @@ -872,9 +872,9 @@ setGeneric("ntile", function(x) { standardGeneric("ntile") })
#' @export
setGeneric("n_distinct", function(x, ...) { standardGeneric("n_distinct") })

#' @rdname percentRank
#' @rdname percent_rank
#' @export
setGeneric("percentRank", function(x) { standardGeneric("percentRank") })
setGeneric("percent_rank", function(x) { standardGeneric("percent_rank") })

#' @rdname pmod
#' @export
Expand Down Expand Up @@ -913,9 +913,9 @@ setGeneric("reverse", function(x) { standardGeneric("reverse") })
#' @export
setGeneric("rint", function(x, ...) { standardGeneric("rint") })

#' @rdname rowNumber
#' @rdname row_number
#' @export
setGeneric("rowNumber", function(x) { standardGeneric("rowNumber") })
setGeneric("row_number", function(x) { standardGeneric("row_number") })

#' @rdname rpad
#' @export
Expand Down
4 changes: 2 additions & 2 deletions R/pkg/inst/tests/test_sparkSQL.R
Original file line number Diff line number Diff line change
Expand Up @@ -861,8 +861,8 @@ test_that("column functions", {
c11 <- to_date(c) + trim(c) + unbase64(c) + unhex(c) + upper(c)
c12 <- variance(c)
c13 <- lead("col", 1) + lead(c, 1) + lag("col", 1) + lag(c, 1)
c14 <- cumeDist() + ntile(1)
c15 <- denseRank() + percentRank() + rank() + rowNumber()
c14 <- cume_dist() + ntile(1)
c15 <- dense_rank() + percent_rank() + rank() + row_number()

# Test if base::rank() is exposed
expect_equal(class(rank())[[1]], "Column")
Expand Down