首页 > 其他 > 详细

hive分区表实践

时间:2017-06-07 21:39:27      阅读:389      评论:0      收藏:0      [点我收藏+]


      HIVE把表组织成“分区”,这是一种根据“分区列”的值对表进行粗略划分的机制,使用分区可以加快数据分片的查询速度。

      表或分区可以进一步分为“桶”。它会为数据提供额外的结构以获得更高效的查询处理。

  1. 创建分区表

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分区表实践

原文:http://sjitwant.blog.51cto.com/3661219/1933204

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!