內部表,外部表,分割槽表

2021-10-11 13:37:20 字數 1431 閱讀 8253

1.未被external修飾的是內部表【managed table】,被external修飾的為外部表【external table】。

2.內部表資料由hive自身管理,外部表資料由hdfs管理。

3.內部表資料儲存在hive.metastore.warehouse.dir【預設:/user/hive/warehouse】,外部表資料儲存位置由使用者自己決定。

4.刪除內部表會直接刪除元資料【metadata】及儲存資料,刪除外部表僅僅刪除元資料,hdfs上的檔案不會被刪除。

5:對內部表的修改會直接同步到元資料,而對外部表的表結構和分割槽進行修改,則需要修改【msck repair table table_name】。

6:分割槽表,理解分割槽表:就是將原來的一整張表,分成多張表.

// 建立內部表:

create table stu1

(id string,name string,*** string,age int

,major string)row format delimited fields terminated by ','

;//將資料上傳到表中

load data local inpath '/home/huaqiang/hivedata/stu.log'

overwrite into table stu1;

// 建立外部表:

create external table if not exists stu1

(id string,name string,***

string,age int

,major string)row format delimited fields terminated

by ','

;

//分割槽表

create table stu4_partition

(id string,name string,*** string,age int

,major string)

partitioned by (year string)

row format delimited fields terminated by ','

//上傳資料

load data local inpath '/home/huaqiang/hivedata/stu.log'

into table stu4_partition partition (year=

'2019'

);

//新增分割槽:

alter table dept_partition add partition

(month=

'201706'

);

前提: month 分布必須存在.

Hive表分類,內部表 外部表 分割槽表簡介

內部表與資料庫中的table在概念上是類似的,每乙個內部table在hive中都有乙個相應目錄儲存資料,所有的table資料 不包括external table 都儲存在這個目錄中。刪除表時,元資料與資料都會被刪除。在建立表的時候可以指定external關鍵字建立外部表,外部表對應的檔案儲存在loc...

Hive 內部表 外部表 分割槽表 擴充套件命令

create external table if not exists 表名 列名資料型別 comment 本列注釋 comment 表注釋 partitioned by 列名資料型別 comment 本列注釋 clustered by 列名,列名,sorted by 列名 asc desc inf...

Hive內部表,外部表,分割槽表的建立

建立內部表 預設儲存在 user hive warehouse下 也可以通過location指定 刪除表時,會刪除表資料及元資料 create table if not exists db study.student id string name string row format delimite...