在Metastore中进行分区,但HDFS中不存在路径

And*_*rew 6 hive hdfs

我们的提取过程遇到问题,这会导致将分区添加到Hive中的表中,但是HDFS中的路径实际上并不存在。我们已经解决了该问题,但是仍然存在这些错误的分区。使用Tez查询这些表时,我们得到FileNotFound异常,指向HDFS中不存在的位置。如果我们使用MR而不是Tez,则查询有效(这对我来说很混乱),但是它太慢了。

有没有办法列出所有具有此探针的分区? MSCK REPAIR似乎可以解决相反的问题,即HDFS中存在数据,但Hive中没有分区。

编辑:更多信息。这是找不到文件异常的输出:

java.io.FileNotFoundException: File hdfs://<server>/db/tables/2016/03/14/mytable does not exist.

如果运行show partitions <db.mytable>,我将获得所有分区,包括的一个分区dt=2016-03-14

show table extended like '<db.mytable>' partition(dt='2016-03-14'返回相同的位置: location:hdfs://server/db/tables/2016/03/14/mytable

小智 5

MSCK REPAIR TABLE <tablename> 没有提供此功能,我也面临同样的问题,因此我找到了解决方案,

众所周知,“ msck repair”命令会根据目录添加分区,因此首先删除所有分区

hive>ALTER TABLE mytable drop if exists partitions(p<>'');
Run Code Online (Sandbox Code Playgroud)

上面的命令删除所有分区,

然后使用msck repair命令,它将从表位置的目录创建分区。

hive>msck repair table mytable
Run Code Online (Sandbox Code Playgroud)


Dav*_*itz 2

它似乎MSCK REPAIR TABLE不会删除指向丢失目录的分区,但它确实列出了这些分区(请参阅参考资料Partitions not in metastore:),因此只需编写一些脚本/手动工作,您就可以根据给定的列表删除它们。

hive> create table mytable (i int) partitioned by (p int);
OK
Time taken: 0.539 seconds

hive> !mkdir mytable/p=1;
hive> !mkdir mytable/p=2;
hive> !mkdir mytable/p=3;

hive> msck repair table mytable;
OK
Partitions not in metastore:    mytable:p=1 mytable:p=2 mytable:p=3
Repair: Added partition to metastore mytable:p=1
Repair: Added partition to metastore mytable:p=2
Repair: Added partition to metastore mytable:p=3
Time taken: 0.918 seconds, Fetched: 4 row(s)

hive> show partitions mytable;
OK
p=1
p=2
p=3
Time taken: 0.331 seconds, Fetched: 3 row(s)

hive> !rmdir mytable/p=1;
hive> !rmdir mytable/p=2;
hive> !rmdir mytable/p=3;

hive> msck repair table mytable;
OK
Partitions missing from filesystem: mytable:p=1 mytable:p=2 mytable:p=3
Time taken: 0.425 seconds, Fetched: 1 row(s)

hive> show partitions mytable;
OK
p=1
p=2
p=3
Time taken: 0.56 seconds, Fetched: 3 row(s)
Run Code Online (Sandbox Code Playgroud)