Hive的复杂数据类型和时间类型⼀ 复杂数据类型
Array:数组类型,由⼀系列相同类型的元素组成
Map:集合类型,包括key->value键值对,可以通过key来访问元素。
Struct:结构类型,可以包含不同类型的元素。这些元素可以通过“点语法”的⽅式来得到所需要的元素。
⼆ 实战
1、数组
hive> create table student
> (sid int,
> sname string,
> grade array<float>);
类似:{1,Tom,[80,90,75]}
hive> desc student;
OK
sid int
sname string
grade array<float>
2、映射
hive> create table student1
> (sid int,
> sname string,
> grade map<string,float>);
OK
Time taken: 0.546 seconds
类似{1,Tom,<'⼤学语⽂',85>}
hive> desc student1;
OK
sid int
sname string
grade map<string,float>
Time taken: 0.377 seconds, Fetched: 3 row(s)
3、数组加映射
hive> create table student3
> (sid int,
> sname string,
> grade array<map<string,float>>);
OK
Time taken: 0.178 seconds
类似:{1,‘Tom’,[<'⼤学语⽂',80>,<‘⼤学英语’,90>]} hive> desc student3;
OK
sid int
sname string
grade array<map<string,float>>
Time taken: 1.428 seconds, Fetched: 3 row(s)
4、结构
hive> create table student4
> (sid int,
> info struct<name:string,age:int,sex:string>);
OK
Time taken: 0.398 seconds
类似:{1,{‘Tom’,10,‘男’}}
hive> desc student4;
OK
sid int
info struct<name:string,age:int,sex:string>
Time taken: 0.682 seconds, Fetched: 2 row(s)
5、时间
hive> select unix_timestamp();
Total jobs = 1
Launching Job 1 out of 1
Number of reduce tasks is set to 0 since there's no reduce operator
Starting Job = job_201708270801_0001, Tracking URL = localhost:50030/jobdetails.jsp?jobid=job_201708270801_0001 Kill Command = /opt/hadoop-1.2.1/libexec/../bin/hadoop job -kill job_201708270801_0001
Hadoop job information for Stage-1: number of mappers: 1; number of reducers: 0
2017-08-27 08:05:58,184 Stage-1 map = 0%, reduce = 0%
2017-08-27 08:06:21,155 Stage-1 map = 100%, reduce = 0%, Cumulative CPU 6.28 sec
2017-08-27 08:06:30,451 Stage-1 map = 100%, reduce = 100%, Cumulative CPU 6.28 sec
MapReduce Total cumulative CPU time: 6 seconds 280 msec
hive 字符串转数组Ended Job = job_201708270801_0001
MapReduce Jobs Launched:
Job 0: Map: 1 Cumulative CPU: 6.28 sec HDFS Read: 270 HDFS Write: 11 SUCCESS
Total MapReduce CPU Time Spent: 6 seconds 280 msec
OK
1503792379
Time taken: 77.649 seconds, Fetched: 1 row(s)

版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。