hive分区表与数据关联的三种方式

3.把数据直接上传到分区目录上,让分区表和数据产生关联的三种方式:
(1)方式一:上传数据后修复
上传数据
hive (db_614)> dfs -mkdir -p /user/hive/warehouse/db_614.db/user_info6/month=202011/day=22;
hive (db_614)> dfs -put /root/data/user_info.csv /user/hive/warehouse/db_614.db/user_info6/month=202011/day=22;
查询数据(查询不到刚上传的数据)
hive (db_614)> select * from user_info6 where month='202011' and day='22';
执行修复命令
hive (db_614)> msck repair table user_info6;
再次查询数据
hive (db_614)> select * from user_info6 where month='202011' and day='22';
(2)方式二:上传数据后添加分区
上传数据
hive (db_614)> dfs -mkdir -p /user/hive/warehouse/db_614.db/user_info6/month=202011/day=23;
hive (db_614)> dfs -put /root/data/user_info.csv /user/hive/warehouse/db_614.db/user_info6/month=202011/day=23;
执行添加分区
hive (db_614)> alter table user_info6 add partition(month='202011',day='23');
查询数据
hive (db_614)> select * from user_info6 where month='202011' and day='23';
(2)方式三:上传数据后load数据到分区
上传数据
hive (db_614)> load data local inpath '/root/data/user_info.csv' into table user_info6
> partition(month='202011',day='24');
查询数据
hive (db_614)> select * from user_info6 where month='202011' and day='24';

原文地址:https://www.cnblogs.com/LEPENGYANG/p/14019908.html