如果我们Hadoop的core-site.xml文件中的fs.defaultFS配置由于某种原因需要修改,比如Hadoop升级、重新命名fs.defaultFS等。也就是由hdfs://olditeblog变成hdfs://newiteblogle ,如下:
<property> <name>fs.defaultFS</name> <value>hdfs://olditeblog</value> </property> 变成 <property> <name>fs.defaultFS</name> <value>hdfs://newiteblogle </value> </property>
这些修改会影响到Hive的正常运行,因为Hive在建表的时候保存了该表的数据存放路径,而存放路径里面就会带有fs.defaultFS属性的值,比如:hdfs://olditeblog/user/hive/warehouse/xxx,但是这时候Hadoop中的fs.defaultFS配置已经修改了,所以如果你在Hive中查询,就会出现错误。因为hdfs://olditeblog已经变了。有两种方法可以修改Hive元数据中的fs.defaultFS值。
一、直接去数据库中修改
我们知道,Hive的元数据信息是存放在关系型数据库中的,我们只要找到存放这些数据的Table,然后用SQL去修改就行了。但是这样比较麻烦,你还得去登录数据库,最重要的是这样还很容易出错,所以不推荐使用。
二、使用Hive自带命令修改
Hive自带了修改元素相关的命令,我们可以直接使用bin/metatool命令去修改。先看看这个命令都有什么功能:
[iteblog@www.iteblog.com hive]$ bin/metatool -help
Initializing HiveMetaTool..
usage: metatool
-dryRun Perform a dry run of updateLocation
changes.When run with the dryRun
option updateLocation changes are
displayed but not persisted. dryRun
is valid only with the
updateLocation option.
-executeJDOQL <query-string> execute the given JDOQL query
-help print this message
-listFSRoot print the current FS root locations
-serdePropKey <serde-prop-key> Specify the key for serde property
to be updated. serdePropKey option
is valid only with updateLocation
option.
-tablePropKey <table-prop-key> Specify the key for table property
to be updated. tablePropKey option
is valid only with updateLocation
option.
-updateLocation <new-loc> <old-loc> Update FS root location in the
metastore to new location.Both
new-loc and old-loc should be valid
URIs with valid host names and
schemes.When run with the dryRun
option changes are displayed but
are not persisted. When run with
the serdepropKey/tablePropKey
option updateLocation looks for the
serde-prop-key/table-prop-key that
is specified and updates its value
if found.
从上面命令可以看出,使用-listFSRoot参数可以查看当前FS root的路径,如下:
[iteblog@www.iteblog.com hive]$ bin/metatool -listFSRoot Initializing HiveMetaTool.. ... ... Listing FS Roots.. hdfs://olditeblog/user/hive/warehouse/test1.db hdfs://olditeblog/user/hive/warehouse hdfs://olditeblog/user/hive/warehouse/test2.db
从上面可以看到FS Roots信息全部都是hdfs://olditeblog,现在我们可以使用bin/metatool修更新FS Roots,如下:
[iteblog@www.iteblog.com hive]$ bin/metatool -updateLocation hdfs://newiteblog hdfs://olditeblog Initializing HiveMetaTool.. ... ... Updated 274 records in SDS table Warning: Found records with bad LOCATION in SDS table..
更新完之后,我们可以再看下FS Roots信息是否修改完成:
[iteblog@www.iteblog.com hive]$ bin/metatool -listFSRoot Initializing HiveMetaTool.. ... ... Listing FS Roots.. hdfs://newiteblog/user/hive/warehouse/test1.db hdfs://newiteblog/user/hive/warehouse hdfs://newiteblog/user/hive/warehouse/test2.db
可以看出FS Roots信息已经全部更新完成。而且Hive表查询运行正常了。
本博客文章除特别声明,全部都是原创!原创文章版权归过往记忆大数据(过往记忆)所有,未经许可不得转载。
本文链接: 【Hive元数据升级】(https://www.iteblog.com/archives/1486.html)

