hive 复杂数据类型和时间数据类型简介

一、hive 复杂数据类型建表举例
1、使用数组的情况
hive>create table student(sid int,sname string,grade array<float>);
记录内容 {1,'alice',[80,90,90]}
2、使用map的情况
hive>create table student1(sid int,sname string,grade map<string,float>);
记录内容 {1,'alice',<'math',80>}
3、在数组中map数组的情况
hive>create table student3(sid int,sname string,array<map<string,float>>);
记录内容 {1,'alice',[<'math',80>,<'eng',90>]}
4、使用结构的情况,可以使不同数据类型的数据,通过加点的方式获得数据
hive>create table student5(sid int,info struct<name:string,age:int,sex:string>);
记录内容 {1,{'alice',10,'male'}}

注意 结构与数组比较类似,但是数组必须是同一种数据类型,而结构内的数据类型可以是不一样的

二、hive 时间数据类型
有两种,Date 用以表示年、月、日,Timestamp是偏移量
hive> select unix_timestamp();
unix_timestamp(void) is deprecated. Use current_timestamp instead.
OK
1424183200
Time taken: 2.215 seconds, Fetched: 1 row(s)


Date与Timestamp可以使用cast函数相互转化,

猜你喜欢

转载自blog.csdn.net/lepton126/article/details/80013677
今日推荐