hive分区表几大注意事项

来源:互联网 发布:手机淘宝脸部拍摄认证 编辑:程序博客网 时间:2024/05/16 13:16

分区表:
1.问题的引入
1).bf_log
/usr/hive/warehouse
20170910.log
20170922.log
我想分析某一天的数据,如果按照以上的就会扫描全表,从而增加了数据库的压力,引入了分区表
2)./usr/hive/warehouse
20170910/
20170910.log
20170922/
20170922.log
2.分区表实际上就是对应一个HDFS文件的文件系统上一个文件夹,该文件下就是该分区所有数据的文件,hive中的分区就是分目录,就是把一个大的数据集根据业务需求拆分成更小的数据集.就跟Java中的查询时通过where子句中的表达式来选择分区,这样的查询效率会提高很多。
create table db_hive.dept_partition(
deptno int,dname string,loc string)
partitioned by(month string)
row format delimited fields terminated by ‘\t’;
load data local inpath ‘数据路径’ into table db_hive.dept_partition partition(month=’2017-09-12’);
注意事项:
create table db_hive.dept_partition(
deptno int,dname string,loc string)
row format delimited fields terminated by ‘\t’;
create table db_hive.dept_partition(
deptno int,dname string,loc string)
partitioned by(month string)
row format delimited fields terminated by ‘\t’;
向hdfs上传对应的数据
msck repair table db_hive.dept_partition;就可以加载导数据
alert table db_hive.dept_partition add partition(day string);