hive 分區表和數據產生關聯三種方式

寫在前面:

想要從hive數據庫裏面查詢到數據就要求hive的元數據必須存在且元數據指向的的HDFS路徑中也必須要存在實際的數據

(1)方式一:上傳數據後修復 使用的場景是歷史數據積累了很多分區數據,推薦使用該方式,該方法將HDFS上的數據方向寫到hive的元數據庫MySQL中

上傳數據

hive (default)> dfs -mkdir -p /user/hive/warehouse/dept_partition2/month=201709/day=12;

hive (default)> dfs -put /user/hive/warehouse/dept_partition2/month=201709/day=12; 查詢數據(查詢不到剛上傳的數據)
hive (default)> select * from dept_partition2 where month='201709' and day='12'; 執行修復命令

hive> msck repair table dept_partition2;


再次查詢數據
hive (default)> select * from dept_partition2 where month='201709' and day='12';

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

hive (default)> dfs -mkdir -p /user/hive/warehouse/dept_partition2/month=201709/day=11;

hive (default)> dfs -put /user/hive/warehouse/dept_partition2/month=201709/day=11;
執行添加分區
hive (default)> alter table dept_partition2 add partition(month='201709', day='11'); 查詢數據

hive (default)> select * from dept_partition2 where month='201709' and day='11';

(3)方式三:上傳數據後 load 數據到分區 創建目錄

hive (default)> dfs -mkdir -p /user/hive/warehouse/dept_partition2/month=201709/day=10;
上傳數據
hive (default)> load data local inpath '/opt/module/datas/dept.txt' into table

dept_partition2 partition(month='201709',day='10');

查詢數據

hive (default)> select * from dept_partition2 where month='201709' and day='10';

發佈了42 篇原創文章 · 獲贊 6 · 訪問量 2萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章