hive中的外部表,内部表以及分区表;
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,sex 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,sex string,age int,major string)row format delimited fields terminated by ',';
//分区表create table stu4_partition(id string,name string,sex 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='');
//添加分区:alter table dept_partition add partition(month='06') ; 前提: month 分布必须存在.