Spark Dataframe count function and many more functions throw IndexOutOfBoundsException

核能气质少年 提交于 2019-12-08 07:37:23

问题


1) Initially filtered RDD with null values.

val rddWithOutNull2 = rddSlices.filter(x => x(0) != null)

2) Then converted this RDD to RDD of Row

3) After converting RDD to Dataframe using Scala :

val df = spark.createDataFrame(rddRow,schema)
df.printSchema()

Output:

root
 |-- name: string (nullable = false)


println(df.count())

Output:

Error : 
count : : 
[Stage 11:==================================>                       (3 + 2) / 5][error] o.a.s.e.Executor - Exception in task 4.0 in stage 11.0 (TID 16)
java.lang.IndexOutOfBoundsException: 0
  • No other spark sql functions working on this spark dataframe.

回答1:


Agree with the comments, the problem seems to be in x(0). If there is an empty row, it will throw that Exception. One solution (depending on the type of the variable x) is to retrieve it with a headOption

val rddWithOutNull2 = rddSlices.filter(_.headOption.isDefined)


来源:https://stackoverflow.com/questions/48416695/spark-dataframe-count-function-and-many-more-functions-throw-indexoutofboundsexc

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