-
Notifications
You must be signed in to change notification settings - Fork 28.1k
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
[SPARK-6300][Spark Core] sc.addFile(path) does not support the relative path. #4993
Changes from 7 commits
c3f046f
cb1852d
c87e8b6
161cae3
e4a13fe
dced8eb
0ff3fa8
d594e16
ee375cd
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 |
---|---|---|
|
@@ -106,6 +106,35 @@ class SparkContextSuite extends FunSuite with LocalSparkContext { | |
sc.stop() | ||
} | ||
} | ||
|
||
test("addFile works with relative path") { | ||
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. Rather than copy and paste the test I wonder if this can just be injected into the "addFile works" test. Like, make the test file a relative path there. Also I see that test doesn't use the framework provided temp dir which you did correctly here. 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. I think it would be good to test both absolute and relative paths. Maybe we can break the meat of the test out into a separate function and have both tests call it. |
||
val pluto = Utils.createTempDir() | ||
val file = File.createTempFile("someprefix", "somesuffix", pluto) | ||
val relativePath = file.getParent + "/../" + file.getParentFile.getName + "/" + file.getName | ||
val absolutePath = file.getAbsolutePath | ||
try { | ||
Files.write("somewords", file, UTF_8) | ||
val length = file.length() | ||
sc = new SparkContext(new SparkConf().setAppName("test").setMaster("local")) | ||
sc.addFile(relativePath) | ||
sc.parallelize(Array(1), 1).map(x => { | ||
val gotten = new File(SparkFiles.get(file.getName)) | ||
if (!gotten.exists()) { | ||
throw new SparkException("file doesn't exist") | ||
} | ||
if (length != gotten.length()) { | ||
throw new SparkException( | ||
s"file has different length $length than added file ${gotten.length()}") | ||
} | ||
if (absolutePath == gotten.getAbsolutePath) { | ||
throw new SparkException("file should have been copied") | ||
} | ||
x | ||
}).count() | ||
} finally { | ||
sc.stop() | ||
} | ||
} | ||
|
||
test("addFile recursive works") { | ||
val pluto = Utils.createTempDir() | ||
|
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.
I think this might be slightly more robust as
new File(path).getCanonicalFile.toURI.toString
. Then the"file:"
can go away too.