Spark Dataframe计数函数以及其他许多函数抛出IndexOutOfBoundsException [英] Spark Dataframe count function and many more functions throw IndexOutOfBoundsException
本文介绍了Spark Dataframe计数函数以及其他许多函数抛出IndexOutOfBoundsException的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
1)使用空值初始过滤的RDD.
val rddWithOutNull2 = rddSlices.filter(x => x(0) != null)
2)然后将这个RDD转换为Row的RDD
3)使用Scala将RDD转换为Dataframe后:
val df = spark.createDataFrame(rddRow,schema)
df.printSchema()
输出:
root
|-- name: string (nullable = false)
println(df.count())
输出:
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
- 在此spark数据帧上没有其他Spark sql函数.
推荐答案
同意注释,问题似乎出在x(0)中.如果有一个空行,它将抛出该Exception
.一种解决方案(取决于变量x
的类型)是使用headOption
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)
这篇关于Spark Dataframe计数函数以及其他许多函数抛出IndexOutOfBoundsException的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文