Error while exploding a struct column in Spark

后端 未结 3 736
孤城傲影
孤城傲影 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:48

    You can use explode in an array or map columns so you need to convert the properties struct to array and then apply the explode function as below

    import org.apache.spark.sql.functions._
    df_json.withColumn("event_properties", explode(array($"event.properties.*"))).show(false)
    

    You should have your desired requirement

提交回复
热议问题