hive行转列 (Lateral View explode())

原始数据:
test.txt

a b 1,2,3

c d 4,5,6

方案:

drop table test_jzl_20140701_test;

create table test_jzl_20140701_test

(

col1 string,

col2 string,

col3 string

)

row format delimited fields terminated by ' '

stored as textfile;


load data local inpath '/home/jiangzl/shell/test.txt' into table test_jzl_20140701_test;

select * from test_jzl_20140701_test  

a       b       1,2,3

c       d       4,5,6

遍历数组中的每一列

select col1,col2,name 

from test_jzl_20140701_test  

lateral view explode(split(col3,',')) col3 as name;


a       b       1

a       b       2

a       b       3

c       d       4

c       d       5

c       d       6 

转载自:https://my.oschina.net/repine/blog/287254

你可能感兴趣的:(hive,hadoop)