当前位置: 首页 > news >正文

posexplode函数实战总结

目录

1、建表和准备数据

2、炸裂实践

3、错误炸裂方式

4、当字段类型为string,需要split一下


对单列array类型的字段进行炸裂时,可以使用lateral view explode

对多列array类型的字段进行炸裂时,可以使用lateral view posexplode。

1、建表和准备数据

--测试posexplode
create table tmp.test_lateral_view_movie_230831(class string,name array<string>,score array<string>);insert into tmp.test_lateral_view_movie_230831 select 'calss1',array('A','B','C'),array('61','66','90');
insert into tmp.test_lateral_view_movie_230831 select 'calss2',array('D','E','F','G'),array('56','67','78','76');
insert into tmp.test_lateral_view_movie_230831 select 'calss3',array('X','Y','Z'),array('77','88','99');select * from tmp.test_lateral_view_movie_230831;

表中数据

2、炸裂实践

--双列炸裂 poexplode 可以将index和数据都取出来,使用两次posexplode并令两次取到的index相等
select class,index_na+1 as stu_id,tmp_name,tmp_score
from tmp.test_lateral_view_movie_230831 
lateral view posexplode(name) tmp_na as index_na,tmp_name
lateral view posexplode(score) tmp_sc as index_sc,tmp_score
where index_na = index_sc

结果

3、错误炸裂方式

--炸裂列会相互交叉,类似与笛卡尔积
select class,tmp_name,tmp_score
from tmp.test_lateral_view_movie_230831 
lateral view explode(name) tmp as tmp_name
lateral view explode(score) tmp as tmp_score

或者

--嵌套炸裂
select  class,tmp_name,tmp_score
from 
(select class,tmp_name,scorefrom tmp.test_lateral_view_movie_230831 lateral view explode(name) tmp as tmp_name
) a
lateral view explode(score) tmp as tmp_score

结果

4、当字段类型为string,需要split一下

create table tmp.test_lateral_view_movie_230831_01(class string,name string,score string);insert into tmp.test_lateral_view_movie_230831_01 select 'calss1','A,B,C','61,66,90';
insert into tmp.test_lateral_view_movie_230831_01 select 'calss2','D,E,F,G','56,67,78,76';
insert into tmp.test_lateral_view_movie_230831_01 select 'calss3','X,Y,Z','77,88,99';select * from tmp.test_lateral_view_movie_230831_01;

表中数据:

炸裂:

select class,index_n+1 as id,nn_name,ss_score
from tmp.test_lateral_view_movie_230831_01 
lateral view posexplode(split(name,',')) nn as index_n,nn_name
lateral view posexplode(split(score,',')) ss as index_s,ss_score
where index_n = index_s

结果

http://www.lryc.cn/news/149712.html

相关文章:

  • QTday3(对话框、发布软件、事件处理核心机制)
  • el-date-picker限制选择的时间范围
  • Scala中的Actor模型
  • Java使用pdfbox将pdf转图片
  • 大规模场景下对Istio的性能优化
  • 数字化新零售平台系统提供商,门店商品信息智慧管理-亿发进销存
  • postgresql-窗口函数
  • Revit SDK 介绍:CreateAirHandler 创建户式风管机
  • 微信小程序云开发-云函数发起https请求简易封装函数
  • 深入探索PHP编程:连接数据库的完整指南
  • 【Centos8配置节点免密登陆】
  • 不可变集合、Lambda表达式、Stream流
  • Three.js GLTF模型加载
  • 外包干了2个月,技术退步明显...
  • java八股文面试[多线程]——主内存和工作内存的关系
  • 技术分享 | LSM,Linux 内核的安全防护盾
  • http服务(Apache 2.4.57)源码编译及使用
  • 【1day】H5S视频平台未授权漏洞学习
  • 企业架构LNMP学习笔记3
  • 使用Spring Boot和Kafka实现消息发送和订阅
  • 探讨uniapp的组件使用的问题
  • 【跟小嘉学 Rust 编程】十七、面向对象语言特性
  • mall :rabbit项目源码解析
  • JDBC连接数据库
  • Linux学习之Ubuntu 20中OpenResty的nginx目录里内容和配置文件
  • 使用axi_quad_spi操作spi_flash
  • Linux:tomcat (源码包安装)(官网下载-安装-启动-配置-等等等-----从入门到入土)
  • 中科驭数以DPU先进计算技术,夯实下一代金融IT基础设施底座
  • Android 手游聚合SDK小知识(二) 聚合分包
  • 【RISC-V】RISC-V寄存器