hive lateral view explode列拆分与行转列用法

在日常工作中,我们在处理数据时,会遇到某个列存在多个数据的情况,如果想拿到这个列里面每个数据进行后续处理的话,这种情况下有两种处理方式:

第一种:如果这个列多个数据是固定数目,可以使用split切分

第二种:如果是不定数目,下面我们就来看看这种情况要怎么处理。

先创建一张临时表供测试,sql如下:

-- 执行引擎:spark引擎
-- 1.创建表
create table tmp.tmp1(book_name string comment '书名',character_name string comment '人名');

-- 2.插入数据
insert into tmp.tmp1
select 
"《凡人修仙传》" as book_name,"韩立" as character_name
union all
select
"《凡人修仙传》" as book_name,"厉飞雨" as character_name
union all
select
"《凡人修仙传》" as book_name,"南宫婉" as character_name
union all
select
"《凡人修仙传》" as book_name,"紫灵仙子" as character_name
union all
select
"《凡人修仙传》" as book_name,"银月" as character_name
union all
select
"《凡人修仙传》" as book_name,

你可能感兴趣的:(hive,hadoop,数据仓库)