Skip to content
Closed
Show file tree
Hide file tree
Changes from 9 commits
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
11 changes: 10 additions & 1 deletion R/pkg/R/client.R
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,15 @@ generateSparkSubmitArgs <- function(args, sparkHome, jars, sparkSubmitOpts, pack
combinedArgs
}

determineLauncher <- function(sparkSubmitBin, combinedArgs, capture = FALSE) {
Copy link
Contributor

Choose a reason for hiding this comment

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

can this be a common utility function and be re-used in test_includeJAR.R?

Copy link
Member Author

@HyukjinKwon HyukjinKwon May 25, 2016

Choose a reason for hiding this comment

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

Sure. I will.

BTW, could you inform me if I can disable style checking for some blocks in R like Scala? It seems it fails due to the usages of shell.

Copy link
Contributor

Choose a reason for hiding this comment

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

You can use nolint - See context.R for an example. BTW what is the lint error here ?

Copy link
Member Author

@HyukjinKwon HyukjinKwon May 26, 2016

Choose a reason for hiding this comment

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

@shivaram For some reasons, it seems there is no mothod shell() on Linux (I tested this on my Mac) but on Windows. I am using this twice within this PR. Here is a thread for this, http://r.789695.n4.nabble.com/Shell-Function-not-on-Linux-td4672569.html.

I could not find the official documentation though. Let me address the comments first.

Copy link
Contributor

Choose a reason for hiding this comment

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

the common function could be like:

  launchScript(script) {
    if (windowsOS) use shell()
    else (system2()
  }

This makes it more general, not binding to launching SparkSubmit

Copy link
Member Author

Choose a reason for hiding this comment

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

@sun-rui Thank you so much. I was trying to come up with a good name.

if (.Platform$OS.type == "windows") {
sparkSubmitWithArgs <- paste(sparkSubmitBin, combinedArgs, sep = " ")
shell(sparkSubmitWithArgs, translate = TRUE, wait = ! capture, intern = capture)
} else {
system2(sparkSubmitBin, combinedArgs, wait = F, stdout = capture)
}
}

launchBackend <- function(args, sparkHome, jars, sparkSubmitOpts, packages) {
sparkSubmitBinName <- determineSparkSubmitBin()
if (sparkHome != "") {
Expand All @@ -69,5 +78,5 @@ launchBackend <- function(args, sparkHome, jars, sparkSubmitOpts, packages) {
}
combinedArgs <- generateSparkSubmitArgs(args, sparkHome, jars, sparkSubmitOpts, packages)
cat("Launching java with spark-submit command", sparkSubmitBin, combinedArgs, "\n")
invisible(system2(sparkSubmitBin, combinedArgs, wait = F))
invisible(determineLauncher(sparkSubmitBin, combinedArgs))
}
26 changes: 26 additions & 0 deletions R/pkg/inst/tests/testthat/test_Windows.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
#
# Licensed to the Apache Software Foundation (ASF) under one or more
# contributor license agreements. See the NOTICE file distributed with
# this work for additional information regarding copyright ownership.
# The ASF licenses this file to You under the Apache License, Version 2.0
# (the "License"); you may not use this file except in compliance with
# the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
context("test the support SparkR on Windows")

test_that("sparkJars tag in SparkContext", {
if (.Platform$OS.type != "windows") {
skip("This test is only for Windows, skipped")
}
testOutput <- determineLauncher("ECHO", "a/b/c", capture = TRUE)
abcPath <- testOutput[1]
expect_equal(abcPath, "a\\b\\c")
})
6 changes: 3 additions & 3 deletions R/pkg/inst/tests/testthat/test_context.R
Original file line number Diff line number Diff line change
Expand Up @@ -125,13 +125,13 @@ test_that("getClientModeSparkSubmitOpts() returns spark-submit args from whiteli
test_that("sparkJars sparkPackages as comma-separated strings", {
expect_warning(processSparkJars(" a, b "))
jars <- suppressWarnings(processSparkJars(" a, b "))
expect_equal(jars, c("a", "b"))
expect_equal(lapply(jars, basename), list("a", "b"))

jars <- suppressWarnings(processSparkJars(" abc ,, def "))
expect_equal(jars, c("abc", "def"))
expect_equal(lapply(jars, basename), list("abc", "def"))

jars <- suppressWarnings(processSparkJars(c(" abc ,, def ", "", "xyz", " ", "a,b")))
expect_equal(jars, c("abc", "def", "xyz", "a", "b"))
expect_equal(lapply(jars, basename), list("abc", "def", "xyz", "a", "b"))

p <- processSparkPackages(c("ghi", "lmn"))
expect_equal(p, c("ghi", "lmn"))
Expand Down
10 changes: 8 additions & 2 deletions R/pkg/inst/tests/testthat/test_includeJAR.R
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,16 @@ runScript <- function() {
sparkTestJarPath <- "R/lib/SparkR/test_support/sparktestjar_2.10-1.0.jar"
jarPath <- paste("--jars", shQuote(file.path(sparkHome, sparkTestJarPath)))
scriptPath <- file.path(sparkHome, "R/lib/SparkR/tests/testthat/jarTest.R")
submitPath <- file.path(sparkHome, "bin/spark-submit")
res <- system2(command = submitPath,
if (.Platform$OS.type == "windows") {
Copy link
Contributor

Choose a reason for hiding this comment

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

you can call determineSparkSubmitBin() here

submitPath <- file.path(sparkHome, "bin/spark-submit2.cmd")
command <- paste(submitPath, jarPath, scriptPath, sep = " ")
res <- shell(command, translate = TRUE, intern = TRUE)
} else {
submitPath <- file.path(sparkHome, "bin/spark-submit")
res <- system2(command = submitPath,
args = c(jarPath, scriptPath),
stdout = TRUE)
}
tail(res, 2)
}

Expand Down