Apache spark 在apache spark上执行sql查询时发生arrayindexoutofbound异常

Apache spark 在apache spark上执行sql查询时发生arrayindexoutofbound异常,apache-spark,apache-spark-sql,Apache Spark,Apache Spark Sql,我使用Spark中的以下命令在Spark中创建了一个表 case class trip(trip_id: String, duration: String, start_date: String, start_station: String, start_terminal: String, end_date: String, end_station: String, end_terminal: String, bike: String, su

我使用Spark中的以下命令在Spark中创建了一个表

case class trip(trip_id: String, duration: String, start_date: String, 
        start_station: String, start_terminal: String, end_date: String, 
        end_station: String, end_terminal: String, bike: String, 
        subscriber_type: String, zipcode: String)

    val trip_data = sc.textFile("/user/sankha087_gmail_com/trip_data.csv")

    val tripDF = trip_data
        .map(x=> x.split(","))
        .filter(x=> (x(1)!= "Duration"))
        .map(x=> trip(x(0),x(1),x(2),x(3),x(4),x(5),x(6),x(7),x(8),x(9),x(10)))
        .toDF() 

    tripDF.registerTempTable("tripdatas")

    sqlContext.sql("select * from tripdatas").show()
如果我正在运行上面的查询,即select*,那么我将得到所需的结果,但是如果我运行下面的查询,那么我将得到下面的异常:

sqlContext.sql("select count(1) from tripdatas").show() 
2007年3月18日17:59:55错误调度程序。TaskSetManager:阶段2.0中的任务1失败4次;中止工作 org.apache.spark.sparkeexception:作业因阶段失败而中止:阶段2.0中的任务1失败4次,最近的失败:阶段2中的任务1.3丢失。 0 TID 6,datanode1-cloudera.mettl.com,执行器1:java.lang.ArrayIndexOutofBounds异常:10 在$iwC$$iwC$$iwC$$iwC$$iwC$$iwC$$iwC$$iwC$$anonfun$3。申请:31 在$iwC$$iwC$$iwC$$iwC$$iwC$$iwC$$iwC$$iwC$$anonfun$3。申请:31***


检查您的数据。如果数据中的任何行少于11个元素,您将看到该错误

您可以尝试以这种方式查看最小列数

val trip_data = spark.read.csv("/user/sankha087_gmail_com/trip_data.csv")
println(trip_data.columns.length)

我在试你建议的命令,但是得到以下异常:`scala>val trip_data\u sample=spark.read.csv/user/sankha087\u gmail\u com/trip_data.csv:25:错误:未找到:值spark valtrip_data_sample=spark.read.csv/user/sankha087_gmail_com/trip_data.csv`请帮助'spark'只是使用spark外壳时自动创建的spark会话。如果你正在编写一个spark应用程序,只要用你正在生成的sparkSession替换它即可。这只是查看数据中列数的一种简便方法。如果文件不太大,您始终可以执行手动检查。如果错误消息由tripdatas.show中的sqlContext.sqlselect count1显示,则错误消息也应与tripdatas.show中的sqlContext.sqlselect*一起显示