目录
分区表
单级分区表(一级文件夹)
多级分区表(多级文件夹)
小结
#博学谷IT学习技术支持#
鸽了这么久,最近在做项目有点忙不过来。。。。
分区表
-
单级分区表(一级文件夹)
- 用到的数据(score.txt)
- 复制代码1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
1901 01 80 01 02 90 01 03 99 02 01 70 02 02 60 02 03 80 03 01 80 03 02 80 03 03 80 04 01 50 04 02 30 04 03 20 05 01 76 05 02 87 06 01 31 06 03 34 07 02 89 07 03 98
复制代码
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21-- 1、创建分区表 静态分区: 所有的分区的值需要手动指定 动态分区: 所有的分区的值自动生成 use myhive; create table score ( sid string, -- 学号 cid string, -- 学科id sscore int -- 成绩 ) partitioned by (month string) row format delimited fields terminated by 't'; -- 2、给分区表添加数据 -- 3.查询数据 -- 3.1 条件查询 - 只查询6月份的月考成绩 -- 3.1 条件查询 - 只查询6月份或7月份成绩
答案如下
复制代码
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17#答案 -- 2、给分区表添加数据 -- /user/hive/warehouse/myhive.db/score/month=202006 load data local inpath '/export/data/score.txt' into table score partition (month='202006'); -- /user/hive/warehouse/myhive.db/score/month=202007 load data local inpath '/export/data/score.txt' into table score partition (month='202007'); -- /user/hive/warehouse/myhive.db/score/month=202008 load data local inpath '/export/data/score.txt' into table score partition (month='202008'); -- 3.查询数据 select * from score; -- 3.1 条件查询 - 只查询6月份的月考成绩 select * from score where month='202006'; -- 3.1 条件查询 - 只查询6月份或7月份成绩 select * from score where month='202007';
-
多级分区表(多级文件夹)
复制代码
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26#建表 create table score2 ( sid string, cid string, sscore int ) partitioned by (year string,month string,day string) row format delimited fields terminated by 't'; #多级分区例1 load data local inpath '/export/data/score.txt' into table score2 partition (year='2022',month='01',day='01'); #多级分区例2 load data local inpath '/export/data/score.txt' into table score2 partition (year='2022',month='02',day='02'); -- 查询 -- 查询所有数据 -- 查询指定时间的成绩(2022年成绩) -- 查询指定时间的成绩(2023年2月成绩) -- 查询指定时间的成绩(2023年2月2日成绩) -- 查看分区信息 -- 查看表结构,包含分区信息 -- 添加分区 --删除分区
答案如下
复制代码
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29#答案 -- 查询 -- 查询所有数据 select * from score2 ; -- 查询指定时间的成绩(2022年成绩) select * from score2 where year='2022'; -- 查询指定时间的成绩(2023年2月成绩) select * from score2 where year='2023' and month='02'; -- 查询指定时间的成绩(2023年2月2日成绩) select * from score2 where year='2023' and month='02' and day = '02'; --- union all,将两个表的结果上下拼接在一起(和join不同,join是左右拼接) explain select * from score where month = '202006' union all select * from score where month = '202007'; select * from score where month = '202006' or month = '202007'; -- 查看分区信息 show partitions score; show partitions score2; -- 查看表结构,包含分区信息 desc score; desc formatted covid2; //Table Type: EXTERNAL_TABLE -- 添加分区 alter table score add partition(month='202009'); alter table score add partition(month='202010') partition(month='202011'); --删除分区 alter table score drop partition(month = '202010');
小结
这些都是来自我自己的笔记,可以让你认识基础的分区表(静态)
最后
以上就是传统夕阳最近收集整理的关于Hive练习题--分区分区表的全部内容,更多相关Hive练习题--分区分区表内容请搜索靠谱客的其他文章。
本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
发表评论 取消回复