hive/hdfs 移动数据未按预期工作

hive/hdfs moving data not working as expected

我在 hive 中有一个 table 称为测试,位置是 'hdfs://location1/partition='x'' 并移动所有数据到 'hdfs://location2/partition='x''.

hdfs dfs -mv /location1 /location2

然后我做了

alter table test set location 'hdfs://location2'.

正在做

 hdfs dfs -ls /location2

我看到右分区的所有数据

查询以获取计数,即

select count(*) from test 

工作正常。

但是在做

 select * from test 

没有提取任何记录。

无法确定移动时出了什么问题。

您需要手动删除指向原始位置的现有分区 "hdfs://location1/partition='x'"。 使用以下命令手动删除所有分区:

alter table test drop partition(partition='x');

删除所有分区后运行以下命令更新配置单元元存储中的新分区:

msck repair table test;

这是为什么?因为 table 的位置已更改,但配置单元 Metastore 未使用新位置的新分区进行更新。 Hive Metastore 仍然保存着旧位置的分区信息。一旦你删除分区和 运行 the

msck repair

命令,hive metastore 将使用来自新位置的新分区进行更新。