Skip to content

Commit 156ac27

Browse files
Tom GravesMarcelo Vanzin
authored andcommitted
[SPARK-10858] YARN: archives/jar/files rename with # doesn't work unl
https://issues.apache.org/jira/browse/SPARK-10858 The issue here is that in resolveURI we default to calling new File(path).getAbsoluteFile().toURI(). But if the path passed in already has a # in it then File(path) will think that is supposed to be part of the actual file path and not a fragment so it changes # to %23. Then when we try to parse that later in Client as a URI it doesn't recognize there is a fragment. so to fix we just check if there is a fragment, still create the File like we did before and then add the fragment back on. Author: Tom Graves <[email protected]> Closes #9035 from tgravescs/SPARK-10858. (cherry picked from commit 63c340a)
1 parent f95129c commit 156ac27

File tree

2 files changed

+10
-3
lines changed

2 files changed

+10
-3
lines changed

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

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1751,6 +1751,13 @@ private[spark] object Utils extends Logging {
17511751
if (uri.getScheme() != null) {
17521752
return uri
17531753
}
1754+
// make sure to handle if the path has a fragment (applies to yarn
1755+
// distributed cache)
1756+
if (uri.getFragment() != null) {
1757+
val absoluteURI = new File(uri.getPath()).getAbsoluteFile().toURI()
1758+
return new URI(absoluteURI.getScheme(), absoluteURI.getHost(), absoluteURI.getPath(),
1759+
uri.getFragment())
1760+
}
17541761
} catch {
17551762
case e: URISyntaxException =>
17561763
}

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -384,7 +384,7 @@ class UtilsSuite extends SparkFunSuite with ResetSystemProperties with Logging {
384384
assertResolves("hdfs:/root/spark.jar", "hdfs:/root/spark.jar")
385385
assertResolves("hdfs:///root/spark.jar#app.jar", "hdfs:/root/spark.jar#app.jar")
386386
assertResolves("spark.jar", s"file:$cwd/spark.jar")
387-
assertResolves("spark.jar#app.jar", s"file:$cwd/spark.jar%23app.jar")
387+
assertResolves("spark.jar#app.jar", s"file:$cwd/spark.jar#app.jar")
388388
assertResolves("path to/file.txt", s"file:$cwd/path%20to/file.txt")
389389
if (Utils.isWindows) {
390390
assertResolves("C:\\path\\to\\file.txt", "file:/C:/path/to/file.txt")
@@ -414,10 +414,10 @@ class UtilsSuite extends SparkFunSuite with ResetSystemProperties with Logging {
414414
assertResolves("file:/jar1,file:/jar2", "file:/jar1,file:/jar2")
415415
assertResolves("hdfs:/jar1,file:/jar2,jar3", s"hdfs:/jar1,file:/jar2,file:$cwd/jar3")
416416
assertResolves("hdfs:/jar1,file:/jar2,jar3,jar4#jar5,path to/jar6",
417-
s"hdfs:/jar1,file:/jar2,file:$cwd/jar3,file:$cwd/jar4%23jar5,file:$cwd/path%20to/jar6")
417+
s"hdfs:/jar1,file:/jar2,file:$cwd/jar3,file:$cwd/jar4#jar5,file:$cwd/path%20to/jar6")
418418
if (Utils.isWindows) {
419419
assertResolves("""hdfs:/jar1,file:/jar2,jar3,C:\pi.py#py.pi,C:\path to\jar4""",
420-
s"hdfs:/jar1,file:/jar2,file:$cwd/jar3,file:/C:/pi.py%23py.pi,file:/C:/path%20to/jar4")
420+
s"hdfs:/jar1,file:/jar2,file:$cwd/jar3,file:/C:/pi.py#py.pi,file:/C:/path%20to/jar4")
421421
}
422422
}
423423

0 commit comments

Comments
 (0)