首页 > 代码库 > Hive基础之Hive的复杂类型

Hive基础之Hive的复杂类型

Array

一组有序字段,字段的类型必须相同。Array(1,2)

create table hive_array(ip string, uid array<string>)row format delimited fields terminated by ,collection items terminated by |stored as textfile;
load data local inpath "/home/spark/software/data/hive_array.txt" overwrite into table hive_array;

 

hive_array.txt

192.168.1.1,www.baidu.com|www.google.com|www.qq.com192.168.1.2,www.baidu.com|www.sina.com|www.sohu.com192.168.1.3,www.qq.com|www.163.com|www.youku.com
select * from hive_array;                                                                         192.168.1.1     ["www.baidu.com","www.google.com","www.qq.com"]192.168.1.2     ["www.baidu.com","www.sina.com","www.sohu.com"]192.168.1.3     ["www.qq.com","www.163.com","www.youku.com"]

使用下标访问,下标从0开始:

select ip, uid[0] as id from hive_array;192.168.1.1     www.baidu.com192.168.1.2     www.baidu.com192.168.1.3     www.qq.com

查看数据长度:

select size(uid) from hive_array;333

数组查找:

select * from hive_array where array_contains(uid, "www.baidu.com");192.168.1.1     ["www.baidu.com","www.google.com","www.qq.com"]192.168.1.2     ["www.baidu.com","www.sina.com","www.sohu.com"]

 

 

Struts

 

Map