炸裂:将一行数据,炸裂为多行, 也就是“列转行”
例如:hive的订单表order_table有一个字段item_list,是一个列表结构的
array<struct<item_id:string,item_sku_id:string,price:double,quantity:bigint,title:string>>
item_list中有多个商品信息,每个商品信息是一个结构体,那么如何将一个order_id对应的商品列表,转化为多行?即炸裂为多行
使用explode()函数就可以实现
val order_item_df = spark.sql(s"select order_id, explode(item_list) as item_list from vc.order_basic_info where day='2020-12-17'").
select("order_id", "item_list.item_id", "item_list.title").show(1000)
运行的结果如下: