Apache Hive: Resolve “unable to instantiate org.apache.hadoop.hive.ql.metadata.SessionHiveMetaStoreClient”

The HiveException java.lang.RuntimeException: Unable to instantiate org.apache.hadoop.hive.ql.metadata.SessionHiveMetaStoreClient exception is a HiveException that is thrown when the Hive Metastore client cannot be instantiated. This can happen for a number of reasons, such as:

  • The Hive Metastore database is not accessible.
  • The Hive Metastore database is not running.
  • The Hive configuration file is incorrect.
  • The schematool command has not been run to initialize the Hive Metastore database.

Here is an example of the error message that you might see:

Steps to resolve:

Here are the steps on how to resolve the HiveException java.lang.RuntimeException: Unable to instantiate org.apache.hadoop.hive.ql.metadata.SessionHiveMetaStoreClient:

Step 1: Update Hive configuration

Check the Hive configuration file hive-site.xml. Make sure that the following properties are set correctly:

  • javax.jdo.option.ConnectionURL: This property specifies the JDBC URL of the Metastore database. The default value is jdbc:derby:;databaseName=metastore_db;create=true.
  • javax.jdo.option.ConnectionDriverName: This property specifies the JDBC driver class for the Metastore database. The default value is org.apache.derby.jdbc.EmbeddedDriver.
  • hive.metastore.warehouse.dir: This property specifies the directory where the Hive data warehouse is located.

If the Hive configuration file is correct, check it by running a query in the Hive CLI. If changing the Hive configuration file doesn’t fix the problem, follow these steps carefully. This will delete the database and table metadata, but the data will be safe. You can then run the scripts that define your databases and tables again.

Step 2: Backup and delete the Hive Metastore directory

Make a backup of the Hive Metastore directory and then delete the directory. The default path to the Hive Metastore directory is $HIVE_HOME/metastore_db. It could be different depending on your setup.

mv -rf $HIVE_HOME/metastore_db $HIVE_HOME/metastore_db_bk

Step 3: Initialize the Metastore database

Run the schematool command to initialize the Metastore database. To do this, run the following command:

schematool -initSchema -dbType derby

This command will create the Metastore database if it does not already exist, and it will initialize the database schema.

Step 4:Verify using the Hive CLI

You can now verify this by running a query in the Hive CLI.

If the query runs successfully, then the Hive Metastore issue is resolved and you should not get the Unable to instantiate org.apache.hadoop.hive.ql.metadata.SessionHiveMetaStoreClient exception.

Leave a Reply

Your email address will not be published. Required fields are marked *