11.分区表和数据产生关联的三种方式
11.1 方式一:上传数据后修复
①创建目录
dfs -mkdir -p /user/hive/warehouse/student_name/month=202001/day=12;
②上传数据
dfs -put /root/hivedata/stu.txt /user/hive/warehouse/student_name/month=202001/day=12;
③查询数据(查询不到刚上传的数据)
select * from student_name where month='202001' and day='12';
※※ ④执行修复命令
msck repair table student_name;
⑤再次查询
select * from student_name where month='202001' and day='12';
11.2 方式二:上传数据后添加分区
①创建目录
dfs -mkdir -p /user/hive/warehouse/student_name/month=202002/day=22;
②上传数据
dfs -put /root/hivedata/stu.txt /user/hive/warehouse/student_name/month=202002/day=22;
※※ ③执行添加分区
alter table student_name add partition(month='202002',day='22');
④查询数据
select * from student_name where month='202002' and day='22';
11.3 方式三:创建文件夹后load数据到分区
①创建目录
dfs -mkdir -p /user/hive/warehouse/student_name/month=202003/day=13;
※※ ②上传数据
load data local inpath '/root/hivedata/stu.txt' into table student_name partition(month='202003',day='13');
③查询数据
select * from student_name where month='202003' and day='13';