应用场景
方式一:修复命令
在 hdfs 创建目录
hadoop fs -mkdir -p /user/hive/warehouse/user_article/date=20200201;
上传数据
hadoop fs -put /devtools/datas/user_article_20200101.log /user/hive/warehouse/user_article/date=20200201;
查询不到刚上传的数据
select * from user_article where `date`='20200201';
查看分区信息
show partitions user_article;
并没有显示 date=20200201 分区,说明刚才创建的 目录 与 分区表 没产生关联
分区表 与 普通的表不同,需要更多的 元数据信息,只是创建目录 和 数据文件,没有元数据信息,是无法关联的
修复命令
根据 目录结构 修改 分区信息
hive> msck repair table user_article;
再次查询数据
可以查询到数据
select * from user_article where `date`='20200201';
方式二:添加分区
在 hdfs 创建目录
hadoop fs -mkdir -p /user/hive/warehouse/user_article/date=20200202;
上传数据
hadoop fs -put /devtools/datas/user_article_20200101.log /user/hive/warehouse/user_article/date=20200202;
查询不到数据
select * from user_article where `date`='20200202';
添加分区
alter table user_article add partition(`date`='20200202');
可以查询到数据
select * from user_article where `date`='20200202';
