Skip to content

Commit

Permalink
Add timestamp_seconds to SparkR
Browse files Browse the repository at this point in the history
  • Loading branch information
zero323 committed Sep 21, 2020
1 parent 0c66813 commit 645f4c1
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
Expand Up @@ -1354,6 +1354,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
Original file line number Diff line number Diff line change
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 645f4c1

Please sign in to comment.