On this page
Hive MetaTool
Hive MetaTool
Hive MetaTool 使 Management 员可以对元存储中数据库,表和分区 Logging 的位置字段进行批量更新。它提供以下功能:
能够搜索和替换引用 NN 的元存储 Logging 的 HDFS NN(NameNode)位置。一种用途是将 Hive 部署过渡到HDFS HA NN(HDFS 高可用性 NameNode)。
用于对元存储执行JDOQL的命令行工具。对元存储执行 JDOQL 的能力对于用户和 Hive 开发人员都是有用的调试工具。
metatool 命令
metatool
命令使用以下选项调用 Hive MetaTool:
Option | Description |
---|---|
-listFSRoot |
打印当前文件系统根目录(NameNode)的位置。该值的前缀为hdfs:// scheme 。 |
-updateLocation <new-loc> <old-loc> |
更新 Hive Metastore 中的记录,以指向新的 NameNode 位置(文件系统根位置)。 * new-loc 和 old-loc 都应该是具有有效主机名和方案的有效 URI。要升级到 HDFS HA NN, new-loc *应该与dfs.nameservices 属性的值匹配。 * old-loc *应该与 listFSRoot 选项返回的值匹配。 |
当使用 dryRun 选项运行时,将显示更改,但不会保留更改。当使用 serdepropKey / tablePropKey 选项运行时, updateLocation 查找指定的* serde-prop-key / table-prop-key *,并在找到时更新其值。 |
|
-serdePropKey <serde-prop-key> |
指定 SerDe 属性键,其值字段可能引用 HDFS NameNode 的位置,因此可能需要更新。例如,要更新 Haivvero 架构 URL,请为此参数指定 schema.url。 此选项仅对 updateLocation 选项有效。 |
-tablePropKey <table-prop-key> |
指定表属性键,其值字段可能引用 HDFS NameNode 的位置,因此可能需要更新。例如,要更新 Avro SerDe 模式 URL,请为此参数指定 avro.schema.url。 此选项仅对 updateLocation 选项有效。 |
-dryRun |
执行 updateLocation 更改的试运行。会显示 updateLocation 更改,但不会保留。 此选项仅对 updateLocation 选项有效。 |
-executeJDOQL <query-string> |
执行给定的 JDOQL 查询。 |
-help |
打印命令选项及其说明的列表。 |
如果不确定使用哪个版本的 Avro SerDe,请将 serdePropKey 和 tablePropKey 参数及其各自的值传递给 updateLocation 。
Hive Configuration Directory
请注意,metatool
是 HiveManagement 员的命令,它需要直接访问 metastore RDBMS。在某些环境中,RDBMS 登录信息(尤其是密码或密码密钥)仅存储在 metastore 服务器主机上或 metastore 服务器特定的配置目录中(具有更严格的文件系统权限)。在这种情况下,请确保您以配置用户身份在 metastore 服务器计算机上运行,并且还适当地设置了 HIVE_CONF_DIR 环境变量(例如export HIVE_CONF_DIR=<path to metastore server config dir>
)。
Usage Example
以下metatool
命令使用 updateLocation ,tabletablePropKey 和 serdePropKey 选项将 NameNode 位置从 hdfs:// namenode2:8020 更新为 hdfs:// localhost:9000.
./hive --service metatool -updateLocation hdfs://localhost:9000 hdfs://namenode2:8020 -tablePropKey avro.schema.url -serdePropKey avro.schema.url
Initializing HiveMetaTool..
15/04/22 14:18:42 INFO metastore.ObjectStore: ObjectStore, initialize called
15/04/22 14:18:42 INFO DataNucleus.Persistence: Property hive.metastore.integral.jdo.pushdown unknown - will be ignored
15/04/22 14:18:42 INFO DataNucleus.Persistence: Property datanucleus.cache.level2 unknown - will be ignored
15/04/22 14:18:43 INFO metastore.ObjectStore: Setting MetaStore object pin classes with hive.metastore.cache.pinobjtypes="Table,StorageDescriptor,SerDeInfo,Partition,Database,Type,FieldSchema,Order"
15/04/22 14:18:43 INFO DataNucleus.Datastore: The class "org.apache.hadoop.hive.metastore.model.MFieldSchema" is tagged as "embedded-only" so does not have its own datastore table.
15/04/22 14:18:43 INFO DataNucleus.Datastore: The class "org.apache.hadoop.hive.metastore.model.MOrder" is tagged as "embedded-only" so does not have its own datastore table.
15/04/22 14:18:44 INFO DataNucleus.Datastore: The class "org.apache.hadoop.hive.metastore.model.MFieldSchema" is tagged as "embedded-only" so does not have its own datastore table.
15/04/22 14:18:44 INFO DataNucleus.Datastore: The class "org.apache.hadoop.hive.metastore.model.MOrder" is tagged as "embedded-only" so does not have its own datastore table.
15/04/22 14:18:44 INFO DataNucleus.Query: Reading in results for query "org.datanucleus.store.rdbms.query.SQLQuery@0" since the connection used is closing
15/04/22 14:18:44 INFO metastore.MetaStoreDirectSql: Using direct SQL, underlying DB is MYSQL
15/04/22 14:18:44 INFO metastore.ObjectStore: Initialized ObjectStore
Looking for LOCATION_URI field in DBS table to update..
Successfully updated the following locations..
Updated 0 records in DBS table
Looking for LOCATION field in SDS table to update..
Successfully updated the following locations..
Updated 0 records in SDS table
Looking for value of avro.schema.url key in TABLE_PARAMS table to update..
Successfully updated the following locations..
Updated 0 records in TABLE_PARAMS table
Looking for value of avro.schema.url key in SD_PARAMS table to update..
Successfully updated the following locations..
Updated 0 records in SD_PARAMS table
Looking for value of avro.schema.url key in SERDE_PARAMS table to update..
Successfully updated the following locations..
Updated 0 records in SERDE_PARAMS table
使用 metatool 读取表信息(适用于所有 metastore 后端)。
HIVE_CONF_DIR=/etc/hive/conf/conf.server/ hive --service metatool -executeJDOQL 'select dbName+"."+tableName+"::"+colName+"="+numDVs from org.apache.hadoop.hive.metastore.model.MTableColumnStatistics';
HIVE_CONF_DIR=/etc/hive/conf/conf.server/ hive --service metatool -executeJDOQL 'select dbName+"."+tableName+"("+partitionName+")::"+colName+"="+numDVs from org.apache.hadoop.hive.metastore.model.MPartitionColumnStatistics';