aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--R/pkg/NAMESPACE1
-rw-r--r--R/pkg/R/DataFrame.R30
-rw-r--r--R/pkg/R/generics.R14
-rw-r--r--R/pkg/inst/tests/testthat/test_sparkSQL.R30
4 files changed, 57 insertions, 18 deletions
diff --git a/R/pkg/NAMESPACE b/R/pkg/NAMESPACE
index 8db4d5ca1e..5db43ae649 100644
--- a/R/pkg/NAMESPACE
+++ b/R/pkg/NAMESPACE
@@ -82,6 +82,7 @@ exportMethods("arrange",
"persist",
"printSchema",
"rbind",
+ "registerTempTable",
"rename",
"repartition",
"sample",
diff --git a/R/pkg/R/DataFrame.R b/R/pkg/R/DataFrame.R
index c710bffa2c..231e4f0f4e 100644
--- a/R/pkg/R/DataFrame.R
+++ b/R/pkg/R/DataFrame.R
@@ -457,6 +457,32 @@ setMethod("createOrReplaceTempView",
invisible(callJMethod(x@sdf, "createOrReplaceTempView", viewName))
})
+#' (Deprecated) Register Temporary Table
+#' Registers a SparkDataFrame as a Temporary Table in the SQLContext
+#' @param x A SparkDataFrame
+#' @param tableName A character vector containing the name of the table
+#'
+#' @family SparkDataFrame functions
+#' @seealso \link{createOrReplaceTempView}
+#' @rdname registerTempTable-deprecated
+#' @name registerTempTable
+#' @export
+#' @examples
+#'\dontrun{
+#' sc <- sparkR.init()
+#' sqlContext <- sparkRSQL.init(sc)
+#' path <- "path/to/file.json"
+#' df <- read.json(path)
+#' registerTempTable(df, "json_df")
+#' new_df <- sql("SELECT * FROM json_df")
+#'}
+setMethod("registerTempTable",
+ signature(x = "SparkDataFrame", tableName = "character"),
+ function(x, tableName) {
+ .Deprecated("createOrReplaceTempView")
+ invisible(callJMethod(x@sdf, "createOrReplaceTempView", tableName))
+ })
+
#' insertInto
#'
#' Insert the contents of a SparkDataFrame into a table registered in the current SQL Context.
@@ -1286,7 +1312,7 @@ setMethod("dapplyCollect",
#' @name gapply
#' @export
#' @examples
-#'
+#'
#' \dontrun{
#' Computes the arithmetic mean of the second column by grouping
#' on the first and third columns. Output the grouping values and the average.
@@ -1317,7 +1343,7 @@ setMethod("dapplyCollect",
#' Fits linear models on iris dataset by grouping on the 'Species' column and
#' using 'Sepal_Length' as a target variable, 'Sepal_Width', 'Petal_Length'
#' and 'Petal_Width' as training features.
-#'
+#'
#' df <- createDataFrame (iris)
#' schema <- structType(structField("(Intercept)", "double"),
#' structField("Sepal_Width", "double"),structField("Petal_Length", "double"),
diff --git a/R/pkg/R/generics.R b/R/pkg/R/generics.R
index 8164e7731a..594bf2eadc 100644
--- a/R/pkg/R/generics.R
+++ b/R/pkg/R/generics.R
@@ -446,6 +446,13 @@ setGeneric("covar_samp", function(col1, col2) {standardGeneric("covar_samp") })
#' @export
setGeneric("covar_pop", function(col1, col2) {standardGeneric("covar_pop") })
+#' @rdname createOrReplaceTempView
+#' @export
+setGeneric("createOrReplaceTempView",
+ function(x, viewName) {
+ standardGeneric("createOrReplaceTempView")
+ })
+
#' @rdname dapply
#' @export
setGeneric("dapply", function(x, func, schema) { standardGeneric("dapply") })
@@ -548,12 +555,9 @@ setGeneric("printSchema", function(x) { standardGeneric("printSchema") })
#' @export
setGeneric("rename", function(x, ...) { standardGeneric("rename") })
-#' @rdname createOrReplaceTempView
+#' @rdname registerTempTable-deprecated
#' @export
-setGeneric("createOrReplaceTempView",
- function(x, viewName) {
- standardGeneric("createOrReplaceTempView")
- })
+setGeneric("registerTempTable", function(x, tableName) { standardGeneric("registerTempTable") })
#' @rdname sample
#' @export
diff --git a/R/pkg/inst/tests/testthat/test_sparkSQL.R b/R/pkg/inst/tests/testthat/test_sparkSQL.R
index 11d69366df..7aa03a9048 100644
--- a/R/pkg/inst/tests/testthat/test_sparkSQL.R
+++ b/R/pkg/inst/tests/testthat/test_sparkSQL.R
@@ -443,22 +443,21 @@ test_that("jsonRDD() on a RDD with json string", {
expect_equal(count(df), 6)
})
-test_that("test cache, uncache and clearCache", {
- df <- read.json(jsonPath)
- createOrReplaceTempView(df, "table1")
- cacheTable("table1")
- uncacheTable("table1")
- clearCache()
- dropTempTable("table1")
-})
-
test_that("test tableNames and tables", {
df <- read.json(jsonPath)
createOrReplaceTempView(df, "table1")
expect_equal(length(tableNames()), 1)
- df <- tables()
- expect_equal(count(df), 1)
+ tables <- tables()
+ expect_equal(count(tables), 1)
+
+ suppressWarnings(registerTempTable(df, "table2"))
+ tables <- tables()
+ expect_equal(count(tables), 2)
dropTempTable("table1")
+ dropTempTable("table2")
+
+ tables <- tables()
+ expect_equal(count(tables), 0)
})
test_that(
@@ -471,6 +470,15 @@ test_that(
dropTempTable("table1")
})
+test_that("test cache, uncache and clearCache", {
+ df <- read.json(jsonPath)
+ createOrReplaceTempView(df, "table1")
+ cacheTable("table1")
+ uncacheTable("table1")
+ clearCache()
+ dropTempTable("table1")
+})
+
test_that("insertInto() on a registered table", {
df <- read.df(jsonPath, "json")
write.df(df, parquetPath, "parquet", "overwrite")