数据类型array<string>
有如下数据:字段分别是movie_name, actors集合,show,字段分别以‘,’分割,第二个字段有三个元素,元素之间以:分割,因此把第二个字段设置为array<string>。
战狼2,吴京:吴刚:龙母,2017-08-16
三生三世十里桃花,刘亦菲:痒痒,2017-08-20
普罗米修斯,苍老师:小泽老师:波多老师,2017-09-17
美女与野兽,吴刚:加藤鹰,2017-09-17
建表
create table db_hive.t_movie(movie_name string, actors array<string>, show date)
row format delimited fields terminated by ','
collection items terminated by ':';
导数
load data local inpath "/home/arraytest.txt"
into table db_hive.t_movie;
查询
array_contains函数
select * from t_movie where array_contains(actors,"龙母");
size函数
select movie_name,size(actors) as size,show from t_movie;