Hive 炸裂函数 explode(map<string,string>) 宽表转高表SQL:
select
slice_id,
user_id,
shop_id,
'user_stats_public' as table_code,
explode(kv) as (field_code,field_value)
from
( select
user_id,
-1 as shop_id,
abs(hash(user_id) % 20000) as slice_id,
map(
'residence_city_name',residence_city_name,
'residence_city_level',residence_city_level,
'gender', gender,
'age', age,
'activeness_level' , activeness_level,
'consuming_level' , consuming_level,
'pay_amt_td_level' , pay_amt_td_level,
'old_ecom_user' , old_ecom_user
) as kv
from ecom_kunlun.types_mapping_table_13_1639904624993
where date = max_pt('ecom_kunlun.types_mapping_table_13_1639904624993') ) a;
select explode(array('A','B','C'));
select explode(array('A','B','C')) as col;
select tf.* from (select 0) t lateral view explode(array('A','B','C')) tf;
select tf.* from (select 0) t lateral view explode(array('A','B','C')) tf as col;
select explode(map('A',10,'B',20,'C',30));
select explode(map('A',10,'B',20,'C',30)) as (key,value);
select tf.* from (select 0) t lateral view explode(map('A',10,'B',20,'C',30)) tf;
select tf.* from (select 0) t lateral view explode(map('A',10,'B',20,'C',30)) tf as key,value;
select posexplode(array('A','B','C'));
select posexplode(array('A','B','C')) as (pos,val);
select tf.* from (select 0) t lateral view posexplode(array('A','B','C')) tf;
select tf.* from (select 0) t lateral view posexplode(array('A','B','C')) tf as pos,val;
select inline(array(struct('A',10,date '2015-01-01'),struct('B',20,date '2016-02-02')));
select inline(array(struct('A',10,date '2015-01-01'),struct('B',20,date '2016-02-02'))) as (col1,col2,col3);
select tf.* from (select 0) t lateral view inline(array(struct('A',10,date '2015-01-01'),struct('B',20,date '2016-02-02'))) tf;
select tf.* from (select 0) t lateral view inline(array(struct('A',10,date '2015-01-01'),struct('B',20,date '2016-02-02'))) tf as col1,col2,col3;
select stack(2,'A',10,date '2015-01-01','B',20,date '2016-01-01');
select stack(2,'A',10,date '2015-01-01','B',20,date '2016-01-01') as (col0,col1,col2);
select tf.* from (select 0) t lateral view stack(2,'A',10,date '2015-01-01','B',20,date '2016-01-01') tf;
select tf.* from (select 0) t lateral view stack(2,'A',10,date '2015-01-01','B',20,date '2016-01-01') tf as col0,col1,col2;
Using the syntax "SELECT udtf(col) AS colAlias..." has a few limitations:
Please see LanguageManual LateralView for an alternative syntax that does not have these limitations.
Also see Writing UDTFs if you want to create a custom UDTF.
https://cwiki.apache.org/confluence/display/Hive/LanguageManual+UDF#LanguageManualUDF
扫码关注腾讯云开发者
领取腾讯云代金券
Copyright © 2013 - 2025 Tencent Cloud. All Rights Reserved. 腾讯云 版权所有
深圳市腾讯计算机系统有限公司 ICP备案/许可证号:粤B2-20090059 深公网安备号 44030502008569
腾讯云计算(北京)有限责任公司 京ICP证150476号 | 京ICP备11018762号 | 京公网安备号11010802020287
Copyright © 2013 - 2025 Tencent Cloud.
All Rights Reserved. 腾讯云 版权所有