Hive msck 描述

news/2024/10/20 21:09:49/

MSCK SQL 语法如下:

MSCK [REPAIR] TABLE table_name [ADD/DROP/SYNC PARTITIONS];

1. 背景

先创建3个分区,把分区文件删除。这时 metastore 有这个3个分区,文件上不存在。再在文件系统上创建其他两个分区,这两个分区在 metastore 不存在。

1.1 初始化SQL

drop table if exists t_drop_partitions;
create table  t_drop_partitions(c1 string)partitioned by (pt string,hr string) stored as textfile location '/tmp/t_drop_partitions';
alter table t_drop_partitions add partition(pt='20230101',hr='00') location '/tmp/t_drop_partitions/pt=20230101/hr=00';
alter table t_drop_partitions add partition(pt='20230101',hr='01') location '/tmp/t_drop_partitions/pt=20230101/hr=01';
alter table t_drop_partitions add partition(pt='20230101',hr='02') location '/tmp/t_drop_partitions/pt=20230101/hr=02';
! hadoop fs -rm -r /tmp/t_drop_partitions/pt=20230101/hr=00;
! hadoop fs -rm -r /tmp/t_drop_partitions/pt=20230101/hr=01;
! hadoop fs -rm -r /tmp/t_drop_partitions/pt=20230101/hr=02;
! hadoop fs -mkdir -p /tmp/t_drop_partitions/pt=20230101/hr=03;
! hadoop fs -mkdir -p /tmp/t_drop_partitions/pt=20230101/hr=04;
  • show partitions t_drop_partitions;
    显示有 3 个分区
hive>  show partitions t_drop_partitions;
OK
pt=20230101/hr=00
pt=20230101/hr=01
pt=20230101/hr=02
  • ls 文件系统显示2个目录
 ! hadoop fs -ls /tmp/t_drop_partitions/pt=20230101;Found 2 items
drwxr-xr-x   - hive hadoop          0 2023-04-23 14:52 /tmp/t_drop_partitions/pt=20230101/hr=03
drwxr-xr-x   - hive hadoop          0 2023-04-23 14:52 /tmp/t_drop_partitions/pt=20230101/hr=04

2. MSCK TABLE

2.1 MSCK TABLE 没有选项

执行初始化SQL。

hive> MSCK TABLE t_drop_partitions;
OK
Partitions not in metastore:	t_drop_partitions:pt=20230101/hr=03	t_drop_partitions:pt=20230101/hr=04
Partitions missing from filesystem:	t_drop_partitions:pt=20230101/hr=00	t_drop_partitions:pt=20230101/hr=01	t_drop_partitions:pt=20230101/hr=02
Time taken: 0.094 seconds, Fetched: 2 row(s)

MSCK TABLE 不做任何操作,仅仅显示 metastore 和 文件系统中不匹配的分区。
Partitions not in metastore: 这些分区存在于文件系统,但是不在 Metastore 。
Partitions missing from filesystem: 这些存在于Metastore,但是不在文件系统 。

  • show partitions 还是显示3个分区
hive> show partitions t_drop_partitions;
OK
pt=20230101/hr=00
pt=20230101/hr=01
pt=20230101/hr=02
Time taken: 0.105 s

2.2 MSCK REPAIR TABLE

MSCK [REPAIR] TABLE 对表的分区进行修复。后面可以根修复的选项,默认是 ADD。
ADD PARTITIONS: 把文件系统上存在,metastore 上不存在的分区添加到 metastore。
DROP PARTITIONS: 把 metastore 上存在,文件系统上不存在的分区从 metastore 删除。
SYNC PARTITIONS: 代表 ADD PARTITIONS 和 DROP PARTITIONS 同时选中。

2.2. 1ADD PARTITIONS

执行初始化SQL。
执行 MSCK REPAIR TABLE。

hive>  MSCK REPAIR TABLE t_drop_partitions;
OK
Partitions not in metastore:	t_drop_partitions:pt=20230101/hr=03	t_drop_partitions:pt=20230101/hr=04
Partitions missing from filesystem:	t_drop_partitions:pt=20230101/hr=00	t_drop_partitions:pt=20230101/hr=01	t_drop_partitions:pt=20230101/hr=02
Repair: Added partition to metastore t_drop_partitions:pt=20230101/hr=03
Repair: Added partition to metastore t_drop_partitions:pt=20230101/hr=04

Repair: Added partition to metastore: 部分显示了 metastore 添加了哪些分区。

hive> show partitions t_drop_partitions;
OK
pt=20230101/hr=00
pt=20230101/hr=01
pt=20230101/hr=02
pt=20230101/hr=03
pt=20230101/hr=04

现在有5个分区。

2.2. DROP PARTITIONS

执行初始化SQL。
执行 MSCK REPAIR TABLE xxx DROP PARTITIONS。

