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;