hive 列表去重_hive列转行 (collect_all()/collect_list() 不去重)

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       b1

a       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"]

四、关于我们

本文author:数据的开拓者成员之一 江中炼

QQ群:248087140

座右铭:

你在你擅长的领域牛逼,

并带着一群小白变牛逼,

别人会发自内心的去尊重你的。

--可点击加入我们


版权声明:本文为weixin_39590453原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接和本声明。