Hive分区表

分区表:

分区表实际上就是对应一个HDFS文件系统上独立的文件夹,该文件夹下是该分区所有的数据文件,Hive中的分区就是分目录,把一个大的数据集根据业务需要分割成更小的数据集;

在查询时通过where子句中的表达式来选择查询所需要的指定的分区,这样的查询效率会提高很多;

CREATE EXTERNAL TABLE IF NOT EXISTS default.emp_partition(
empno int,
ename string,
job string,
mgr int,
hiredate string,
sal double,
comm double,
deptno int)
partitioned by(month string)
ROW FORMAT DELIMITED FIELDS TERMINATED BY ',';

加载数据到分区表中:
load data local inpath '/home/wql/app/hData/emp.txt' into table emp_partition partition(month='20190307');

查询:
select * from emp_partition where month='20190307';

select count(distinct ip) from emp_partition where month='20190307';


CREATE EXTERNAL TABLE IF NOT EXISTS default.emp_partition2(
empno int,
ename string,
job string,
mgr int,
hiredate string,
sal double,
comm double,
deptno int)
partitioned by(month string,day string)
ROW FORMAT DELIMITED FIELDS TERMINATED BY ',';

查询:
select count(distinct ip) from emp_partition where month='201903' and day='07';

创建dept表:
CREATE TABLE IF NOT EXISTS default.dept_nopart(
deptno int,
dname string,
loc string)
ROW FORMAT DELIMITED FIELDS TERMINATED BY '\t';

创建dept分区表:
CREATE TABLE IF NOT EXISTS default.dept_part(
deptno int,
dname string,
loc string)
partitioned by(day string)
ROW FORMAT DELIMITED FIELDS TERMINATED BY '\t';

创建分区目录:
dfs -mkdir -p /user/hive/warehouse/dept_part/day=20190307;

出现的问题:将数据put到分区中,select不到数据,因为元数据中不知道该分区的存在;
dfs -put /home/wql/app/hData/dept.txt /user/hive/warehouse/dept_part/day=20190307;

解决问题:修复分区
msck repair table dept_part;
alter table dept_part add partiton(day='20190307');

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值