Hive中怎麼快速複製分割槽表

2021-10-08 23:22:42 字數 834 閱讀 6790

舉個栗子,比如我現在要將表a遷移為表b,

以下步驟:

建立乙個結構相同的表;

create table tmp.b like tmp.a;
這樣我們就建立了乙個和表a結構完全一模一樣的表b,但是裡頭是沒人任務資料的,因為create like只複製表結構,不複製資料,複製資料需要操作hdfs。

遷移hdfs檔案;

我們先檢視兩個表的hdfs檔案分別在什麼位置

show create table tmp.a;

show create table tmp.b;

也有可能,這樣也不顯示表的路徑,具體原因尚不清楚,那我們可以用以下方法讓路徑顯示出來:

desc formatted tmp.a;

desc formatted tmp.b;

這兩種方法至少有一種能獲取到表的location的。

找到表的location之後,我們就可以複製檔案了。

hadoop fs -cp hdfs://nameservice1/user/hive/warehouse/tmp.db/a/*   hdfs://nameservice1/user/hive/warehouse/tmp.db/b/
更新元資料資訊

雖然我們已經把資料放到了對應的hdfs目錄下,但元資料資訊沒有更新,hive查表b時,仍然不知道表b下面的檔案更新了,所以會出現無法查資料的情況,這時候我們更新元資料資訊就可以了。

msck repair table tmp.b
至此,大功告成。

hive分割槽表快速複製

drop table if exists dwt.dwt activity auction house activity sale full 1d 0805forliuqian create table dwt.dwt activity auction house activity sale ful...

hive 分割槽表

partitioned by create table tb name name string partitioned by age int row format delimited fields terminated by t load data local inpath file path in...

hive分割槽表

partition對應於資料庫的 partition 列的密集索引 在 hive 中,表中的乙個 partition 對應於表下的乙個目錄,所有的 partition 的資料都儲存在對應的目錄中 例如 test表中包含 date 和 city 兩個 partition 則對應於date 201302...