繁体   English   中英

java.lang.ClassCast errors.GenericRowWithSchema 不能转换为 scala.collection.Seq

[英]java.lang.ClassCast errors.GenericRowWithSchema cannot be cast to scala.collection.Seq

如何将 map 的RDD转换为包装的Array ,我收到错误

架构:

在此处输入图片说明

当我尝试将数据帧转换为 pojo 时,出现如下异常:

java.lang.ClassCastException: 
  org.apache.spark.sql.catalyst.expressions.GenericRowWithSchema cannot 
  be cast to scala.collection.Seq

代码:

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
    })
  })
})

上面的异常只是一个类转换异常,因为struct 不能转换为 struct 的 Seq (参考 Schema: -- Pduct: struct (nullable = true) )。 将 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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM