引用这里和这里,我希望我应该能够通过使用octothorpe来更改spark中引用文件的名称—也就是说,如果我调用 spark-submit --files local-file-name.json#spark-file-name.json
,我应该可以引用文件 spark-file-name.json
. 然而,情况似乎并非如此:
$ cat ../differentDirectory/local-file-name.json
{
"name": "Adam",
"age": 25
}
$ cat testing1.py
import os
import json
import time
from pyspark import SparkFiles, SparkContext
print(os.getcwd())
print(os.listdir('.'))
sc = SparkContext('local', 'App For Testing --files upload')
print(SparkFiles.getRootDirectory())
print(os.listdir(SparkFiles.getRootDirectory()))
print(json.load(open(SparkFiles.get('local-file-name.json'))))
$ spark-submit --files ../differentDirectory/local-file-name.json testing1.py
20/08/06 17:05:00 WARN NativeCodeLoader: Unable to load native-hadoop library for your platform... using builtin-java classes where applicable
/private/tmp/sparkSubmitTesting
['testing.py']
...
/private/var/folders/0q/qw3xxl5x2yx1rf1nncl6s4rw2yzhgq/T/spark-2d052f27-59da-463a-9ddf-edd05108c19a/userFiles-5fec4b39-90e3-4402-a644-0c5314c1d0a5
[u'local-file-name.json']
{u'age': 25, u'name': u'Adam'}
...
$ cat testing2.py
import os
import json
import time
from pyspark import SparkFiles, SparkContext
print(os.getcwd())
print(os.listdir('.'))
sc = SparkContext('local', 'App For Testing --files upload')
print(SparkFiles.getRootDirectory())
print(os.listdir(SparkFiles.getRootDirectory()))
print(json.load(open(SparkFiles.get('spark-file-name.json'))))
$ spark-submit --files ../differentDirectory/local-file-name.json#spark-file-name.json testing2.py
20/08/06 17:07:35 WARN NativeCodeLoader: Unable to load native-hadoop library for your platform... using builtin-java classes where applicable
/private/tmp/sparkSubmitTesting
['testing.py']
...
20/08/06 17:07:38 ERROR SparkContext: Error initializing SparkContext.
java.io.FileNotFoundException: File file:/private/tmp/differentDirectory/local-file-name.json#spark-file-name.json does not exist
at org.apache.hadoop.fs.RawLocalFileSystem.deprecatedGetFileStatus(RawLocalFileSystem.java:611)
at org.apache.hadoop.fs.RawLocalFileSystem.getFileLinkStatusInternal(RawLocalFileSystem.java:824)
at org.apache.hadoop.fs.RawLocalFileSystem.getFileStatus(RawLocalFileSystem.java:601)
at org.apache.hadoop.fs.FilterFileSystem.getFileStatus(FilterFileSystem.java:421)
at org.apache.spark.SparkContext.addFile(SparkContext.scala:1544)
at org.apache.spark.SparkContext.addFile(SparkContext.scala:1508)
at org.apache.spark.SparkContext$$anonfun$13.apply(SparkContext.scala:462)
at org.apache.spark.SparkContext$$anonfun$13.apply(SparkContext.scala:462)
at scala.collection.immutable.List.foreach(List.scala:392)
at org.apache.spark.SparkContext.<init>(SparkContext.scala:462)
at org.apache.spark.api.java.JavaSparkContext.<init>(JavaSparkContext.scala:58)
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
at java.lang.reflect.Constructor.newInstance(Constructor.java:423)
at py4j.reflection.MethodInvoker.invoke(MethodInvoker.java:247)
at py4j.reflection.ReflectionEngine.invoke(ReflectionEngine.java:357)
at py4j.Gateway.invoke(Gateway.java:238)
at py4j.commands.ConstructorCommand.invokeConstructor(ConstructorCommand.java:80)
at py4j.commands.ConstructorCommand.execute(ConstructorCommand.java:69)
at py4j.GatewayConnection.run(GatewayConnection.java:238)
at java.lang.Thread.run(Thread.java:748)
我试过用反斜杠转义#(即- --files ../differentDirectory/local-file-name.json\#spark-file-name.json
)用引号括住文件路径,并显式地加上前缀 file://
但在所有情况下,我要么得到相同的错误( File <path, including fragment> does not exist
),或 Expected scheme-specific part at index 5
macos,spark v2.4.5版
1条答案
按热度按时间kzipqqlq1#
一位同事指出,这种重命名行为依赖于yarn,而在本地运行时它是不存在的,因此在我的设置中,这个特性是不起作用的。