explode就是把一行中为数组类型的数据转为多行, 比如tableIP这个表中有个Iplist列的值是数组Array: [192.168.0.1,192.1680.2,192.168.0.3] 

使用explode后,会生成多行:

  sql: select explode(iplist) from tableIP;

  执行结果:

       192.168.0.1

       192.1680.2      

       192.168.0.3

  注意: 使用explode时,列需要是Array类型,如果不是Array类型而是string类型,需要先转换为Array类型。 

lateral view 一般情况下和explode这类UDTF连用, lateral view可以将结果放到一个虚拟表中, 并且把explode的每行结果与输入行join。

比如tableIP的表如下: 

   

name iplist
 office    [192.168.0.1,192.1680.2,192.168.0.3] 

 

如果我想把每个ip拆分出来,生成这样的结果: 

name ip
office 192.168.0.1
office 192.1680.2
office 192.168.0.3

可以使用如下sql: 

     select name,ip  from tableIP lateral view explode(iplist)  iplists as ip ;

lateral view直接outer关键词, 使用outer之后,可以达到类似left outer join的效果。 

 

 

   

      

相关文章:

  • 2022-01-02
  • 2021-08-25
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-05-17
  • 2022-12-23
  • 2021-07-06
猜你喜欢
  • 2021-09-16
  • 2021-06-22
  • 2021-10-15
  • 2021-12-05
  • 2022-12-23
  • 2021-07-28
  • 2021-12-01
相关资源
相似解决方案