Skip to content

Commit

Permalink
[SPARK-32949][R][SQL] Add timestamp_seconds to SparkR
Browse files Browse the repository at this point in the history
### 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>
  • Loading branch information
zero323 authored and dongjoon-hyun committed Sep 22, 2020
1 parent f03c035 commit 3118c22
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 0 deletions.
1 change: 1 addition & 0 deletions R/pkg/NAMESPACE
Expand Up @@ -405,6 +405,7 @@ exportMethods("%<=>%",
"sumDistinct",
"tan",
"tanh",
"timestamp_seconds",
"toDegrees",
"toRadians",
"to_csv",
Expand Down
15 changes: 15 additions & 0 deletions R/pkg/R/functions.R
Expand Up @@ -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)
})
4 changes: 4 additions & 0 deletions R/pkg/R/generics.R
Expand Up @@ -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") })
Expand Down
1 change: 1 addition & 0 deletions R/pkg/tests/fulltests/test_sparkSQL.R
Expand Up @@ -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))
Expand Down

0 comments on commit 3118c22

Please sign in to comment.