Hive Schema Tool
Metastore Schema Verification
Introduced in Hive 0.12.0. See HIVE-3764 .
Hive now records the schema version in the metastore database and verifies that the metastore schema version is compatible with Hive binaries that are going to accesss the metastore. Note that the Hive properties to implicitly create or alter the existing schema are disabled by default. Hive will not attempt to change the metastore schema implicitly. When you execute a Hive query against an old schema, it will fail to access the metastore:
The log will contain an error about version information not found:
By default the configuration property hive.metastore.schema.verification is false and metastore to implicitly write the schema version if it's not matching. To enable the strict schema verification, you need to set this property to true in
See Hive Metastore Administration for general information about the metastore.
The Hive Schema Tool
The Hive distribution now includes an offline tool for Hive metastore schema manipulation. This tool can be used to initialize the metastore schema for the current Hive version. It can also handle upgrading the schema from an older version to current. It tries to find the current schema from the metastore if it is available. This will be applicable to future upgrades like 0.12.0 to 0.13.0. In case of upgrades from older releases like 0.7.0 or 0.10.0, you can specify the schema version of the existing metastore as a command line option to the tool.
schematool figures out the SQL scripts required to initialize or upgrade the schema and then executes those scripts against the backend database. The metastore DB connection information like JDBC URL, JDBC driver and DB credentials are extracted from the Hive configuration. You can provide alternate DB credentials if needed.
schematool command invokes the Hive schema tool with these options:
The dbType is required and can be one of:
The dbType "
mssql" was added in Hive 0.13.1 with HIVE-6862 .
Initialize to current schema for a new Hive setup:
Get schema information:
Attempt to get schema information with older metastore:
Since the older metastore doesn't store the version information, the tool reports an error retrieving it.
Upgrade schema from an 0.10.0 release by specifying the 'from' version:
Upgrade dry run can be used to list the required scripts for the given upgrade.
This is useful if you just want to find out all the required scripts for the schema upgrade.
Moving a database and tables under it from default Hive catalog to a custom spark catalog
Moving a table from Hive catalog to Spark Catalog