我尝试从spark scala中的外部路径读取属性文件,如下所示:
spark-submit --class com.spark.scala.my.class --deploy-mode cluster --master yarn --files /user/mine/dev.properties /path/to/jar/dev-0.0.1-SNAPSHOT-uber.jar 2020-08-19T06:00:00Z 2020-08-20T07:00:00Z
我是这样读的:
val props = new Properties()
val filePath = SparkFiles.get("/user/mine/dev.properties")
LOGGER.info("Path to file : "+ filePath)
val is= Source.fromFile(filePath)
props.load(is.bufferedReader())
我也试过这样:
val is= Source.fromFile("/user/mine/dev.properties")
但在以下两种情况下均未发现获取文件异常:
diagnostics: User class threw exception: java.io.FileNotFoundException: /hadoopfs/fs1/data/hdfs1/hadoop/yarn/local/usercache/user/appcache/application_1598445422718_5591/spark-78c8ae71-3381-4317-90e1-d5a6da6b2956/userFil9a-b3c7-4b24-8227-441837/user/mine/dev.properties (No such file or directory)
at java.io.FileInputStream.open0(Native Method)
at java.io.FileInputStream.open(FileInputStream.java:195)
at java.io.FileInputStream.<init>(FileInputStream.java:138)
at scala.io.Source$.fromFile(Source.scala:91)
at scala.io.Source$.fromFile(Source.scala:76)
at scala.io.Source$.fromFile(Source.scala:54)
当我不使用spark.file时,我会得到:
20/11/17 07:57:45 INFO Client:
client token: Token { kind: YARN_CLIENT_TOKEN, service: }
diagnostics: User class threw exception: java.io.FileNotFoundException: /user/mine/dev.properties (No such file or directory)
at java.io.FileInputStream.open0(Native Method)
at java.io.FileInputStream.open(FileInputStream.java:195)
at java.io.FileInputStream.<init>(FileInputStream.java:138)
at scala.io.Source$.fromFile(Source.scala:91)
at scala.io.Source$.fromFile(Source.scala:76)
at scala.io.Source$.fromFile(Source.scala:54)
暂无答案!
目前还没有任何答案,快来回答吧!