错误:带有hadoop的spark提交中不存在路径

时间:2018-06-06 22:28:01

标签: apache-spark hadoop cluster-computing yarn spark-submit

我们使用命令/home/ubuntu/spark/bin/spark-submit --master yarn --deploy-mode cluster --class "SimpleApp" /home/ubuntu/spark/examples/src/main/scala/sbt/target/scala-2.11/teste_2.11-1.0.jar来运行下面的脚本

import org.apache.spark.sql.SQLContext
import org.apache.spark.sql._
import org.apache.spark.sql.types._
import org.apache.spark.sql.SparkSession
import org.apache.spark._
import org.apache.spark
import org.apache.spark.sql
import org.apache.spark.SparkContext._


object SimpleApp {
     def main(args: Array[String]) {

     val spark = SparkSession.builder().appName("query1").master("yarn").getOrCreate
     val header = StructType(Array(
             StructField("medallion", StringType, true),
             StructField("hack_license", StringType, true),
             StructField("vendor_id", StringType, true),
             StructField("rate_code", IntegerType, true),
             StructField("store_and_fwd_flag", StringType, true),
             StructField("pickup_datetime", TimestampType, true),
             StructField("dropoff_datetime", TimestampType, true),
             StructField("passenger_count", IntegerType, true),
             StructField("trip_time_in_secs", IntegerType, true),
             StructField("trip_distance", FloatType, true),
             StructField("pickup_longitude", FloatType, true),
             StructField("pickup_latitude", FloatType, true),
             StructField("dropoff_longitude", FloatType, true),
             StructField("dropoff_latitude", FloatType, true),
             StructField("payment_type", StringType, true),
             StructField("fare_amount", FloatType, true),
             StructField("surcharge", FloatType, true),
             StructField("mta_tax", FloatType, true),
             StructField("trip_amount", FloatType, true),
             StructField("tolls_amount", FloatType, true),
             StructField("total_amount", FloatType, true),
             StructField("zone", StringType, true)))

     val nyct = spark.read.format("csv").option("delimiter", ",").option("header", "true").schema(header).load("/home/ubuntu/trip_data/trip_data_fare_1.csv")
     nyct.createOrReplaceTempView("nyct_temp_table")

     spark.time(spark.sql("""SELECT zone, COUNT(*) AS accesses FROM nyct_temp_table WHERE (HOUR(dropoff_datetime) >= 8 AND HOUR(dropoff_datetime) <= 19) GROUP BY zone ORDER BY accesses DESC""").show())

     }
 }

这个想法是将脚本中的查询运行到带有spark和Hadoop的集群中。但是在执行结束时,这会从路径/home/ubuntu/trip_data/trip_data_fare_1.csv生成一个csv文件。 This is the picture of the error

我认为问题是节点slave无法在master目录中找到该文件。有人知道如何解决此问题并在群集中运行此脚本?

2 个答案:

答案 0 :(得分:0)

由于您在群集中运行,因此您应该在hdfs中拥有此文件。您可以使用以下命令将文件从本地文件系统复制到HDFS:

hadoop fs -put source_path dest_path

然后在代码中使用dest_path。

对于您,请在具有本地文件的主机上执行此操作:

hadoop fs -put /home/ubuntu/trip_data/trip_data_fare_1.csv <some_hdfs_location>

通过执行以下操作验证副本是否有效:

hdfs dfs -ls <some_hdfs_location>

答案 1 :(得分:0)

如果我没有错,那么Spark正在考虑将您的本地文件系统作为其默认文件系统,这就是您遇到此错误的原因。配置应该传递到Spark上下文中,您应该提到{{1在所有节点的HADOOP_CONF_DIR文件中。确保在所有节点中指定spark-env.sh

HADOOP_CONF_DIR