-
Notifications
You must be signed in to change notification settings - Fork 28.7k
[SPARK-6568] spark-shell.cmd --jars option does not accept the jar that has space in its path #5447
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
c7ba6a7
649da82
93c3c40
10f1c73
45946ee
7019a8a
2c62e3b
016128d
84c33d0
e03f289
1784239
ed46047
3f9a188
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1658,11 +1658,6 @@ private[spark] object Utils extends Logging { | |
*/ | ||
val windowsDrive = "([a-zA-Z])".r | ||
|
||
/** | ||
* Format a Windows path such that it can be safely passed to a URI. | ||
*/ | ||
def formatWindowsPath(path: String): String = path.replace("\\", "/") | ||
|
||
/** | ||
* Indicates whether Spark is currently running unit tests. | ||
*/ | ||
|
@@ -1760,37 +1755,24 @@ private[spark] object Utils extends Logging { | |
* If the supplied path does not contain a scheme, or is a relative path, it will be | ||
* converted into an absolute path with a file:// scheme. | ||
*/ | ||
def resolveURI(path: String, testWindows: Boolean = false): URI = { | ||
|
||
// In Windows, the file separator is a backslash, but this is inconsistent with the URI format | ||
val windows = isWindows || testWindows | ||
val formattedPath = if (windows) formatWindowsPath(path) else path | ||
|
||
val uri = new URI(formattedPath) | ||
if (uri.getPath == null) { | ||
throw new IllegalArgumentException(s"Given path is malformed: $uri") | ||
} | ||
|
||
Option(uri.getScheme) match { | ||
case Some(windowsDrive(d)) if windows => | ||
new URI("file:/" + uri.toString.stripPrefix("/")) | ||
case None => | ||
// Preserve fragments for HDFS file name substitution (denoted by "#") | ||
// For instance, in "abc.py#xyz.py", "xyz.py" is the name observed by the application | ||
val fragment = uri.getFragment | ||
val part = new File(uri.getPath).toURI | ||
new URI(part.getScheme, part.getPath, fragment) | ||
case Some(other) => | ||
uri | ||
def resolveURI(path: String): URI = { | ||
try { | ||
val uri = new URI(path) | ||
if (uri.getScheme() != null) { | ||
return uri | ||
} | ||
} catch { | ||
case e: URISyntaxException => | ||
} | ||
new File(path).getAbsoluteFile().toURI() | ||
} | ||
|
||
/** Resolve a comma-separated list of paths. */ | ||
def resolveURIs(paths: String, testWindows: Boolean = false): String = { | ||
def resolveURIs(paths: String): String = { | ||
if (paths == null || paths.trim.isEmpty) { | ||
"" | ||
} else { | ||
paths.split(",").map { p => Utils.resolveURI(p, testWindows) }.mkString(",") | ||
paths.split(",").map { p => Utils.resolveURI(p) }.mkString(",") | ||
} | ||
} | ||
|
||
|
@@ -1801,8 +1783,7 @@ private[spark] object Utils extends Logging { | |
Array.empty | ||
} else { | ||
paths.split(",").filter { p => | ||
val formattedPath = if (windows) formatWindowsPath(p) else p | ||
val uri = new URI(formattedPath) | ||
val uri = resolveURI(p) | ||
Option(uri.getScheme).getOrElse("file") match { | ||
case windowsDrive(d) if windows => false | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Not your fault, but I'm not sure this will ever match anything, since the match is on the URI's scheme. But probably doesn't hurt to leave here if you don't want to double-check that. |
||
case "local" | "file" => false | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -19,6 +19,8 @@ package org.apache.spark.deploy | |
|
||
import org.scalatest.FunSuite | ||
|
||
import org.apache.spark.util.Utils | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nit: order (meaning, it's a Spark import and should be in a separate group) |
||
|
||
class PythonRunnerSuite extends FunSuite { | ||
|
||
// Test formatting a single path to be added to the PYTHONPATH | ||
|
@@ -28,10 +30,14 @@ class PythonRunnerSuite extends FunSuite { | |
assert(PythonRunner.formatPath("file:///spark.py") === "/spark.py") | ||
assert(PythonRunner.formatPath("local:/spark.py") === "/spark.py") | ||
assert(PythonRunner.formatPath("local:///spark.py") === "/spark.py") | ||
assert(PythonRunner.formatPath("C:/a/b/spark.py", testWindows = true) === "C:/a/b/spark.py") | ||
assert(PythonRunner.formatPath("/C:/a/b/spark.py", testWindows = true) === "C:/a/b/spark.py") | ||
assert(PythonRunner.formatPath("file:/C:/a/b/spark.py", testWindows = true) === | ||
"C:/a/b/spark.py") | ||
if (Utils.isWindows) { | ||
assert(PythonRunner.formatPath("file:/C:/a/b/spark.py", testWindows = true) === | ||
"C:/a/b/spark.py") | ||
assert(PythonRunner.formatPath("C:\\a\\b\\spark.py", testWindows = true) === | ||
"C:/a/b/spark.py") | ||
assert(PythonRunner.formatPath("C:\\a b\\spark.py", testWindows = true) === | ||
"C:/a b/spark.py") | ||
} | ||
intercept[IllegalArgumentException] { PythonRunner.formatPath("one:two") } | ||
intercept[IllegalArgumentException] { PythonRunner.formatPath("hdfs:s3:xtremeFS") } | ||
intercept[IllegalArgumentException] { PythonRunner.formatPath("hdfs:/path/to/some.py") } | ||
|
@@ -45,14 +51,15 @@ class PythonRunnerSuite extends FunSuite { | |
Array("/app.py", "/spark.py")) | ||
assert(PythonRunner.formatPaths("me.py,file:/you.py,local:/we.py") === | ||
Array("me.py", "/you.py", "/we.py")) | ||
assert(PythonRunner.formatPaths("C:/a/b/spark.py", testWindows = true) === | ||
Array("C:/a/b/spark.py")) | ||
assert(PythonRunner.formatPaths("/C:/a/b/spark.py", testWindows = true) === | ||
Array("C:/a/b/spark.py")) | ||
assert(PythonRunner.formatPaths("C:/free.py,pie.py", testWindows = true) === | ||
Array("C:/free.py", "pie.py")) | ||
assert(PythonRunner.formatPaths("lovely.py,C:/free.py,file:/d:/fry.py", testWindows = true) === | ||
Array("lovely.py", "C:/free.py", "d:/fry.py")) | ||
if (Utils.isWindows) { | ||
assert(PythonRunner.formatPaths("C:\\a\\b\\spark.py", testWindows = true) === | ||
Array("C:/a/b/spark.py")) | ||
assert(PythonRunner.formatPaths("C:\\free.py,pie.py", testWindows = true) === | ||
Array("C:/free.py", "pie.py")) | ||
assert(PythonRunner.formatPaths("lovely.py,C:\\free.py,file:/d:/fry.py", | ||
testWindows = true) === | ||
Array("lovely.py", "C:/free.py", "d:/fry.py")) | ||
} | ||
intercept[IllegalArgumentException] { PythonRunner.formatPaths("one:two,three") } | ||
intercept[IllegalArgumentException] { PythonRunner.formatPaths("two,three,four:five:six") } | ||
intercept[IllegalArgumentException] { PythonRunner.formatPaths("hdfs:/some.py,foo.py") } | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: ordering; scala import should be grouped with the other scala imports.