从spark scala中的外部路径读取属性文件时出错

从spark scala中的外部路径读取属性文件时出错,scala,apache-spark,Scala,Apache Spark,我试图从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

我试图从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")
我也试过这样:

    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)
 
diagnostics:User类引发异常:java.io.FileNotFoundException:/hadoopfs/fs1/data/hdfs1/hadoop/warn/local/usercache/User/appcache/application_1598445422718_5591/spark-78c8ae71-3381-4317-90e1-d5a6bda2956/userFil9a-b3c7-4b24-8227-441837/User/mine/dev.properties(无此类文件或目录)
位于java.io.FileInputStream.open0(本机方法)
在java.io.FileInputStream.open(FileInputStream.java:195)
位于java.io.FileInputStream。(FileInputStream.java:138)
位于scala.io.Source$.fromFile(Source.scala:91)
位于scala.io.Source$.fromFile(Source.scala:76)
位于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)
 
20/11/17 07:57:45信息客户端:
客户端令牌:令牌{种类:纱线\客户端\令牌,服务:}
诊断:用户类引发异常:java.io.FileNotFoundException:/User/mine/dev.properties(没有这样的文件或目录)
位于java.io.FileInputStream.open0(本机方法)
在java.io.FileInputStream.open(FileInputStream.java:195)
位于java.io.FileInputStream。(FileInputStream.java:138)
位于scala.io.Source$.fromFile(Source.scala:91)
位于scala.io.Source$.fromFile(Source.scala:76)
位于scala.io.Source$.fromFile(Source.scala:54)

您可以尝试使用“dev.properties”吗。代替“/user/mine/dev.properties”@maximeG的是相同的错误,您在该路径中安装了HDFS。我假设您正在一个容器中运行Spark驱动程序,该容器在您的文件系统中映射了HDFS路由。更改属性文件位置。@EmiCareOfCell44。我不明白你的意思。如果我打印我在第一个方法中使用的路径,它与路径thrwing error>这个sis路径相同,由记录器语句打印:``/hadoopfs/fs1/data/hdfs1/hadoop/thread/local/usercache/user/appcache/application\u 1598445422718\u 5591/spark-78c8ae71-3381-4317-90e1-d5a6bda2956/userFil9a-b3c7-4b24-8227-441837/user/mine/dev.properties```