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;
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值