[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 <mszymkiewicz@gmail.com>
Signed-off-by: Dongjoon Hyun <dhyun@apple.com>
This commit is contained in:
zero323 2020-09-21 22:32:25 -07:00 committed by Dongjoon Hyun
parent f03c03576a
commit 3118c220f9
4 changed files with 21 additions and 0 deletions

View file

@ -405,6 +405,7 @@ exportMethods("%<=>%",
"sumDistinct",
"tan",
"tanh",
"timestamp_seconds",
"toDegrees",
"toRadians",
"to_csv",

View file

@ -4407,3 +4407,18 @@ setMethod("current_timestamp",
jc <- callJStatic("org.apache.spark.sql.functions", "current_timestamp")
column(jc)
})
#' @details
#' \code{timestamp_seconds}: Creates timestamp from the number of seconds since UTC epoch.
#'
#' @rdname column_datetime_functions
#' @aliases timestamp_seconds timestamp_seconds,Column-method
#' @note timestamp_seconds since 3.1.0
setMethod("timestamp_seconds",
signature(x = "Column"),
function(x) {
jc <- callJStatic(
"org.apache.spark.sql.functions", "timestamp_seconds", x@jc
)
column(jc)
})

View file

@ -1357,6 +1357,10 @@ setGeneric("substring_index", function(x, delim, count) { standardGeneric("subst
#' @name NULL
setGeneric("sumDistinct", function(x) { standardGeneric("sumDistinct") })
#' @rdname column_datetime_functions
#' @name timestamp_seconds
setGeneric("timestamp_seconds", function(x) { standardGeneric("timestamp_seconds") })
#' @rdname column_collection_functions
#' @name NULL
setGeneric("transform_keys", function(x, f) { standardGeneric("transform_keys") })

View file

@ -1424,6 +1424,7 @@ test_that("column functions", {
date_trunc("quarter", c) + current_date() + current_timestamp()
c25 <- overlay(c1, c2, c3, c3) + overlay(c1, c2, c3) + overlay(c1, c2, 1) +
overlay(c1, c2, 3, 4)
c26 <- timestamp_seconds(c1)
# Test if base::is.nan() is exposed
expect_equal(is.nan(c("a", "b")), c(FALSE, FALSE))