title: SparkSQL error: org.apache.hadoop.hive.ql.metadata.HiveException: Unable to instantiate org.apache.hadoop.hive.ql.metadata.SessionHiveMetaStoreClient
body: <p>I have installed Spark in windows machine(<strong>standalone</strong>) and trying to connect HDP 2.6 hive metastore which is available in VM using Spark app.</p>
  
  <p>I have used <strong>NAT</strong> as Network Adapter for <strong>HDP 2.6</strong> VM.
  While I am trying to connect hive metastore (<strong>HDP 2.6 VM</strong>) from <strong>Spark application</strong> (<strong><em>Local mode on Windows machine</em></strong>),  I am getting below error message.</p>
  
  <pre><code>17/08/12 17:00:16 INFO metastore: Waiting 1 seconds before next connection attempt.
  17/08/12 17:00:17 INFO metastore: Trying to connect to metastore with URI thrift://172.0.0.1:9083
  17/08/12 17:00:38 WARN metastore: Failed to connect to the MetaStore Server...
  17/08/12 17:00:38 INFO metastore: Waiting 1 seconds before next connection attempt.
  17/08/12 17:00:39 WARN Hive: Failed to access metastore. This class should not accessed in runtime.
  org.apache.hadoop.hive.ql.metadata.HiveException: java.lang.RuntimeException: Unable to instantiate org.apache.hadoop.hive.ql.metadata.SessionHiveMetaStoreClient
      at org.apache.hadoop.hive.ql.metadata.Hive.getAllDatabases(Hive.java:1236)
      at org.apache.hadoop.hive.ql.metadata.Hive.reloadFunctions(Hive.java:174)
      at org.apache.hadoop.hive.ql.metadata.Hive.&lt;clinit&gt;(Hive.java:166)
      at org.apache.hadoop.hive.ql.session.SessionState.start(SessionState.java:503)
      at org.apache.spark.sql.hive.client.HiveClientImpl.&lt;init&gt;(HiveClientImpl.scala:191)
      at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
      at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source)
      at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source)
      at java.lang.reflect.Constructor.newInstance(Unknown Source)
      at org.apache.spark.sql.hive.client.IsolatedClientLoader.createClient(IsolatedClientLoader.scala:264)
      at org.apache.spark.sql.hive.HiveUtils$.newClientForMetadata(HiveUtils.scala:362)
      at org.apache.spark.sql.hive.HiveUtils$.newClientForMetadata(HiveUtils.scala:266)
      at org.apache.spark.sql.hive.HiveExternalCatalog.client$lzycompute(HiveExternalCatalog.scala:66)
      at org.apache.spark.sql.hive.HiveExternalCatalog.client(HiveExternalCatalog.scala:65)
      at org.apache.spark.sql.hive.HiveExternalCatalog$$anonfun$databaseExists$1.apply$mcZ$sp(HiveExternalCatalog.scala:194)
      at org.apache.spark.sql.hive.HiveExternalCatalog$$anonfun$databaseExists$1.apply(HiveExternalCatalog.scala:194)
      at org.apache.spark.sql.hive.HiveExternalCatalog$$anonfun$databaseExists$1.apply(HiveExternalCatalog.scala:194)
      at org.apache.spark.sql.hive.HiveExternalCatalog.withClient(HiveExternalCatalog.scala:97)
      at org.apache.spark.sql.hive.HiveExternalCatalog.databaseExists(HiveExternalCatalog.scala:193)
      at org.apache.spark.sql.internal.SharedState.externalCatalog$lzycompute(SharedState.scala:105)
      at org.apache.spark.sql.internal.SharedState.externalCatalog(SharedState.scala:93)
      at org.apache.spark.sql.hive.HiveSessionStateBuilder.externalCatalog(HiveSessionStateBuilder.scala:39)
      at org.apache.spark.sql.hive.HiveSessionStateBuilder.catalog$lzycompute(HiveSessionStateBuilder.scala:54)
      at org.apache.spark.sql.hive.HiveSessionStateBuilder.catalog(HiveSessionStateBuilder.scala:52)
      at org.apache.spark.sql.hive.HiveSessionStateBuilder.catalog(HiveSessionStateBuilder.scala:35)
      at org.apache.spark.sql.internal.BaseSessionStateBuilder.build(BaseSessionStateBuilder.scala:289)
      at org.apache.spark.sql.SparkSession$.org$apache$spark$sql$SparkSession$$instantiateSessionState(SparkSession.scala:1050)
      at org.apache.spark.sql.SparkSession$$anonfun$sessionState$2.apply(SparkSession.scala:130)
      at org.apache.spark.sql.SparkSession$$anonfun$sessionState$2.apply(SparkSession.scala:130)
      at scala.Option.getOrElse(Option.scala:121)
      at org.apache.spark.sql.SparkSession.sessionState$lzycompute(SparkSession.scala:129)
      at org.apache.spark.sql.SparkSession.sessionState(SparkSession.scala:126)
      at org.apache.spark.sql.SparkSession.sql(SparkSession.scala:623)
      at org.apache.spark.sql.SQLContext.sql(SQLContext.scala:691)
      at com.psl.spark.RemoteHiveConnSpark1_6$.main(RemoteHiveConnSpark1_6.scala:29)
      at com.psl.spark.RemoteHiveConnSpark1_6.main(RemoteHiveConnSpark1_6.scala)
  Caused by: java.lang.RuntimeException: Unable to instantiate org.apache.hadoop.hive.ql.metadata.SessionHiveMetaStoreClient
      at org.apache.hadoop.hive.metastore.MetaStoreUtils.newInstance(MetaStoreUtils.java:1523)
      at org.apache.hadoop.hive.metastore.RetryingMetaStoreClient.&lt;init&gt;(RetryingMetaStoreClient.java:86)
      at org.apache.hadoop.hive.metastore.RetryingMetaStoreClient.getProxy(RetryingMetaStoreClient.java:132)
  </code></pre>
  
  <p><strong>Spark application:</strong></p>
  
  <pre><code>import org.apache.spark.SparkConf
  import org.apache.spark.SparkContext
  
  /**
   * @author prasanta_sahoo
   */
  object RemoteHiveConnSpark1_6 {
  
    def main(arg: Array[String]) {
  
      //Create conf object
      val conf = new SparkConf()
        .setAppName("RemoteHiveConnSpark1_6")
        .setMaster("local") // local mode
        .set("spark.storage.memoryFraction", "1")
        System.setProperty("hive.metastore.uris", "thrift://172.0.0.1:9083");
  
      //create spark context object
      val sc = new SparkContext(conf)
      val hiveContext = new org.apache.spark.sql.hive.HiveContext(sc)
      //hiveContext.setConf("hive.metastore.uris", "thrift://172.0.0.1:9083");
  
      //disable case sensitivity of SQL
      //hiveContext.sql("set spark.sql.caseSensitive=false");
      hiveContext.sql("FROM default.sample_07 SELECT code, description, total_emp, salary").collect().foreach(println)
    }
  
  }
  </code></pre>
  
  <p><strong>Can anyone please help me to solve the issue?</strong></p>