[英]java.lang.ClassCast errors.GenericRowWithSchema cannot be cast to scala.collection.Seq
How to convert the RDD
of map to wrapped Array
, I am getting error如何将 map 的
RDD
转换为包装的Array
,我收到错误
Schema:架构:
When I am trying to convert dataframe to pojo, I am getting exception as below:当我尝试将数据帧转换为 pojo 时,出现如下异常:
java.lang.ClassCastException:
org.apache.spark.sql.catalyst.expressions.GenericRowWithSchema cannot
be cast to scala.collection.Seq
Code:代码:
rdd.map(row => {
var arrm_list: Seq[Row] = rows.getAs[AnyRef]("ArrTeber").asInstanceOf[Seq[Row]]
//working fine here
arrm_list.foreach(x => {
var arrmtrb__list: Seq[Row] = rows.getAs[AnyRef]("ArrTeberPRD").asInstanceOf[Seq[Row]]
//working fine here
arrmtrb__list.foreach(pt => {
var pd__list: Seq[Row] = rows.getAs[AnyRef]("Pduct").asInstanceOf[Seq[Row]] //raising error
})
})
})
The above exception is simply a class cast exception, Since struct cannot be cast to Seq of struct (Refer Schema: -- Pduct: struct (nullable = true) ).上面的异常只是一个类转换异常,因为struct 不能转换为 struct 的 Seq (参考 Schema: -- Pduct: struct (nullable = true) )。 Cast Pduct to Row and then extract nested members.
将 Pduct 转换为 Row,然后提取嵌套成员。
df.map(row => {
var arrm_list: Seq[Row] = row.getAs[Seq[Row]]("ArrTeber")
arrm_list.foreach(x => {
var arrmtrb__list: Seq[Row] = x.getAs[Seq[Row]]("ArrTeberPRD")
arrmtrb__list.foreach(pt => {
var pd__list: Row = pt.getAs[Row]("Pduct") //Pduct: struct (nullable = true)
})
})
})
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.