title: Unable to access to Hive warehouse directory with Spark
body: <p>I'm trying to connect to the Hive warehouse directory by using Spark on IntelliJ which is located at the following path :</p>
  
  <pre><code>hdfs://localhost:9000/user/hive/warehouse
  </code></pre>
  
  <p>In order to do this, I'm using the following code :</p>
  
  <pre><code>import org.apache.spark.sql.SparkSession
  
  // warehouseLocation points to the default location for managed databases and tables
  val warehouseLocation = "hdfs://localhost:9000/user/hive/warehouse"
  
  val spark = SparkSession
   .builder()
   .appName("Spark Hive Local Connector")
   .config("spark.sql.warehouse.dir", warehouseLocation)
   .config("spark.master", "local")
   .enableHiveSupport()
   .getOrCreate()
  
  spark.catalog.listDatabases().show(false)
  spark.catalog.listTables().show(false)
  spark.conf.getAll.mkString("\n")
  
  import spark.implicits._
  import spark.sql
  
  sql("USE test")
  sql("SELECT * FROM test.employee").show()
  </code></pre>
  
  <p>As one can see, I have created a database 'test' and create a table 'employee' into this database using the hive console. I want to get the result of the latest request.</p>
  
  <p>The 'spark.catalog.' and 'spark.conf.' are used in order to print the properties of the warehouse path and database settings. </p>
  
  <p><code>spark.catalog.listDatabases().show(false)</code> gives me :</p>
  
  <ul>
  <li>name : default</li>
  <li>description : Default Hive database</li>
  <li>locationUri : hdfs://localhost:9000/user/hive/warehouse</li>
  </ul>
  
  <p><code>spark.catalog.listTables.show(false)</code> gives me an empty result. So something is wrong at this step.</p>
  
  <p>At the end of the execution of the job, i obtained the following error : </p>
  
  <pre><code>&gt; Exception in thread "main" org.apache.spark.sql.catalyst.analysis.NoSuchDatabaseException: Database 'test' not found;
  </code></pre>
  
  <p>I have also configured the hive-site.xml file for the Hive warehouse location :</p>
  
  <pre><code>&lt;property&gt;
  &lt;name&gt;hive.metastore.warehouse.dir&lt;/name&gt;
  &lt;value&gt;hdfs://localhost:9000/user/hive/warehouse&lt;/value&gt;
  &lt;/property&gt;
  </code></pre>
  
  <p>I have already created the database 'test' using the Hive console.</p>
  
  <p>Below, the versions of my components :</p>
  
  <ul>
  <li>Spark : 2.2.0</li>
  <li>Hive : 1.1.0</li>
  <li>Hadoop : 2.7.3</li>
  </ul>
  
  <p>Any ideas ?</p>