如何通过 thrift 客户端在 Hive Standalone Metastore 服务器上运行 MSCK

问题描述

我使用 Hive 作为我的元存储数据库和 Hive Standalone metastore 来处理 DDL,通过实现服务器节俭映射的 this thrift client

我想执行 MSCK(或其他类似方法)以向 Hive 新表批量添加分区。

但是 afaik,this Thrift mapping file 没有公开 msck 方法。 虽然,我看到有一些关于 Msck 实现的 inside standalone server (我认为它应该在 jira HIVE-17824 中实现)。但是 Hivemetastore 类中没有(我理解这是 Thrift 服务器方法的映射)。

有谁知道我是否可以通过 thrift 客户端通过独立的 hive 服务器运行 MSCK?

解决方法

我目前使用 python 成功地使用了这个客户端:PyHive

您也可以从 dbeaver 执行此操作(如果该命令必须由某个人运行):dbeaver

编辑(我没有意识到问题是关于将命令直接发送到 hive Metastore):

名为 IMetaStoreClient 的接口(hive 客户端和 hive Metastore 服务器之间的协议)没有实现 MSCK 命令,因为它不需要它。让我解释一下 MSCK 命令背后的逻辑:

  1. 检查表是否存在于 hive Metastore 中。

  2. 在表存储其数据的物理文件系统中扫描新分区。请参阅代码 checkMetastore

  3. 创建/添加这些新分区。请参阅代码 createPartitionsInBatches。这段代码最终使用了 hive Metastore 客户端的 add_partitions 方法。

    add_partitions此时,而不是在客户端应用程序将数据发送到 hive Metastore 服务器之前

  4. 删除不再存在于文件系统中的分区。请参阅代码 dropPartitionsInBatches,该代码最终使用了 hive Metastore 客户端的名为 dropPartitions 的方法。

    dropPartitions同样,正是在这一点上,而不是在客户端应用程序向 Hive Metastore 服务器发送数据之前

MSCK 并不是一个真正的 hive Metastore 命令。它需要由运行该 MSCK 命令的客户端实现的逻辑。在您的情况下,您应该将该逻辑添加到您要使用的客户端。

例如,Spark 在使用 MSCK 时已经实现了该逻辑。