Hive应用:外部分区表

Hive应用:外部分区表

介绍

Hive能够建立外部分区表。建立表的时候,分区要在建表语句中体现。建完以后,你不会在表中看到数据,须要进行分区添加,使用alter语句进行添加。而后数据才会显示。sql

样例

有以下的目录结构。oop

建表语句:spa

create external table Tbl_Custom(CustomID int,AreaID int,Name string,Gender int) partitioned by(city string) row format delimited fields terminated by '\t' location 'hdfs://hadoop01:9000/data/tbl_custom';

    建立表的时候,只建立到tbl_custom这一层目录,余下的一层目录使用分区表示,若是余下的有两层目录,那么能够使用两个分区,目录层级以此类推。将这个外部表建立好以后,使用查询语句,是看不到数据的,须要给这个表添加分区内容,才能看到具体的信息,以下:.net

alter table Tbl_Custom add partition(city='beijing') location 'hdfs://hadoop01:9000/data/tbl_custom/city=beijing';
alter table Tbl_Custom add partition(city='shanghai') location 'hdfs://hadoop01:9000/data/tbl_custom/city=shanghai';

当添加好这两个分区以后,这两个目录下的数据就能够在一张表中查看了,这个方法很适用于合并数据。code

上一篇:Hive应用:外部表连接内部表orm

下一篇:Hive应用:数据外置内部表blog

相关文章
相关标签/搜索