Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
change property to use to move derby.log, clean start in test, update…
… test
  • Loading branch information
felixcheung committed Mar 18, 2017
commit 4604a531c321dbd18ba5a5f9cac055137db49670
4 changes: 2 additions & 2 deletions R/pkg/R/sparkR.R
Original file line number Diff line number Diff line change
Expand Up @@ -390,8 +390,8 @@ sparkR.session <- function(
deployMode <- sparkConfigMap[["spark.submit.deployMode"]]
}

if (!exists("spark.r.sql.default.derby.dir", envir = sparkConfigMap)) {
sparkConfigMap[["spark.r.sql.default.derby.dir"]] <- tempdir()
if (!exists("spark.r.sql.derby.temp.dir", envir = sparkConfigMap)) {
sparkConfigMap[["spark.r.sql.derby.temp.dir"]] <- tempdir()
}

if (!exists(".sparkRjsc", envir = .sparkREnv)) {
Expand Down
17 changes: 10 additions & 7 deletions R/pkg/inst/tests/testthat/test_sparkSQL.R
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ unsetHiveContext <- function() {

# Tests for SparkSQL functions in SparkR

filesBefore <- list.files(path = file.path(Sys.getenv("SPARK_HOME"), "R"), all.files = TRUE)
filesBefore <- list.files(path = sparkRDir, all.files = TRUE)
sparkSession <- sparkR.session()
sc <- callJStatic("org.apache.spark.sql.api.r.SQLUtils", "getJavaSparkContext", sparkSession)

Expand Down Expand Up @@ -2923,12 +2923,15 @@ compare_list <- function(list1, list2) {
test_that("No extra files are created in SPARK_HOME by starting session and making calls", {
# Check that it is not creating any extra file.
# Does not check the tempdir which would be cleaned up after.
filesAfter <- list.files(path = file.path(Sys.getenv("SPARK_HOME"), "R"), all.files = TRUE)

expect_true(length(sparkHomeFileBefore) > 0)
compare_list(sparkHomeFileBefore, filesBefore)

compare_list(filesBefore, filesAfter)
filesAfter <- list.files(path = sparkRDir, all.files = TRUE)

expect_true(length(sparkRFilesBefore) > 0)
# first, ensure derby.log is not there
expect_false("derby.log" %in% filesAfter)
# second, ensure only spark-warehouse is created when calling SparkSession, enableHiveSupport = F
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm a little confused how these two setdiff commands map to with or without hive support. Can we make this a bit more easier to understand ?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

agreed.
updated, hope it's better now.

compare_list(sparkRFilesBefore, setdiff(filesBefore, sparkRWhitelistSQLDirs[[1]]))
# third, ensure only spark-warehouse and metastore_db are created when enableHiveSupport = T
compare_list(sparkRFilesBefore, setdiff(filesAfter, sparkRWhitelistSQLDirs))
})

unlink(parquetPath)
Expand Down
7 changes: 6 additions & 1 deletion R/pkg/tests/run-all.R
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,12 @@ library(SparkR)
options("warn" = 2)

# Setup global test environment
sparkHomeFileBefore <- list.files(path = file.path(Sys.getenv("SPARK_HOME"), "R"), all.files = TRUE)
sparkRDir <- file.path(Sys.getenv("SPARK_HOME"), "R")
sparkRFilesBefore <- list.files(path = sparkRDir, all.files = TRUE)
sparkRWhitelistSQLDirs <- c("spark-warehouse", "metastore_db")
invisible(lapply(sparkRWhitelistSQLDirs,
function(x) { unlink(file.path(sparkRDir, x), recursive = TRUE, force = TRUE)}))

install.spark()

test_package("SparkR")
10 changes: 6 additions & 4 deletions core/src/main/scala/org/apache/spark/api/r/RRDD.scala
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
package org.apache.spark.api.r

import java.util.{Map => JMap}
import java.io.File

import scala.collection.JavaConverters._
import scala.reflect.ClassTag
Expand Down Expand Up @@ -127,11 +128,12 @@ private[r] object RRDD {
sparkConf.setExecutorEnv(name.toString, value.toString)
}

if (sparkEnvirMap.containsKey("spark.r.sql.default.derby.dir") &&
System.getProperty("derby.system.home") == null) {
if (sparkEnvirMap.containsKey("spark.r.sql.derby.temp.dir") &&
System.getProperty("derby.stream.error.file") == null) {
// This must be set before SparkContext is instantiated.
System.setProperty("derby.system.home",
sparkEnvirMap.get("spark.r.sql.default.derby.dir").toString)
System.setProperty("derby.stream.error.file",
Seq(sparkEnvirMap.get("spark.r.sql.derby.temp.dir").toString, "derby.log")
.mkString(File.separator))
}

val jsc = new JavaSparkContext(sparkConf)
Expand Down