Skip to content

Commit

Permalink
Merge pull request apache#173 from shivaram/windows-space-fix
Browse files Browse the repository at this point in the history
[SPARKR-200][SPARKR-149] Fix path, classpath separator for Windows
  • Loading branch information
shivaram committed Feb 20, 2015
2 parents 17eda4c + 06d99f0 commit 06bf250
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 5 deletions.
19 changes: 14 additions & 5 deletions pkg/R/sparkR.R
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ assemblyJarName <- "sparkr-assembly-0.1.jar"

sparkR.onLoad <- function(libname, pkgname) {
assemblyJarPath <- paste(libname, "/SparkR/", assemblyJarName, sep = "")
assemblyJarPath <- gsub(" ", "\\ ", assemblyJarPath, fixed = T)
packageStartupMessage("[SparkR] Initializing with classpath ", assemblyJarPath, "\n")

.sparkREnv$libname <- libname
Expand Down Expand Up @@ -98,9 +97,19 @@ sparkR.init <- function(
}

sparkMem <- Sys.getenv("SPARK_MEM", "512m")
jars <- c(as.character(.sparkREnv$assemblyJarPath), as.character(sparkJars))

cp <- paste0(jars, collapse = ":")
jars <- suppressWarnings(
normalizePath(c(as.character(.sparkREnv$assemblyJarPath), as.character(sparkJars))))

# Classpath separator is ";" on Windows
# URI needs four /// as from http://stackoverflow.com/a/18522792
if (.Platform$OS.type == "unix") {
collapseChar <- ":"
uriSep <- "//"
} else {
collapseChar <- ";"
uriSep <- "////"
}
cp <- paste0(jars, collapse = collapseChar)

yarn_conf_dir <- Sys.getenv("YARN_CONF_DIR", "")
if (yarn_conf_dir != "") {
Expand Down Expand Up @@ -136,7 +145,7 @@ sparkR.init <- function(
}

nonEmptyJars <- Filter(function(x) { x != "" }, jars)
localJarPaths <- sapply(nonEmptyJars, function(j) { paste("file://", j, sep = "") })
localJarPaths <- sapply(nonEmptyJars, function(j) { utils::URLencode(paste("file:", uriSep, j, sep = "")) })

assign(
".sparkRjsc",
Expand Down
2 changes: 2 additions & 0 deletions pkg/R/sparkRClient.R
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ launchBackend <- function(
} else {
java_bin <- java_bin_name
}
# Quote the classpath to make sure it handles spaces on Windows
classPath <- shQuote(classPath)
combinedArgs <- paste(javaOpts, "-cp", classPath, mainClass, args, sep = " ")
cat("Launching java with command ", java_bin, " ", combinedArgs, "\n")
invisible(system2(java_bin, combinedArgs, wait = F))
Expand Down

0 comments on commit 06bf250

Please sign in to comment.