hive>  MSCK REPAIR TABLE t_drop_partitions DROP PARTITIONS;
OK
Partitions not in metastore:	t_drop_partitions:pt=20230101/hr=03	t_drop_partitions:pt=20230101/hr=04
Partitions missing from filesystem:	t_drop_partitions:pt=20230101/hr=00	t_drop_partitions:pt=20230101/hr=01	t_drop_partitions:pt=20230101/hr=02
Repair: Dropped partition from metastore test.t_drop_partitions:pt=20230101/hr=02
Repair: Dropped partition from metastore test.t_drop_partitions:pt=20230101/hr=01
Repair: Dropped partition from metastore test.t_drop_partitions:pt=20230101/hr=00

Repair: Dropped partition: 部分显示了从metastore 删除了哪些分区。

hive> show partitions t_drop_partitions;
OK
Time taken: 0.066 seconds

现在有0个分区。

2.3. SYNC PARTITIONS

执行初始化SQL。
执行 MSCK REPAIR TABLE xxx SYNC PARTITIONS。

Partitions not in metastore:	t_drop_partitions:pt=20230101/hr=03	t_drop_partitions:pt=20230101/hr=04
Partitions missing from filesystem:	t_drop_partitions:pt=20230101/hr=00	t_drop_partitions:pt=20230101/hr=01	t_drop_partitions:pt=20230101/hr=02
Repair: Added partition to metastore t_drop_partitions:pt=20230101/hr=03
Repair: Added partition to metastore t_drop_partitions:pt=20230101/hr=04
Repair: Dropped partition from metastore test.t_drop_partitions:pt=20230101/hr=00
Repair: Dropped partition from metastore test.t_drop_partitions:pt=20230101/hr=02
Repair: Dropped partition from metastore test.t_drop_partitions:pt=20230101/hr=01
Time taken: 0.225 seconds, Fetched: 7 row(s)

Repair: Added partition to metastore: 显示了在 metastore 添加了哪些分区。
Repair: Dropped partition from metastore : 显示了从metastore 删除了哪些分区。

hive> show partitions t_drop_partitions;
OK
Time taken: 0.066 seconds

现在有0个分区。


http://www.ppmy.cn/news/51747.html

相关文章

vue实现多布局模式

1、目标效果 源码地址:multipal-layout-demo: vue2实现多布局暗黑模式 默认布局:头部宽度100%,侧边栏、内容区 顶部布局:头部宽度100%,内容区 侧边栏布局:侧边栏高度100%,头部、内容区 2、原理…

MobTech MobPush|A/B测试提升运营决策

在实际推送过程中,我们常常有这样的困惑: 我们如何确定哪种推送内容更能吸引用户? 我们如何衡量推送效果的提升程度? 我们如何优化推送方案,实现更高的ROI? 为了解决这些困惑,我们需要一种科…

类加载和实例化

类初始化和实例初始化 一个实例对象的创建包括&#xff1a;类初始化和实例初始化1. 一个类要创建实例需要先加载并初始化该类,main方法所在的类需要先加载和初始化2. 一个子类要初始化需要先初始化父类3. 一个类初始化就是执行<clinit>()方法<clinit>方法由静态变量…

算法——分布式——一致性哈希、一致性hash图解动画

分布式算法——一致性哈希、一致性Hash 概述传统Hash算法算法步骤生成Hash环定位服务器定位数据和映射服务器 服务器变更Hash环倾斜虚拟节点总结 概述 一致性哈希算法在1997年由麻省理工学院提出&#xff0c;是一种特殊的哈希算法&#xff0c;目的是解决分布式缓存的问题。在移…

带你打开GCC的大门

START hi&#xff0c;大家好&#xff01; 今天带大家了解一下GCC。 首先说一句&#xff1a;大写的GCC和小写的gcc不是一个东西呦&#xff0c;下面我们慢慢道来... 1. GCC是什么&#xff1f; GNU Compiler Collection (GCC)是GNU项目开发的编译工具集&#xff0c;支持各种编…

DATAFAKER 使用方法记录

DATAFAKER 使用方法记录 win10 64位 Python 3.10.11 参考网址 datafaker的使用–详细教程 https://blog.csdn.net/A15517340610/article/details/105623103 https://github.com/gangly/datafaker python 版本 It is compatible with python2.7 and python3.4 也就是说 他…

Python 读写 CSV 数据

问题 你想读写一个 CSV 格式的文件 解决方案 对于大多数的 CSV 格式的数据读写问题&#xff0c;都可以使用 csv 库。 例如&#xff1a;假设你在一 个名叫 stocks.csv 文件中有一些股票市场数据&#xff0c;像这样&#xff1a; Symbol,Price,Date,Time,Change,Volume "…

为什么企业要做大规模敏捷?

背景 软件工程里一个重要的指标就是“可用的软件”&#xff0c;敏捷宣言里也同样告诉我们“工作的软件高于详尽的文档”&#xff0c;那“可用的软件”、“工作的软件”意味着什么呢&#xff1f;在我的理解里&#xff0c;可以经历用户 “千锤百炼”的软件就是一个“可用的软件”…