09-hive中的分区表

lines terminated by ‘\n’;

2 ) 加载数据

user1.txt (user2.txt)

1 user1 1

2 user2 2

3 user1 1

4 user2 2

5 user2 2

6 user1 1

7 user2 1

8 user1 2

9 user2 2

load data local inpath ‘./root/user1.txt’ into table part1 partition(dt=‘2020-05-05’);

select * from part1;

1 user1 1 2020-05-05

2 user2 2 2020-05-05

3 user1 1 2020-05-05

4 user2 2 2020-05-05

5 user2 2 2020-05-05

6 user1 1 2020-05-05

7 user2 1 2020-05-05

8 user1 2 2020-05-05

9 user2 2 2020-05-05

load data local inpath ‘./root/user2.txt’ into table part1 partition(dt=‘2020-05-06’);

这样就会从2020-05-05里查

select * from part1 where dt=‘2020-05-05’;

二级分区的使用

1 ) 建表语句

create table if not exists part2(

id int,

name string,

age int

)

partitioned by (year string,month string)

row format delimited

fields terminated by ‘\t’;

2 ) 加载数据

load data local inpath ‘./root/user1.txt’ into table part1 partition(year=‘2020’,month=‘03’);

load data local inpath ‘./root/user1.txt’ into table part1 partition(year=‘2020’,month=‘04’);

load data local inpath ‘./root/user1.txt’ into table part1 partition(year=‘2020’,month=‘05’);

select * from part2 where year=‘2020’ and month=‘04’;

三级分区的使用

1 ) 建表语句

create table if not exists part2(

id int,

name string,

age int

)

partitioned by (year string,month string,day string)

row format delimited

fields terminated by ‘\t’;

2 ) 加载数据

load data local inpath ‘./root/user1.txt’ into table part1 partition(year=‘2020’,month=‘03’,day=‘01’);

load data local inpath ‘./root/user1.txt’ into table part1 partition(year=‘2020’,month=‘04’,day=‘02’);

load data local inpath ‘./root/user1.txt’ into table part1 partition(year=‘2020’,month=‘05’,day=‘03’);

select * from part2 where year='2020’and month='04’and day=‘02’;

在hive中,分区字段名是不区分大小写的,不过字段值是区分大小写的。

查看分区

show partitions tableName;

举例

show partitions part1

删除分区

alter table part2 drop partition(year=‘2020’,month=‘05’,day=‘03’);

– 删除多个分区 逗号隔开

alter table part2 drop

partition(year=‘2020’,month=‘05’,day=‘03’),

partition year=‘2020’,month=‘04’,day=‘02’;

结论︰在删除操作时,对应的目录(最里层)会被删除,上级目录如果没有文件存在,也会被删除,如果有文件存在,则不会被删除。

在这里插入图片描述

hive分区类型详解


在这里插入图片描述

创建动态分区的案例

1 )创建动态分区表

create table if not exists dy_part1(

id int,

name string,

gender string,

age int,

academy string

)

partitioned by (dt string)

row format delimited fields terminated by ‘\t’

;

2 )动态分区加载数据

下面方式不要用,因为不是动态加载数据

load data local inpath ‘./root/user1.txt’ into table dy_part1 partition(dt=‘2020-05-06’);

正确方式,要从别的表中加载数据

第一步:先创建临时表

create table if not exists temp_part1(

id int,

name string,

gender string,

age int,

academy string

)

partitioned by (dt string)

row format delimited fields terminated by ‘\t’

;

注意

创建临时表时,必须要有动态分区表中的分区字段

第二步:导入数据到临时表

在这里插入图片描述

第三步:动态加载到表

insert into dy_part1 partition(dt) select sid name,gender,age,academy,dt from temp_part1;

注意:严格模式下,给动态分区表导入数据时,分区字段至少要有一个分区字段是静态值

非严格模式下,导入数据时,可以不指定静态值。

混合分区示例

在这里插入图片描述

在这里插入图片描述

分区表注意事项

最后

Java架构进阶面试及知识点文档笔记

这份文档共498页,其中包括Java集合,并发编程,JVM,Dubbo,Redis,Spring全家桶,MySQL,Kafka等面试解析及知识点整理

image

Java分布式高级面试问题解析文档

其中都是包括分布式的面试问题解析,内容有分布式消息队列,Redis缓存,分库分表,微服务架构,分布式高可用,读写分离等等!

image

互联网Java程序员面试必备问题解析及文档学习笔记

image

Java架构进阶视频解析合集
]( )分区表注意事项

最后

Java架构进阶面试及知识点文档笔记

这份文档共498页,其中包括Java集合,并发编程,JVM,Dubbo,Redis,Spring全家桶,MySQL,Kafka等面试解析及知识点整理

[外链图片转存中…(img-3OJ1TcJH-1718727468614)]

Java分布式高级面试问题解析文档

其中都是包括分布式的面试问题解析,内容有分布式消息队列,Redis缓存,分库分表,微服务架构,分布式高可用,读写分离等等!

[外链图片转存中…(img-xEQ0fmW5-1718727468615)]

互联网Java程序员面试必备问题解析及文档学习笔记

[外链图片转存中…(img-yaSHUJdx-1718727468615)]

Java架构进阶视频解析合集

  • 14
    点赞
  • 27
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值