我们的摄取过程遇到了一个问题,会导致分区被添加到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
.
MSCK REPAIR TABLE <tablename>
不提供此功能,我也面临同样的问题,我为此找到了解决方案,
众所周知,"msck repair"命令根据目录添加分区,因此首先删除所有分区
hive>ALTER TABLE mytable drop if exists partitions(p<>'');
上面的命令删除所有分区,
然后使用msck repair
命令,它将从表位置的目录中创建分区。
hive>msck repair table mytable
似乎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)