Skip to content

Commit 3118c22

Browse files
zero323dongjoon-hyun
authored andcommitted
[SPARK-32949][R][SQL] Add timestamp_seconds to SparkR
### What changes were proposed in this pull request? This PR adds R wrapper for `timestamp_seconds` function. ### Why are the changes needed? Feature parity. ### Does this PR introduce _any_ user-facing change? Yes, it adds a new R function. ### How was this patch tested? New unit tests. Closes #29822 from zero323/SPARK-32949. Authored-by: zero323 <[email protected]> Signed-off-by: Dongjoon Hyun <[email protected]>
1 parent f03c035 commit 3118c22

4 files changed

Lines changed: 21 additions & 0 deletions

File tree

R/pkg/NAMESPACE

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -405,6 +405,7 @@ exportMethods("%<=>%",
405405
"sumDistinct",
406406
"tan",
407407
"tanh",
408+
"timestamp_seconds",
408409
"toDegrees",
409410
"toRadians",
410411
"to_csv",

R/pkg/R/functions.R

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4407,3 +4407,18 @@ setMethod("current_timestamp",
44074407
jc <- callJStatic("org.apache.spark.sql.functions", "current_timestamp")
44084408
column(jc)
44094409
})
4410+
4411+
#' @details
4412+
#' \code{timestamp_seconds}: Creates timestamp from the number of seconds since UTC epoch.
4413+
#'
4414+
#' @rdname column_datetime_functions
4415+
#' @aliases timestamp_seconds timestamp_seconds,Column-method
4416+
#' @note timestamp_seconds since 3.1.0
4417+
setMethod("timestamp_seconds",
4418+
signature(x = "Column"),
4419+
function(x) {
4420+
jc <- callJStatic(
4421+
"org.apache.spark.sql.functions", "timestamp_seconds", x@jc
4422+
)
4423+
column(jc)
4424+
})

R/pkg/R/generics.R

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1357,6 +1357,10 @@ setGeneric("substring_index", function(x, delim, count) { standardGeneric("subst
13571357
#' @name NULL
13581358
setGeneric("sumDistinct", function(x) { standardGeneric("sumDistinct") })
13591359

1360+
#' @rdname column_datetime_functions
1361+
#' @name timestamp_seconds
1362+
setGeneric("timestamp_seconds", function(x) { standardGeneric("timestamp_seconds") })
1363+
13601364
#' @rdname column_collection_functions
13611365
#' @name NULL
13621366
setGeneric("transform_keys", function(x, f) { standardGeneric("transform_keys") })

R/pkg/tests/fulltests/test_sparkSQL.R

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1424,6 +1424,7 @@ test_that("column functions", {
14241424
date_trunc("quarter", c) + current_date() + current_timestamp()
14251425
c25 <- overlay(c1, c2, c3, c3) + overlay(c1, c2, c3) + overlay(c1, c2, 1) +
14261426
overlay(c1, c2, 3, 4)
1427+
c26 <- timestamp_seconds(c1)
14271428

14281429
# Test if base::is.nan() is exposed
14291430
expect_equal(is.nan(c("a", "b")), c(FALSE, FALSE))

0 commit comments

Comments
 (0)