大數據(Hive-外部表分區)

1:定義
    未被external修改的是內部表(MANAGED TABLE),被external修飾的爲外部表(EXTERNAL TABLE)
    建立外部表語法:code

    create external table person2(
     id int,
     name string,
     hobby array<string>,
     addr map<string,string>
     )
     row format delimited 
     fields terminated by ',' 
     collection items terminated by '-' 
     map keys terminated by ':' 
     location '/user/person2' 
     ;

2:區別
    1)內部表數據由hive自身管理,外部表數據由hdfs來管理
        內部表數據存儲的位置默認/user/hive/warehouse,
        外部表數據存儲的位置由用戶本身指定orm

    2)刪除內部表會直接刪除元數據和存儲數據
       刪除外部表僅僅只會刪除元數據,HDFS上的文件不會刪除。string


3:分區表
    1)定義語法it

     create table p1(
             id int,
             name string,
             hobby array<string>,
             addr map<string,string>
         )
         partitioned by (p_dt string) 
         row format delimited 
         fields terminated by ',' 
         collection items terminated by '-' 
         map keys terminated by ':' 
         ;


    注意:分區字段不能和表中的字段重複,若要建立分區表,必須在表定義的時候建立partitionio

相關文章
相關標籤/搜索