How to Fix Error: Unable to Instantiate org.apache.hadoop.hive.ql.metadata.SessionHiveMetaStoreClient

Sheeraz Gul Feb 02, 2024
How to Fix Error: Unable to Instantiate org.apache.hadoop.hive.ql.metadata.SessionHiveMetaStoreClient

This tutorial demonstrates how to solve java.lang.RuntimeException: Unable to instantiate org.apache.hadoop.hive.ql.metadata.SessionHiveMetaStoreClient.

Unable to instantiate org.apache.hadoop.hive.ql.metadata.SessionHiveMetaStoreClient in Java

The Apache Hive is an open-source data warehouse software for reading, managing, and writing the large data sets stored in Hadoop files. It works similar to SQL; sometimes, if Hadoop and Hive are not configured properly, it can throw the error java.lang.RuntimeException: Unable to instantiate org.apache.hadoop.hive.ql.metadata.SessionHiveMetaStoreClient.

The solution to this error while working on the Ubuntu platform is below. Follow the methods below to run the Hive shell properly without any errors.

the ~/.bashrc File

Open the bashrc file in the home directory and add the following environment variables at the end of the file sudo gedit ~/.bashrc.

# directory configuration for JAVA_HOME
export JAVA_HOME="/usr/lib/jvm/java-9-oracle"
export PATH="$PATH:$JAVA_HOME/bin"

# directory configuration for HADOOP_HOME
export HADOOP_HOME=/usr/local/hadoop
export PATH=$PATH:$HADOOP_HOME/bin
export PATH=$PATH:$HADOOP_HOME/sbin

export HIVE_HOME=/usr/lib/hive
export PATH=$PATH:$HIVE_HOME/bin

the .jar File

We also need to put the .jar file MySQL-connector-java-5.1.28.jar or any latest version in the lib directory of Hive home.

Create the hive-site.xml File

We have to create the hive-site.xml file, which will be placed in the conf directory of Hive. Make sure to insert the following code in the file.

<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<?xml-stylesheet type="text/xsl" href="configuration.xsl"?>
<configuration>

<property>
  <name>javax.jdo.option.ConnectionURL</name>
  <value>jdbc:mysql://localhost/metastore?createDatabaseIfNotExist=true</value>
</property>

<property>
  <name>javax.jdo.option.ConnectionDriverName</name>
  <value>com.mysql.jdbc.Driver</value>
</property>

<property>
  <name>javax.jdo.option.ConnectionUserName</name>
  <value>root</value>
</property>

<property>
  <name>javax.jdo.option.ConnectionPassword</name>
  <value>root</value>
</property>

<property>
  <name>datanucleus.autoCreateSchema</name>
  <value>true</value>
</property>

<property>
  <name>datanucleus.fixedDatastore</name>
  <value>true</value>
</property>

<property>
 <name>datanucleus.autoCreateTables</name>
 <value>True</value>
 </property>

</configuration>

Install the Required Software and Plugins

To run the Hive shell on Ubuntu, we must install a few software first. The list is given below.

  1. MySQL
  2. Hadoop
  3. Hive
  4. Java

Once this software and plugins are successfully installed, we can run the Hive shell.

Execute Services and Run Hive Shell

The final method is the execution part, where we need to execute all the services and run the Hive shell. Follow the steps below.

  1. Start all Hadoop’s services by starting start-all.sh.
  2. Now check if all the services of Hadoop are running. Use the jps command to check that.
  3. Finally, enter the Hive command to start the Hive shell.
Author: Sheeraz Gul
Sheeraz Gul avatar Sheeraz Gul avatar

Sheeraz is a Doctorate fellow in Computer Science at Northwestern Polytechnical University, Xian, China. He has 7 years of Software Development experience in AI, Web, Database, and Desktop technologies. He writes tutorials in Java, PHP, Python, GoLang, R, etc., to help beginners learn the field of Computer Science.

LinkedIn Facebook

Related Article - Java Error