hive分區表實踐
阿新 • • 發佈:2017-06-07
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;
本文出自 “未來時空” 博客,請務必保留此出處http://sjitwant.blog.51cto.com/3661219/1933204
hive分區表實踐