title: When to execute REFRESH TABLE my_table in spark?
body: <p>Consider a code;</p>
  
  <pre><code> import org.apache.spark.sql.hive.orc._
   import org.apache.spark.sql._
  
   val path = ...
   val dataFrame:DataFramew = ...
  
   val hiveContext = new org.apache.spark.sql.hive.HiveContext(sparkContext)
   dataFrame.createOrReplaceTempView("my_table")
   val results = hiveContext.sql(s"select * from my_table")
   results.write.mode(SaveMode.Append).partitionBy("my_column").format("orc").save(path)
   hiveContext.sql("REFRESH TABLE my_table")
  </code></pre>
  
  <p>This code is executed twice with same path but different dataFrames. The first run is successful, but subsequent rise en error:</p>
  
  <pre><code>Caused by: java.io.FileNotFoundException: File does not exist: hdfs://somepath/somefile.snappy.orc
  It is possible the underlying files have been updated. You can explicitly invalidate the cache in Spark by running 'REFRESH TABLE tableName' command in SQL or by recreating the Dataset/DataFrame involved.
  </code></pre>
  
  <p>I have tried to clean up cache, invoke <code>hiveContext.dropTempTable("tableName")</code> and all have no effect. When to call <code>REFRESH TABLE tableName</code> before, after (other variants) to repair such error?</p>