Skip to content

Commit 84c33d0

Browse files
committed
- use resolveURI in nonLocalPaths
- run tests for Windows path only on Windows
1 parent 016128d commit 84c33d0

File tree

2 files changed

+12
-14
lines changed

2 files changed

+12
-14
lines changed

core/src/main/scala/org/apache/spark/util/Utils.scala

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1793,8 +1793,7 @@ private[spark] object Utils extends Logging {
17931793
Array.empty
17941794
} else {
17951795
paths.split(",").filter { p =>
1796-
val formattedPath = formatPath(p, windows)
1797-
val uri = new URI(formattedPath)
1796+
val uri = resolveURI(p, windows)
17981797
Option(uri.getScheme).getOrElse("file") match {
17991798
case windowsDrive(d) if windows => false
18001799
case "local" | "file" => false

core/src/test/scala/org/apache/spark/util/UtilsSuite.scala

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -241,8 +241,10 @@ class UtilsSuite extends FunSuite with ResetSystemProperties {
241241
assertResolves("spark.jar", s"file:$cwd/spark.jar")
242242
assertResolves("spark.jar#app.jar", s"file:$cwd/spark.jar%23app.jar")
243243
assertResolves("path to/file.txt", s"file:$cwd/path%20to/file.txt")
244-
assertResolves("C:\\path\\to\\file.txt", "file:/C:/path/to/file.txt", testWindows = true)
245-
assertResolves("C:\\path to\\file.txt", "file:/C:/path%20to/file.txt", testWindows = true)
244+
if (SystemUtils.IS_OS_WINDOWS) {
245+
assertResolves("C:\\path\\to\\file.txt", "file:/C:/path/to/file.txt", testWindows = true)
246+
assertResolves("C:\\path to\\file.txt", "file:/C:/path%20to/file.txt", testWindows = true)
247+
}
246248
assertResolves("file:/C:/path/to/file.txt", "file:/C:/path/to/file.txt", testWindows = true)
247249
assertResolves("file:///C:/path/to/file.txt", "file:/C:/path/to/file.txt", testWindows = true)
248250
assertResolves("file:/C:/file.txt#alias.txt", "file:/C:/file.txt#alias.txt", testWindows = true)
@@ -268,9 +270,11 @@ class UtilsSuite extends FunSuite with ResetSystemProperties {
268270
assertResolves("hdfs:/jar1,file:/jar2,jar3", s"hdfs:/jar1,file:/jar2,file:$cwd/jar3")
269271
assertResolves("hdfs:/jar1,file:/jar2,jar3,jar4#jar5,path to/jar6",
270272
s"hdfs:/jar1,file:/jar2,file:$cwd/jar3,file:$cwd/jar4%23jar5,file:$cwd/path%20to/jar6")
271-
assertResolves("""hdfs:/jar1,file:/jar2,jar3,C:\pi.py#py.pi,C:\path to\jar4""",
272-
s"hdfs:/jar1,file:/jar2,file:$cwd/jar3,file:/C:/pi.py%23py.pi,file:/C:/path%20to/jar4",
273-
testWindows = true)
273+
if (SystemUtils.IS_OS_WINDOWS) {
274+
assertResolves( """hdfs:/jar1,file:/jar2,jar3,C:\pi.py#py.pi,C:\path to\jar4""",
275+
s"hdfs:/jar1,file:/jar2,file:$cwd/jar3,file:/C:/pi.py%23py.pi,file:/C:/path%20to/jar4",
276+
testWindows = true)
277+
}
274278
}
275279

276280
test("nonLocalPaths") {
@@ -285,8 +289,8 @@ class UtilsSuite extends FunSuite with ResetSystemProperties {
285289
assert(Utils.nonLocalPaths("local:/spark.jar,file:/smart.jar,family.py") === Array.empty)
286290
assert(Utils.nonLocalPaths("hdfs:/spark.jar,s3:/smart.jar") ===
287291
Array("hdfs:/spark.jar", "s3:/smart.jar"))
288-
assert(Utils.nonLocalPaths("hdfs:/path to/spark.jar,path to/a.jar,s3:/path to/smart.jar") ===
289-
Array("hdfs:/path to/spark.jar", "s3:/path to/smart.jar"))
292+
assert(Utils.nonLocalPaths("hdfs:/spark.jar,path to/a.jar,s3:/smart.jar") ===
293+
Array("hdfs:/spark.jar", "s3:/smart.jar"))
290294
assert(Utils.nonLocalPaths("hdfs:/spark.jar,s3:/smart.jar,local.py,file:/hello/pi.py") ===
291295
Array("hdfs:/spark.jar", "s3:/smart.jar"))
292296
assert(Utils.nonLocalPaths("local.py,hdfs:/spark.jar,file:/hello/pi.py,s3:/smart.jar") ===
@@ -300,11 +304,6 @@ class UtilsSuite extends FunSuite with ResetSystemProperties {
300304
assert(Utils.nonLocalPaths("local:///C:/some/path.jar", testWindows = true) === Array.empty)
301305
assert(Utils.nonLocalPaths("hdfs:/a.jar,C:/my.jar,s3:/another.jar", testWindows = true) ===
302306
Array("hdfs:/a.jar", "s3:/another.jar"))
303-
assert(Utils.nonLocalPaths(
304-
"hdfs:/path to/spark.jar,C:\\path to\\a.jar,s3:/path to/smart.jar"
305-
, testWindows = true
306-
) ===
307-
Array("hdfs:/path to/spark.jar", "s3:/path to/smart.jar"))
308307
assert(Utils.nonLocalPaths("D:/your.jar,hdfs:/a.jar,s3:/another.jar", testWindows = true) ===
309308
Array("hdfs:/a.jar", "s3:/another.jar"))
310309
assert(Utils.nonLocalPaths("hdfs:/a.jar,s3:/another.jar,e:/our.jar", testWindows = true) ===

0 commit comments

Comments
 (0)