天天看點

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 = http://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 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)

繼續閱讀