hive:explode() 与 lateral view
来源:互联网 发布:福建广播电视网络 编辑:程序博客网 时间:2024/05/29 12:30
一、解决如下问题
如何由上面的宽表变成下面的窄表?
二、explode()
explode() takes in an array (or a map) as an input and outputs the elements of the array (map) as separate rows.
explode() 函数接收array或map类型数据,并分行返回数据的每一个元素。注意输入必须是array或map类型,字符串不可以。因此好多情况下都要借助split()。
实例:
select explode(split(test_data,’,’)) from test
输出:
三、lateral view
上面实现了单列的行转列,但是并没有跟date字段进行匹配。这就需要用到lateral view。
Lateral view:lateral view is used in conjunction with user-defined table generating functions such as explode(). As mentioned in Built-in Table-Generating Functions, a UDTF generates zero or more output rows for each input row. A lateral view first applies the UDTF to each row of base table and then joins resulting output rows to the input rows to form a virtual table having the supplied table alias.
Lateral view:lateral view用于和split、explode等UDTF一起使用的,能将一行数据拆分成多行数据,在此基础上可以对拆分的数据进行聚合,lateral view首先为原始表的每行调用UDTF,UDTF会把一行拆分成一行或者多行,lateral view在把结果组合,产生一个支持别名表的虚拟表。
select date date_t,test_data_t from test lateral view explode(split(test_data,’,’)) test_data_t as test2;
输出:
四、这时就可以用聚合函数进行聚类统计了
可以按date_t对test_data_t进行sum、count、avg等等。
- 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详解
- Lateral View用法 与 Hive UDTF explode
- hive lateral view explode 使用
- hive行转列lateral view explode用法
- hive常用UDF and UDTF函数介绍-lateral view explode()
- hive sql 中lateral view explode/json_tuple的使用
- hive collect_set,lateral view,explode 实现行列转换
- SQL 之 lateral view explode()
- 行转多列lateral view explode详解
- Hive--行转列(Lateral View explode())和列转行(collect_set() 去重)
- Hive Lateral view介绍
- hive lateral view语句
- hive中的Lateral View
- Python笔记——几种数据结构的实现:栈、队列及二叉树
- 51Nod 1100 斜率最大
- 黑化的牛牛-Java-牛客模拟四
- 随遇而安也是一种选择
- 解决 IntelliJ IDEA 无法热加载 Spring Boot 模板文件和静态资源文件
- hive:explode() 与 lateral view
- [实训]SSH中使用filter过滤器
- Python笔记——排序算法的实现
- LeetCode445——Add Two Numbers II(两个链表数据相加(从链表尾部开始),返回新链表)
- 膨胀的牛牛-Java-牛客模拟四
- 8. 转义字符 (单引号,双引号和 "\ ")
- Redis之一:数据结构和对象
- 图像处理之特征匹配特征提取之SIFT简单梳理
- RMI 远程方法调用