Getting “org.apache.spark.sql.AnalysisException: Path does not exist” from SparkSession.read() [duplicate]

人走茶凉 提交于 2021-02-18 17:44:26

问题


I am trying to read a file submitted by spark-submit to yarn cluster in client mode. Putting file in HDFS is not an option. Here's what I've done:

def main(args: Array[String]) {
   if (args != null && args.length > 0) {
        val inputfile: String = args(0)

        //get filename: train.csv
        val input_filename = inputfile.split("/").toList.last 

        val d = SparkSession.read
                .option("header", "true")
                .option("inferSchema", "true")
                .csv(SparkFiles.get(input_filename))
        d.show() 
   }   
}

and submitted to yarn this way:

spark2-submit \
--class "com.example.HelloWorld" \
--master yarn --deploy-mode client \
--files repo/data/train.csv \
--driver-cores 2 helloworld-assembly-0.1.jar repo/data/train.csv

but I got an exception:

Exception in thread "main" org.apache.spark.sql.AnalysisException: Path does not exist: hdfs://xxxxx.xxxxx.xxxx.com:8020/tmp/spark-db3ee991-7f3d-427c-8479-aa212f906dc5/userFiles-040293ee-0d1f-44dd-ad22-ef6fe729bd49/train.csv; 

and I've also tried:

val input_filename_1 = """file://""" + SparkFiles.get(input_filename)
println(input_filename_1)

SparkSession.read
  .option("header", "true")
  .option("inferSchema", "true")
  .csv(input_filename_1) 

and still got a similar error:

 file:///tmp/spark-fbd46e9d-c450-4f86-8b23-531e239d7b98/userFiles-8d129eb3-7edc-479d-aeda-2da98432fc50/train.csv
 Exception in thread "main" org.apache.spark.sql.AnalysisException: Path does not exist: file:/tmp/spark-fbd46e9d-c450-4f86-8b23-531e239d7b98/userFiles-8d129eb3-7edc-479d-aeda-2da98432fc50/train.csv;

回答1:


I tried the same scenario with --files test.csv and with spark.sparkContext.addFile("test.csv")

spark.sparkContext.addFile("test.csv")
val df = spark.read.option("header", "true").option("inferSchema", "true").csv("file://"+SparkFiles.get("test.csv"))

File you get with scala> SparkFiles.get("test.csv")

Ex : /tmp/spark-9c4ea9a6-95d7-44ff-8cfb-1d9ce9f30638/userFiles-f8909daa-9710-4416-b0f0-9d9043db5d8c/test.csv is created on local file system where you submit the job.

So workers do not have this file to read. Problem might be with using spark.read.csv

Edit:

I tried copying locally created file to other nodes. It worked.

Hope this would help.



来源:https://stackoverflow.com/questions/53557327/getting-org-apache-spark-sql-analysisexception-path-does-not-exist-from-spark

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!