hive LATERAL VIEW 行转列

drop table lateralview;

create table lateralview (col1 string, col2 string)
ROW FORMAT DELIMITED FIELDS TERMINATED BY '\t';

LOAD DATA LOCAL INPATH '/home/tianzhao/book/lateralview.txt'
OVERWRITE INTO TABLE lateralview;
lateralview.txt 中的数据是
r1 a,b
r2 d,e

select col1, col2 from lateralview;
r1 a,b
r2 d,e

select col1, myCol2
from lateralview 
LATERAL VIEW explode(split(col2,',')) myTable1 as myCol2;
r1 a
r1 b
r2 d
r2 e

你可能感兴趣的:(hive)