码迷,mamicode.com
首页 > 其他好文 > 详细

Hive元数据升级

时间:2017-03-26 17:11:36      阅读:220      评论:0      收藏:0      [点我收藏+]

标签:roots   records   class   contain   blog   sts   com   syntax   div   

如果我们Hadoop的core-site.xml文件中的fs.defaultFS配置由于某种原因需要修改,比如Hadoop升级、重新命名fs.defaultFS等。也就是由hdfs://old 变成hdfs://new,如下:

<property>  
<name>fs.defaultFS</name> 
<value>hdfs://old</value> 
</property> 
变成 
  <property> 
<name>fs.defaultFS</name>
<value>hdfs://new </value>
 </property> 

这些修改会影响到Hive的正常运行,因为Hive在建表的时候保存了该表的数据存放路径,而存放路径里面就会带有fs.defaultFS属性的值,比如:hdfs://old/user/hive/warehouse/xxx,但是这时候Hadoop中的fs.defaultFS配置已经修改了,所以如果你在Hive中查询,就会出现错误。因为hdfs://old已经变了。有两种方法可以修改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元数据升级

标签:roots   records   class   contain   blog   sts   com   syntax   div   

原文地址:http://www.cnblogs.com/thinkpad/p/6623252.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!