hsql中split函数,lateral view explode的常规用法

1.split()函数

hsql中split(item,'分隔符')

2.lateral view

explode将复杂结构一行拆成多行,实现行转列,如

id     name

1      hell,hao,de

select  explode(split(name,','))  from tablename;

id   name

1      hello

1       hao

1      he 

Lateral view:lateral view用于和split、explode等UDTF一起使用的,能将一行数据拆分成多行数据,在此基础上可以对拆分的数据进行聚合,lateral view首先为原始表的每行调用UDTF,UDTF会把一行拆分成一行或者多行,lateral view在把结果组合,产生一个支持别名表的虚拟表。 
select id,name2 from tablename lateral view explode(split(name,’,’))   c as name2; 

c是虚拟表的表名(必填),name2是分割字段的新名字;
输出: id   name2

           1      hello

           1       hao

           1       he 

生成虚拟表之后,可以对虚拟表聚合计算

  

实例:

select count(distinct a.thrknow) from (select distinct thrknow from dm_questlabel.fact_quest_label 
lateral view explode(split(three_know,'\\^\\.\\^')) c AS thrknow
where questinnersource=4 and subject='C01'  and fastdfsurl like 'group%'  and docfastdfsurl 
like 'group%' and pngfastdfsurl like 'group%';


 

猜你喜欢

转载自blog.csdn.net/qq_35958094/article/details/81634842