關於hive的建表操作

2021-08-15 04:32:36 字數 3631 閱讀 4473

hive 建立外部表語句例項:

create external table `***x`(

`mac` string, 

`did` string, 

`uid` string, 

`sid` string, 

`tc_version` string, 

`province` string, 

`city` string, 

`model` string, 

`chip` string, 

`source` string, 

`start_time` string, 

`stop_time` string, 

`dur` string, 

`video_id` string, 

`name` string, 

`category` string,

`play_length` string, 

`vip` string, 

`partner` string, 

`video_source` string, 

`business_type` string)

partitioned by ( 

`partition_day` string)

row format serde 

'org.apache.hadoop.hive.ql.io.orc.orcserde' 

stored as inputformat 

'org.apache.hadoop.hive.ql.io.orc.orcinputformat' 

outputformat 

'org.apache.hadoop.hive.ql.io.orc.orcoutputformat'

location

建立hive

表的另外的方式:

方式二:create table if not exists default.weblog_20150923  

like default.weblog ; 

方式三:create table default.weblog_comm  

as select ip, time, req_url from default.weblog;

向hive

表裡load

資料:

load data local inpath '/opt/hive-0.13.1/weblog.txt' into table default.weblog ;

hive提供了復合資料型別:

structs: 

structs

內部的資料可以通過

dot(

.)來訪問,例如,表中一列

c的型別為

struct

,我們可以通過

c.a來訪問域a

maps(

k-v對):訪問指定域可以通過

["指定網域名稱稱

"]進行,例如,乙個

map m

包含了乙個

group-

》gid的kv

對,gid

的值可以通過

m['group']

來獲取

arrays:

array

中的資料為相同型別,例如,假如

array a

中元素['a','b','c']

,則a[1]

的值為'b'

struct使用

·  hive> create table student_test(id int, info struct)  

·  > row format delimited fields terminated by ','                         

·  > collection items terminated by ':';                                   

·  ok  

·  time taken: 0.446 seconds

'fields terminated by' :欄位與字段之間的分隔符

''collection items terminated by' :乙個字段各個item的分隔符

·  $ cat test5.txt   

·  1,zhou:30  

·  2,yan:30  

·  3,chen:20  

·  4,li:80  

·  hive> load data local inpath '/home/work/data/test5.txt' into table student_test;

array使用

·  hive> create table class_test(name string, student_id_list array)  

·  > row format delimited                                              

·  > fields terminated by ','                                          

·  > collection items terminated by ':';                               

·  ok  

·  time taken: 0.099 seconds 

·  $ cat test6.txt   

·  034,1:2:3:4  

·  035,5:6  

·  036,7:8:9:10  

·  hive>  load data local inpath '/home/work/data/test6.txt' into table class_test ; 

map使用

·  hive> create table employee(id string, perf map)       

·  > row format delimited                                          

·  > fields terminated by '\t'                                

·  > collection items terminated by ','                       

·  > map keys terminated by ':';                                    

·  ok  

·  time taken: 0.144 seconds 

『map keys terminated by』 :key value分隔符

·  $ cat test7.txt   

·  1       job:80,team:60,person:70  

·  2       job:60,team:80  

·  3       job:90,team:70,person:100  

·  hive>  load data local inpath '/home/work/data/test7.txt' into table employee; 

hive建表及表操作

建表的三種形式 1.直接建表 create external table if not exists tab name row 1 type,row 2 type partition by row 3 type,type 4 type row format delimited fields term...

hive建表範例

建表範例 支援update和delete create table aaa id string visitor name string clustered by id into 2buckets stored as orc tblproperties transactional true 目前只有o...

hive建表範例

建表範例 支援update和delete create table aaa id string visitor name string clustered by id into 2buckets stored as orc tblproperties transactional true 目前只有o...