diff --git a/R/pkg/R/sparkR.R b/R/pkg/R/sparkR.R index c57cc8f28561..56d70b2b436c 100644 --- a/R/pkg/R/sparkR.R +++ b/R/pkg/R/sparkR.R @@ -362,6 +362,10 @@ sparkR.session <- function( enableHiveSupport = TRUE, ...) { + if (length(sparkConfig[["spark.sql.warehouse.dir"]]) == 0) { + sparkConfig[["spark.sql.warehouse.dir"]] <- tempdir() + } + sparkConfigMap <- convertNamedListToEnv(sparkConfig) namedParams <- list(...) if (length(namedParams) > 0) { diff --git a/R/pkg/inst/tests/testthat/test_sparkR.R b/R/pkg/inst/tests/testthat/test_sparkR.R index f73fc6baecce..f4e36c9c55ca 100644 --- a/R/pkg/inst/tests/testthat/test_sparkR.R +++ b/R/pkg/inst/tests/testthat/test_sparkR.R @@ -44,3 +44,17 @@ test_that("sparkCheckInstall", { deployMode <- "client" expect_error(sparkCheckInstall(sparkHome, master, deployMode)) }) + +test_that("sparkR.session", { + # nothing should be written outside tempdir() without explicit user permission + inital_working_directory_files <- list.files() + sparkR.session(enableHiveSupport = FALSE) + df <- data.frame("col1" = c(1, 2, 3, 4, 5, 6), + "col2" = c(1, 0, 0, 1, 1, 0), + "col3" = c(1, 0, 0, 2, 6, 2)) + df <- as.DataFrame(df) + createOrReplaceTempView(df, "table") + result <- sql("SELECT * FROM `table`") + sparkR.session.stop() + expect_equal(inital_working_directory_files, list.files()) +})