栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 前沿技术 > 大数据 > 大数据系统

Hive将数组炸开

Hive将数组炸开

split:按特定符号切分为数组
explode:将数组数据炸开,单个select限制一个explode
LATERAL VIEW:侧写函数,可以使explode同其他字段一起查询

select 
    distinct c1
    ,case 
        when c2 = 'A级' then c2 
        when LOCATE('线',c2)=0 then concat(c2,'线')
        else c2 end as c2
      ,c3 
      ,c4
  from table as a
  
  LATERAL VIEW explode(split(a.c1,',')) a AS c1
  LATERAL VIEW explode(split(a.c2,',')) a AS c2
  where a.ds = '${yyyyMMdd,-1d}'

单独使用情况下:

select 
    explode(split(c1,',') ) as c1
from table
where ds = '${yyyyMMdd,-1d}'

spilt以后的数据,

结果

select 
    distinct explode(split(region_code,',') ) as region_code
    
select distinct c1
from table_name as a
lateral view explode(split(region_code,',')) a as c1
where ds = '${yyyyMMdd,-1d}'

转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/775712.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号