collect_all() hive 0.12
collect_list() hive 0.13
一、问题
hive如何将
a b1
a b2
a b2
c d1
c d1
d d2
变为:
a ["b1","b2","b2"]
c ["d1","d1"]
d ["d2"]
二、数据
test.txt (空格分隔)
a b1a b2
a b2
c d1
c d1
d d2
三、答案
1.建表
drop table tmp_jzl_20151027_test;
create table tmp_jzl_20151027_test
(
col1 string,
col2 string
)
row format delimited
fields terminated by ' '
stored as textfile;
load data local inpath '/home/jiangzl/shell/test.txt' into table tmp_jzl_20151027_test;
2.处理
hive>
> select col1, collect_all(col2))
> from tmp_jzl_20151027_test
> group by col1;
a ["b1","b2","b2"]
c ["d1","d1"]
d ["d2"]
最后
以上就是淡然飞机最近收集整理的关于hive列转行 (collect_all()/collect_list() 不去重)的全部内容,更多相关hive列转行内容请搜索靠谱客的其他文章。
本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
发表评论 取消回复