创建文件
vim movie.txt
数据准备:
《疑犯追踪》 悬疑,动作,科幻,剧情 《Lie to me》 悬疑,警匪,动作,心理,剧情 《战狼 2》 战争,动作,灾难
创建新表:
create table movie_info( movie string, category string) row format delimited fields terminated by "t";
数据导入:
load data local inpath "/opt/module/data/movie.txt" into table movie_info;
先将catagory列分开:
split函数是将字符串变成一列以,分割的列表
explode将列表的一列分为多行
select explode(split(category,',')) from movie_info;
结果:
select
movie,
category_name
from movie_info
lateral VIEW explode(split(category,',')) movie_info_tmp AS category_name;



