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;
原创文章,作者:3628473679,如若转载,请注明出处:https://blog.ytso.com/196225.html