From 645f4c16b8a8dd19917e64a5d308b899e213b269 Mon Sep 17 00:00:00 2001 From: zero323 Date: Mon, 21 Sep 2020 08:29:28 +0200 Subject: [PATCH] Add timestamp_seconds to SparkR --- R/pkg/NAMESPACE | 1 + R/pkg/R/functions.R | 15 +++++++++++++++ R/pkg/R/generics.R | 4 ++++ R/pkg/tests/fulltests/test_sparkSQL.R | 1 + 4 files changed, 21 insertions(+) diff --git a/R/pkg/NAMESPACE b/R/pkg/NAMESPACE index 53a0b7856567..d8634026c878 100644 --- a/R/pkg/NAMESPACE +++ b/R/pkg/NAMESPACE @@ -405,6 +405,7 @@ exportMethods("%<=>%", "sumDistinct", "tan", "tanh", + "timestamp_seconds", "toDegrees", "toRadians", "to_csv", diff --git a/R/pkg/R/functions.R b/R/pkg/R/functions.R index 5d9c8e8124d9..1d75819cb613 100644 --- a/R/pkg/R/functions.R +++ b/R/pkg/R/functions.R @@ -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) + }) diff --git a/R/pkg/R/generics.R b/R/pkg/R/generics.R index a6a71666ae58..93ee8359b6b1 100644 --- a/R/pkg/R/generics.R +++ b/R/pkg/R/generics.R @@ -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") }) diff --git a/R/pkg/tests/fulltests/test_sparkSQL.R b/R/pkg/tests/fulltests/test_sparkSQL.R index 5008d3005b5b..188daee3f29c 100644 --- a/R/pkg/tests/fulltests/test_sparkSQL.R +++ b/R/pkg/tests/fulltests/test_sparkSQL.R @@ -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))