Repository: spark Updated Branches: refs/heads/master 961342489 -> 36e812d4b
[SPARK-16029][SPARKR] SparkR add dropTempView and deprecate dropTempTable ## What changes were proposed in this pull request? Add dropTempView and deprecate dropTempTable ## How was this patch tested? unit tests shivaram liancheng Author: Felix Cheung <felixcheun...@hotmail.com> Closes #13753 from felixcheung/rdroptempview. Project: http://git-wip-us.apache.org/repos/asf/spark/repo Commit: http://git-wip-us.apache.org/repos/asf/spark/commit/36e812d4 Tree: http://git-wip-us.apache.org/repos/asf/spark/tree/36e812d4 Diff: http://git-wip-us.apache.org/repos/asf/spark/diff/36e812d4 Branch: refs/heads/master Commit: 36e812d4b695566437c6bac991ef06a0f81fb1c5 Parents: 9613424 Author: Felix Cheung <felixcheun...@hotmail.com> Authored: Mon Jun 20 11:24:41 2016 -0700 Committer: Shivaram Venkataraman <shiva...@cs.berkeley.edu> Committed: Mon Jun 20 11:24:41 2016 -0700 ---------------------------------------------------------------------- R/pkg/NAMESPACE | 1 + R/pkg/R/SQLContext.R | 39 ++++++++++++++++++++++---- R/pkg/inst/tests/testthat/test_sparkSQL.R | 14 ++++----- 3 files changed, 41 insertions(+), 13 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/spark/blob/36e812d4/R/pkg/NAMESPACE ---------------------------------------------------------------------- diff --git a/R/pkg/NAMESPACE b/R/pkg/NAMESPACE index 0cfe190..cc129a7 100644 --- a/R/pkg/NAMESPACE +++ b/R/pkg/NAMESPACE @@ -299,6 +299,7 @@ export("as.DataFrame", "createDataFrame", "createExternalTable", "dropTempTable", + "dropTempView", "jsonFile", "loadDF", "parquetFile", http://git-wip-us.apache.org/repos/asf/spark/blob/36e812d4/R/pkg/R/SQLContext.R ---------------------------------------------------------------------- diff --git a/R/pkg/R/SQLContext.R b/R/pkg/R/SQLContext.R index 3232241..b0ccc42 100644 --- a/R/pkg/R/SQLContext.R +++ b/R/pkg/R/SQLContext.R @@ -599,13 +599,14 @@ clearCache <- function() { dispatchFunc("clearCache()") } -#' Drop Temporary Table +#' (Deprecated) Drop Temporary Table #' #' Drops the temporary table with the given table name in the catalog. #' If the table has been cached/persisted before, it's also unpersisted. #' #' @param tableName The name of the SparkSQL table to be dropped. -#' @rdname dropTempTable +#' @seealso \link{dropTempView} +#' @rdname dropTempTable-deprecated #' @export #' @examples #' \dontrun{ @@ -619,16 +620,42 @@ clearCache <- function() { #' @method dropTempTable default dropTempTable.default <- function(tableName) { - sparkSession <- getSparkSession() if (class(tableName) != "character") { stop("tableName must be a string.") } - catalog <- callJMethod(sparkSession, "catalog") - callJMethod(catalog, "dropTempView", tableName) + dropTempView(tableName) } dropTempTable <- function(x, ...) { - dispatchFunc("dropTempTable(tableName)", x, ...) + .Deprecated("dropTempView") + dispatchFunc("dropTempView(viewName)", x, ...) +} + +#' Drops the temporary view with the given view name in the catalog. +#' +#' Drops the temporary view with the given view name in the catalog. +#' If the view has been cached before, then it will also be uncached. +#' +#' @param viewName the name of the view to be dropped. +#' @rdname dropTempView +#' @name dropTempView +#' @export +#' @examples +#' \dontrun{ +#' sparkR.session() +#' df <- read.df(path, "parquet") +#' createOrReplaceTempView(df, "table") +#' dropTempView("table") +#' } +#' @note since 2.0.0 + +dropTempView <- function(viewName) { + sparkSession <- getSparkSession() + if (class(viewName) != "character") { + stop("viewName must be a string.") + } + catalog <- callJMethod(sparkSession, "catalog") + callJMethod(catalog, "dropTempView", viewName) } #' Load a SparkDataFrame http://git-wip-us.apache.org/repos/asf/spark/blob/36e812d4/R/pkg/inst/tests/testthat/test_sparkSQL.R ---------------------------------------------------------------------- diff --git a/R/pkg/inst/tests/testthat/test_sparkSQL.R b/R/pkg/inst/tests/testthat/test_sparkSQL.R index c5c5a06..ceba0d1 100644 --- a/R/pkg/inst/tests/testthat/test_sparkSQL.R +++ b/R/pkg/inst/tests/testthat/test_sparkSQL.R @@ -472,8 +472,8 @@ test_that("test tableNames and tables", { suppressWarnings(registerTempTable(df, "table2")) tables <- tables() expect_equal(count(tables), 2) - dropTempTable("table1") - dropTempTable("table2") + suppressWarnings(dropTempTable("table1")) + dropTempView("table2") tables <- tables() expect_equal(count(tables), 0) @@ -486,7 +486,7 @@ test_that( newdf <- sql("SELECT * FROM table1 where name = 'Michael'") expect_is(newdf, "SparkDataFrame") expect_equal(count(newdf), 1) - dropTempTable("table1") + dropTempView("table1") }) test_that("test cache, uncache and clearCache", { @@ -495,7 +495,7 @@ test_that("test cache, uncache and clearCache", { cacheTable("table1") uncacheTable("table1") clearCache() - dropTempTable("table1") + dropTempView("table1") }) test_that("insertInto() on a registered table", { @@ -516,13 +516,13 @@ test_that("insertInto() on a registered table", { insertInto(dfParquet2, "table1") expect_equal(count(sql("select * from table1")), 5) expect_equal(first(sql("select * from table1 order by age"))$name, "Michael") - dropTempTable("table1") + dropTempView("table1") createOrReplaceTempView(dfParquet, "table1") insertInto(dfParquet2, "table1", overwrite = TRUE) expect_equal(count(sql("select * from table1")), 2) expect_equal(first(sql("select * from table1 order by age"))$name, "Bob") - dropTempTable("table1") + dropTempView("table1") unlink(jsonPath2) unlink(parquetPath2) @@ -536,7 +536,7 @@ test_that("tableToDF() returns a new DataFrame", { expect_equal(count(tabledf), 3) tabledf2 <- tableToDF("table1") expect_equal(count(tabledf2), 3) - dropTempTable("table1") + dropTempView("table1") }) test_that("toRDD() returns an RRDD", { --------------------------------------------------------------------- To unsubscribe, e-mail: commits-unsubscr...@spark.apache.org For additional commands, e-mail: commits-h...@spark.apache.org