005.hive列转行 (collect_all()/collect_list() 不去重)

collect_list()   hive 0.13

collect_all()    hive 0.12 shell

https://cwiki.apache.org/confluence/display/Hive/LanguageManual+UDF#LanguageManualUDF-CollectionFunctions
apache

1、问题

hive如何将 spa

a       b1
a       b2
a       b2
c       d1
c       d1
d       d2 orm

变为: string

a       ["b1","b2","b2"]
c       ["d1","d1"]
d       ["d2"] it


2、数据

test.txt   (空格分隔) io

a       b1
a       b2
a       b2
c       d1
c       d1
d       d2


3、答案

1.建表 table

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; form


load data local inpath '/home/jiangzl/shell/test.txt' into table tmp_jzl_20151027_test; 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"]

4、关于咱们


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

QQ群:248087140 

座右铭: 

你在你擅长的领域牛逼, 

并带着一群小白变牛逼,

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

--可点击加入咱们

相关文章
相关标签/搜索