大数据(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

相关文章
相关标签/搜索