title: The root scratch dir: /tmp/hive on HDFS should be writable. Current permissions are: rwx--------- (on Linux)
body: <p><strong>The root scratch dir: /tmp/hive on HDFS should be writable. Current permissions are: rwx--------</strong></p>
  
  <p>Hi, The following Spark code i was executing in Eclipse of CDH 5.8 &amp; getting above RuntimeExeption</p>
  
  <pre><code>public static void main(String[] args) {
      final SparkConf sparkConf = new SparkConf().setMaster("local").setAppName("HiveConnector");
      final JavaSparkContext sparkContext = new JavaSparkContext(sparkConf);
      SQLContext sqlContext = new HiveContext(sparkContext);
  
      DataFrame df = sqlContext.sql("SELECT * FROM test_hive_table1");
      //df.show();
      df.count();
   }
  </code></pre>
  
  <p>According to Exception <strong>/tmp/hive on HDFS</strong> should be writable, however we are executing spark job in local mode. That means there is no writable permission to the directory <strong>/tmp/hive</strong> in local (linux) file system, not HDFS.</p>
  
  <p>So I had executed below command to gave permission.</p>
  
  <pre><code>$ sudo chmod -R 777 /tmp/hive
  </code></pre>
  
  <p>Now it is working for me.</p>
  
  <p>If you are getting the same issue during execution of spark job in cluster mode you should configure below property in <strong><em>hive-site.xml</em></strong> file of hive conf folder and restart hive server.</p>
  
  <pre><code>  &lt;property&gt;
      &lt;name&gt;hive.exec.scratchdir&lt;/name&gt;
      &lt;value&gt;/tmp/hive&lt;/value&gt;
      &lt;description&gt;Scratch space for Hive jobs&lt;/description&gt;
    &lt;/property&gt;
    &lt;property&gt;
      &lt;name&gt;hive.scratch.dir.permission&lt;/name&gt;
      &lt;value&gt;777&lt;/value&gt;
      &lt;description&gt;The permission for the user-specific scratch directories that get created in the root scratch directory &lt;/description&gt;
    &lt;/property&gt;
  </code></pre>