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

座右铭:

你在你擅长的领域牛逼,

并带着一群小白变牛逼,

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

--可点击加入我们

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值