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;