大数据全系列 教程
1869个小节阅读:465.4k
目录
408考研
JAVA全系列 教程
面向对象的程序设计语言
Python全系列 教程
Python3.x版本,未来主流的版本
人工智能 教程
顺势而为,AI创新未来
大厂算法 教程
算法,程序员自我提升必经之路
C++ 教程
一门通用计算机编程语言
微服务 教程
目前业界流行的框架组合
web前端全系列 教程
通向WEB技术世界的钥匙
大数据全系列 教程
站在云端操控万千数据
AIGC全能工具班
A A
White Night
###3.9.6 修复分区
语法格式:
xxxxxxxxxx
MSCK [REPAIR] TABLE table_name [ADD/DROP/SYNC PARTITIONS];
msck [repair] table table_name [add/drop/sync partitions];
先在hdfs上创建/usr/person7
xxxxxxxxxx
[root@node4 ~]# hdfs dfs -mkdir /usr/person7
[root@node4 ~]# hdfs dfs -ls /usr/
Found 2 items
drwxr-xr-x - root supergroup 0 2021-11-11 21:45 /usr/person7
创建目录/usr/person7/age=10
xxxxxxxxxx
[root@node4 ~]# hdfs dfs -mkdir /usr/person7/age=10
将person.txt文件上传到/usr/person7/age=10目录下
xxxxxxxxxx
[root@node4 ~]# hdfs dfs -put /root/data/person.txt /usr/person7/age=10
[root@node4 ~]# hdfs dfs -ls /usr/person7/age=10
Found 1 items
-rw-r--r-- 3 root supergroup 496 2021-11-11 21:46 /usr/person7/age=10/person.txt
创建外部表person7
xxxxxxxxxx
create external table person7(
id int comment "唯一标识id",
name string comment "名称",
likes array<string> comment "爱好",
address map<string,string> comment "地址"
)
partitioned by(age int)
row format delimited
fields terminated by ","
collection items terminated by "-"
map keys terminated by ":"
lines terminated by "\n"
location '/usr/person7';
创建完表后,并不会将对应的分区信息同步到MySQL数据库的元数据中
在TBLS表中存在person7,它的id为31;然后去PARTITIONS表中存在,找到对应的信息。
可以通过修复分区来实现:
xxxxxxxxxx
hive> msck repair table person7;
OK
Partitions not in metastore: person7:age=10
Repair: Added partition to metastore person7:age=10
Time taken: 0.556 seconds, Fetched: 2 row(s)
在去PARTITIONS表中查询分析信息时,就有对应的分区信息了。
xxxxxxxxxx
mysql> select * from PARTITIONS;
+---------+-------------+------------------+--------------------------------+-------+--------+
| PART_ID | CREATE_TIME | LAST_ACCESS_TIME | PART_NAME | SD_ID | TBL_ID |
+---------+-------------+------------------+--------------------------------+-------+--------+
| 2 | 1636634280 | 0 | age=10 | 29 | 27 |
| 3 | 1636634360 | 0 | age=20 | 30 | 27 |
| 6 | 1636637120 | 0 | age=30 | 36 | 27 |
| 9 | 1636638770 | 0 | age=10 | 40 | 31 |
+---------+-------------+------------------+--------------------------------+-------+--------+
当然也可以通过添加分区实现本案例,但是如果分区比较多时,需要些很多的添加分区的命令,并且执行多次,如果使用修复分区,只需要一条命令搞定。