hive~分區表和數據關聯的三種方式

把數據直接上傳到分區目錄上,讓分區表和數據產生關聯的三種方式

test_partitions 表創建:

create table test_partitions(name string)
partitioned by (month string, day string)
row format delimited fields terminated by '\t';

方式一:上傳數據後修復

#上傳數據
hadoop fs -put test1.txt /hive/test_partitions/month=202005/day=3;
#執行修復命令
msck repair table test_partitions;
#查詢數據則會查詢到數據
select * from test_partitions where month='202005' and day='3';

方式二:上傳數據後添加分區 

#創建目錄
hadoop fs -mkdir -p /hive/test_partitions/month=202005/day=3;
#上傳數據
hadoop fs -put test.txt  /hive/test_partitions/month=202005/day=3;
#執行添加分區
alter table test_partitions add partition(month='202005',  day='3');
#查詢數據
select * from test_partitions where month='202005' and day='3';

方式三:創建文件夾後 load 數據到分區

#創建目錄
hadoop fs -mkdir -p /hive/test_partitions/month=202005/day=3;
#上傳數據
load data local inpath 'test.txt' into table test_partitions partition(month='202005', day='3');
#查詢數據
select * from test_partitions where month='202005' and day='3';

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章