Hive的外部表和分区表

  • 构造一个外部表

外部表的好处是删除external表,数据表的元数据不会被删除

> create external table t_sz_ext(id int,name string)
> row format delimited 
> fields terminated by '\t'
> stored as textfield
> location '/home/hadoop/Desktop';
  • 构造一个分区表

分区表的好处是可以更好的打上记号,区分

> create table t_sz_part(id int,name string)

> partitioned by (country string)

> row format delimited

> fields terminated by ',';

将相关信息添加到你想要的分区

load data local inpath '/home/hadoop/Desktop/sz.dat' into table t_sz_part partition(country='china')

检索country = China的个数

> select count(1) from t_sz_part where country=China group by (name='furong');
  • 建表之后再添加一个分区
> alter table t_sz_part add partition (country='america');

和之前一样再将文件添加到新建的分区中

  • 删除分区
> alter table t_sz_part drop partition (country='america');
  • 查看一个表的分区表
> show partitions t_sz_part;

猜你喜欢

转载自blog.csdn.net/jin__nan/article/details/80572848