持续创作,加速成长!这是我参与「掘金日新计划 · 10 月更文挑战」的第30天,10月更文诚意加码,激发写作潜力|掘金·日新计划 - 掘金 (juejin.cn)点击查看活动详情
Hive的分区表
1. 分区表的创建
cd /opt/testData/hive/
vi worker.txt
数据准备:
1,zhangsan,18000,北京
2,lisi,15000,上海
3,wangwu,12000,深圳
4,yuting,17000,大连
5,danyang,20000,北京
进入hive里面
beeline -u 'jdbc:hive2://192.168.67.110:10000' -n root
建表:
create table test_4(id int,name string,salary bigint,addr string)
partitioned by (day string) //指定分区字段,一定不能与表中字段相同
row format delimited
fields terminated by ‘,’;
然后查看一下表格
select * from test_4;
1. 导入数据到分区:
把数据导入test_4里面
load data local inpath '/opt/testData/hive/worker.txt' into table test_4 partition(day='01');
load data local inpath '/opt/testData/hive/worker.txt' into table test_4 partition(day='02');
注意:导入数据后,分区条件的day也当成一个字段放在表中;
查询test_par下day=01目录下的信息:
select * from test_4 where day=’01’;
增删分区
查看分区信息:
show partitions test_4;
增加分区:
alter table test_4 add partition(day='03') partition(day='04');
增加几个分区那就在命令中添加几个partition()
通过加载数据实现添加分区:
load data local inpath '/opt/testData/hive/worker.txt' into table test_4 partition(day='05');
insert实现分区:
insert into table test_4 partition(day='06')
select * from test_5 where salary>=5000;