hive collect_set,lateral view,explode 实现行列转换
来源:互联网 发布:c语言经典书 编辑:程序博客网 时间:2024/05/22 01:38
1、建表
create table if not exists temp.lateral_test(id string, value string) ROW format delimited FIELDS TERMINATED BY ',' ;
2、插入数据
load date local inpath 'latearl.txt' overwrite into table temp.lateral_test;select * from lateral_test;数据如下:
3.1、collect_set:去重、变数组(列传行)
select id,collect_set(value) as a from temp.lateral_test group by id
3.2、数组前加序号访问对应元素,从0开始
select id, a[0] a0, a[1] a1 from (select id,collect_set(value) as a from temp.lateral_test group by id) b
4、利用lateral view explode 对3.1的数据实现行转列(k、hh别名不可少)
select id, hhfrom (select id,collect_set(value)as a from temp.lateral_test group by id)tlateral view explode(a)k as hh
PS:explode 可以把单行数组类型数据转为列形式:
select explode(split(concat_ws(',','1','2','3','4'),','))
阅读全文
1 0
- hive collect_set,lateral view,explode 实现行列转换
- Hive--行转列(Lateral View explode())和列转行(collect_set() 去重)
- Hive行列转换-lateral view的使用
- hive lateral view explode 使用
- hive:explode() 与 lateral view
- Lateral View用法 与 Hive UDTF explode
- hive lateral view 与 explode详解
- hive lateral view 与 explode详解
- Lateral View用法 与 Hive UDTF explode
- hive行转列lateral view explode用法
- hive lateral view 与 explode详解
- Lateral View用法 与 Hive UDTF explode
- hive常用UDF and UDTF函数介绍-lateral view explode()
- hive sql 中lateral view explode/json_tuple的使用
- SQL 之 lateral view explode()
- 行转多列lateral view explode详解
- Hive中的explode()函数和collect_set()函数
- Hive Lateral view介绍
- [学习笔记]Android常用控件
- stringutils 判断对象以及对象内的map list是否为空
- unity3d与计算机图形学
- 解释器模式&适配器模式的简单比较
- struts2开发步骤
- hive collect_set,lateral view,explode 实现行列转换
- linux网络通讯模型
- Appium链接天猫盒子
- ubuntu 16.04安装navicat
- Swift--14类型扩展
- BZOJ1069: [SCOI2007]最大土地面积
- ajaxfileupload.js问题汇总及解决 附修复版下载
- Redis学习博客
- sparkGc