內部表和外部表區別

2021-10-23 19:19:49 字數 2462 閱讀 9916

1.檔案在本地而不是在hdfs的時候 

1.1 建表時指定location

(1)建表並load資料

create external table extable28 (id int,str string) row format delimited fields terminated by ' ' location '/zgm/test/';

load data local inpath '/zgm2/exe28' into table extable28;

結果:

在hdfs的/zgm/test下出現了exe28的檔案

(2)刪除表

drop table extable28;
在hdfs的/zgm/test的exe28檔案還在

1.1 建表時不指定location

(1)建表並load資料

create external table extable28_2 (id int,str string) row format delimited fields terminated by ' ';

load data local inpath '/zgm2/exe28' into table extable28_2;

在hdfs 的/user/hive/warehouse/extable28_2下出現了exe28的檔案

(2)刪除表

在hdfs 的/user/hive/warehouse/extable28_2的exe28檔案還在

2、檔案在hdfs而不是在本地的時候

2.1 建表時指定location

(1)建表並load資料

create external table extable28_3 (id int,str string) row format delimited fields terminated by ' ' location '/zgm/test2/';

load data inpath '/data/exe28' into table extable28_3;

結果:/zgm/test2下有exe28檔案,而檔案本來存放的地方: /data下面沒有了

(2)刪除表

檔案還在/zgm/test2下面

2.2 建表時不指定location

(1)建表並load資料

create external table extable28_4 (id int,str string) row format delimited fields terminated by ' ';

load data inpath '/data/exe28' into table extable28_4;

結果/user/hive/warehouse/extable28_4下出現了exe28的檔案而檔案本來存放的地方: /data下面沒有了

(2)刪除表

檔案還在/user/hive/warehouse/extable28_4下面

總結:

1、外部表建表的時候如果是指定了location那麼表就在指定的location下面,如果沒有指定那麼和內部表一樣,在/user/hive/warehouse/下;

2、刪除外部表並不會讓資料消失

ps:load資料的時候,如果原資料在本地不是在hdfs上,那麼資料被copy到表路徑下,如果源資料在hdfs上,那麼就會move到表路徑下

alter table extable28_4 set  tblproperties ('external'='true');//好像寫成小寫不會生效?

alter table extable28_4 set tblproperties ('external'='false');

alter table extable28_4 set tblproperties ('external'='false');//大小寫都可以

create external table extable28_4 (id int,str string) partitioned by (dt string)row format delimited fields terminated by ' ';
直接load的話,那麼資料就從原來儲存的地方,mv到了表的目錄下

load data inpath '/data/exe20200103' into table extable28_4 partition(dt='20200103');
改良:這樣操作,資料還在原來的地方,這樣別的人也可以在資料原來的地方找到資料!

alter table add partition (dt='20200102')

location '/data/exe28_20200102';

hive內部表和外部表的區別 內部表和外部表

內部表 create table if not exists table name刪除表時,元資料與資料都會被刪除 外部表 create external table if not exists table name location hdfs path刪除外部表只刪除metastore的元資料,不...

Hive內部表和外部表區別

建立內部表 建立 create table art inn sentence string row format delimited fields terminated by n 匯入 建立外部表 注意 外部表是在建立的時候定義實體資料的位置的,而且位置必須為資料夾,不能為檔案。1 匯入資料時 在匯...

內部表和外部表的區別

managed and external tables 內部表和外部表 hive上有兩種型別的表,一種是managed table 預設的 另一種是external table 加上external關鍵字 它倆的主要區別在於 當我們drop表時,managed table會同時刪去 data 儲存在...