1. 程式人生 > 實用技巧 >hive分割槽表實踐

hive分割槽表實踐

HIVE把表組織成“分割槽”,這是一種根據“分割槽列”的值對錶進行粗略劃分的機制,使用分割槽可以加快資料分片的查詢速度。

表或分割槽可以進一步分為“桶”。它會為資料提供額外的結構以獲得更高效的查詢處理。

建立分割槽表

CREATE TABLE bills_detail (msgid STRING,time STRING,spid STRING,opid STRING,spcode STRING,result STRING) 
PARTITIONED BY (dt STRING,type STRING) 
ROW FORMAT DELIMITED
FIELDS TERMINATED BY '\t'
  表結構

hive> desc bills_detail;
OK
msgid                   string                                      
time                    string                                      
spid                    string                                      
opid                    string                                      
spcode                  string                                      
result                  string                                      
dt                      string                                      
type                    string                                      
                 
# Partition Information          
# col_name              data_type               comment             
                 
dt                      string                                      
type                    string

2.匯入資料

load data local inpath '/home/hive/201601notify.txt' into table bills_detail partition(dt='201601',type='notifySmsDeliveryReceipt');
load data local inpath '/home/hive/201601sendsms.txt' into table bills_detail partition(dt='201601',type='sendSms');
hive中資料實際路徑:

/apps/hive/warehouse/bills_detail/dt=201601/type=sendSms/201601sendsms.txt

3.查詢資料

hive> select * from bills_detail where dt='201601' and type='sendSms' limit 10;