修复 Hive 表分区

修复 Hive 表分区

使用语句

msck repair table <database>.<table>

可以修复因操作 hdfs 导致的 HIVE MetaStore 数据不一致问题。

如果表分区为嵌套结构(多级分区),在执行语句时可能会出现如下错误:

ERROR : FAILED: Execution Error, return code 1 from org.apache.hadoop.hive.ql.exec.DDLTask

这是因为

Starting with Hive 1.3, MSCK will throw exceptions if directories with disallowed characters in partition values are found on HDFS. Use hive.msck.path.validation setting on the client to alter this behavior; “skip” will simply skip the directories. “ignore” will try to create partitions anyway (old behavior). This may or may not work.

翻译成中文的大概意思就是:

​ 从 Hive 1.3 开始,如果在分区的 HDFS 目录中发现不允许的字符,MSCK 将抛出异常。可以使用客户端上的 hive.msck.path.validation 设置来更改此行为; “skip” 将简单地跳过目录。 “ignore” 将无论如何都会尝试创建分区(旧行为)。

即在执行修复语句之前先将hive.msck.path.validation设置为 ignore

set hive.msck.path.validation=ignore;
msck repair table <database>.<table>;

即可。