c语言sscanf函数的用法是什么
307
2022-11-26
Hive lateral view 与 explode
explode(官网链接)
explode 是一个 UDTF(表生成函数),将单个输入行转换为多个输出行。一般和 lateral view 结合使用,主要有两种用法:
输入类型 | 使用方法 | 描述 |
T | explode(ARRAY<T> a) | 将数组分解为多行,返回单列多行,每一行代表数组的一个元素 |
Tkey,Tvalue | explode(MAP<Tkey,Tvalue> m) | 将 MAP 分解为多行,返回的行具有两列(键-值),每一行代表输入中的一个键值对 |
示例:
explode(array)
hive (default)> select explode(array('A','B','C')); OK col A B C Time taken: 0.402 seconds, Fetched: 3 row(s) hive (default)> select explode(array('A','B','C')) as col1; OK col1 A B C Time taken: 0.145 seconds, Fetched: 3 row(s) hive (default)> select tf.* from (select 0) t lateral view explode(array('A','B','C')) tf; OK tf.col A B C Time taken: 0.191 seconds, Fetched: 3 row(s) hive (default)> select tf.* from (select 0) t lateral view explode(array('A','B','C')) tf as col1; OK tf.col1 A B C
explode(map)
hive (default)> select explode(map('A',10,'B',20,'C',30)); OK key value A 10 B 20 C 30 Time taken: 0.153 seconds, Fetched: 3 row(s) hive (default)> select explode(map('A',10,'B',20,'C',30)) as (my_key,my_value); OK my_key my_value A 10 B 20 C 30 Time taken: 0.137 seconds, Fetched: 3 row(s) hive (default)> select tf.* from (select 0) t lateral view explode(map('A',10,'B',20,'C',30)) tf; OK tf.key tf.value A 10 B 20 C 30 Time taken: 0.128 seconds, Fetched: 3 row(s) hive (default)> select tf.* from (select 0) t lateral view explode(map('A',10,'B',20,'C',30)) tf as my_key,my_value; OK tf.my_key tf.my_value A 10 B 20 C 30 Time taken: 0.109 seconds, Fetched: 3 row(s)
LateralView(官网链接)
语法
lateralView: LATERAL VIEW udtf(expression) tableAlias AS columnAlias (',' columnAlias)*
fromClause: FROM baseTable (lateralView)*
描述
lateralview 与用户自定义表生成函数(UDTF)(例如 explode)结合使用,UDTF 为每个输入行生成零个或多个输出行。lateralview 首先将 UDTF 应用于基础表的每一行,然后将结果输出行与输入行连接起来形成具有所提供表别名的虚拟表。
实例
基础表 pageads 具有两列:pageid(页面名称)和 add_list(页面上显示的广告数组)。
hive (test)> !cat pageads
> ;
front_page 1,2,3
contact_page 3,4,5
hive (test)> create table pageads(
> pageid string,
> add_list array
多个lateralview
from 子句可以具有多个 lateralview 子句。后续的 lateralview 子句可以引用 lateralview 左侧表中的任何列。例如以下查询:
SELECT * FROM exampleTable
LATERAL VIEW explode(col1) myTable1 AS myCol1
LATERAL VIEW explode(myCol1) myTable2 AS myCol2;
注意,lateralview 子句按其出现的顺序应用。
实例
hive (test)> !cat basetable;
1,2 a,b,c
3,4 d,e,f
hive (test)> create table basetable(
> col1 array
版权声明:本文内容由网络用户投稿,版权归原作者所有,本站不拥有其著作权,亦不承担相应法律责任。如果您发现本站中有涉嫌抄袭或描述失实的内容,请联系我们jiasou666@gmail.com 处理,核实后本网站将在24小时内删除侵权内容。
发表评论
暂时没有评论,来抢沙发吧~