Error while exploding a struct column in Spark

后端 未结 3 735
孤城傲影
孤城傲影 2021-01-17 16:30

I have a dataframe whose schema looks like this:

event: struct (nullable = true)
|    | event_category: string (nullable = true)
|    | event_name: string (n         


        
3条回答
  •  不要未来只要你来
    2021-01-17 16:44

    You may use following to flatten the struct. Explode does not work for struct as error message states.

    val explodeDF = parquetDF.explode($"event") { 
    case Row(properties: Seq[Row]) => properties.map{ property =>
      val errorCode = property(0).asInstanceOf[String]
      val errorDescription = property(1).asInstanceOf[String]
      Event(errorCode, errorDescription, email, salary)
     }
    }.cache()
    display(explodeDF)
    

提交回复
热议问题