hive的數據類型
阿新 • • 發佈:2019-01-14
reat collect 數據格式 查詢語句 del format 不同 1.5 編寫 1.基本數據類型
因為hive也是java語言編寫的,所以他的基本數據類型和java的大致相同:
2.基本數據類型
(1)array(數組)
特點:個數可以不相同,但是類型相同
例:以family表(name string familes array<string>)為例:
#建表語句: create table t_family (name string, familes array<string>) row format delimited fields terminated by ‘\t‘ collection items terminated by ‘,‘;
#查詢
select * from t_family;
#查詢數組中的某一個
select name, familes[0] from t_family;
(2)map ----映射
特點:key-value 可以不相同,個數也可以不同
數據格式:zs age:28,salary:20000,address:beijing
#建表語句: create table user_info(name string,info map<string,string>) row format delimieted fields terminated by ‘\t‘ collection items terminated by ‘,‘ map keys terminated by ‘:‘
#查詢語句
select * from user_info;
#查詢具體的map的key的值
select name ,info[‘age‘],info[‘salary‘] from user_info ;
(3)struct類型 ----對象
特點:個數相同,類型相同
例:
以stu(name ,info)為例
數據格式:zss 26,123456,shanghai,695
#建表語句: `create table stu_info(name string, info struct<age:int,id:string,address:string,score:double>) row format delimted fields terminated by ‘\t‘ collection items terminated by ‘,‘`
#查詢語句
select * from stu_info;
#具體的對象屬性查詢
select name,info.address from stu_info;
hive的數據類型