title: Spark create or replace temp view not updating existing table multiple times
body: <p><strong>Step-1</strong><br>
  I need to compare two csv files reaptedly while one being static (<code>DB.csv</code>)  and other is downloaded from web <code>Downloaded.csv</code> (which is dynamic,may be updated records )  </p>
  
  <p><strong>Step-2</strong><br>
  After comparing the difference from both two csv,will be writen to mongodb  </p>
  
  <p><strong>Step-3</strong><br>
  Now <code>Downloaded.csv</code> file need to replace <code>DB.csv</code>, then same logic from step-1 will continue.</p>
  
  <blockquote>
    <p><strong>Sample explanation</strong></p>
  </blockquote>
  
  <p><em>Step-1</em></p>
  
  <pre><code>DB.csv   [temp table `db` ]
  
  sno APPLE   BANANA
  1   13  11
  2   2   22
  3   2   22
  
  Downloaded.csv [temp table `downloaded` ]
  sno APPLE   BANANA
  1   n   11
  2   2   22
  3   2   22
  </code></pre>
  
  <p><em>Step-2</em></p>
  
  <pre><code>Difference dataset
  sno APPLE   BANANA
  1     n       11
  </code></pre>
  
  <p><em>Step-3</em></p>
  
  <pre><code>DB.csv [temp table `db` - updated ]
  sno APPLE   BANANA
   1  n   11
   2  2   22
   3  2   22
  </code></pre>
  
  <p><strong>Repeating</strong> <em>Step-1</em>  </p>
  
  <pre><code>DB.csv [temp table `db` - updated ]
  sno APPLE   BANANA
   1  n   11
   2  2   22
   3  2   22
  
  Downloaded.csv [temp table `downloaded` - new downloaded record ]
  sno APPLE   BANANA
  1   n   11
  2   2   n
  3   2   22
  </code></pre>
  
  <p><strong>Repeating</strong> <em>Step-2</em>   </p>
  
  <pre><code>Difference dataset
  sno APPLE   BANANA
  2     2       n  
  </code></pre>
  
  <p><strong>Repeating</strong> <em>Step-3</em>   </p>
  
  <pre><code>DB.csv [temp table `db` ]
  sno APPLE   BANANA
   1  n   11
   2  2   n
   3  2   22
  </code></pre>
  
  <blockquote>
    <p><strong>Here is my logic</strong></p>
  </blockquote>
  
  <pre><code> Dataset&lt;Row&gt; downloaded =spark.read().option("header","true").csv("/home/exa4/Desktop/downloaded.csv");
       Dataset&lt;Row&gt; db =spark.read().option("header","true").csv("/home/exa4/Desktop/db.csv");
       downloaded.createOrReplaceTempView("downloaded");
       db.createOrReplaceTempView("db");
  
       Dataset&lt;Row&gt; diffs= spark.sql("select * from downloaded EXCEPT select * from db");
  
      //write updates to collection
      MongoSpark.save(diffs.write().option("collection", "UpdatedRecords").mode("overwrite"));
  
      //replacing old DB with new dataset downloaded 
      downloaded.createOrReplaceTempView("db");
  
       ////For every 10 seconds I may intenstionaly change the downloaded.csv for testing , as it is dynamic dataset 
       while(true){
           long start = System.currentTimeMillis();
              Thread.sleep(10000);
  
               //this will be newly downloaded file from net 
               Dataset&lt;Row&gt; downloaded =spark.read().option("header","true").csv("/home/exa4/Desktop/downloaded.csv");
               downloaded.createOrReplaceTempView("downloaded");
  
              //now comparing downloaded with previously updated dataset 
              Dataset&lt;Row&gt; diffs_= spark.sql("select * from downloaded EXCEPT select * from db");
              diffs_.show();
               ////HERE I AM GETTING NULL RECORDS 
  
              downloaded.createOrReplaceTempView("db");
  
       }
  </code></pre>