在MetFS中分区但在HDFS中不存在路径

时间:2017-07-05 16:13:56

标签: 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

2 个答案:

答案 0 :(得分:2)

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

我们知道&#39; msck修理&#39;命令根据目录添加分区,所以首先删除所有分区

hive>ALTER TABLE mytable drop if exists partitions(p<>'');

以上命令删除所有分区,

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

hive>msck repair table mytable

答案 1 :(得分:1)

似乎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)