title: Apache Spark JDBC DataFrame count issue
body: <p>I am using Spark JDBC to read data from MS SQL database, but I am getting some weird results.</p>
  
  <p>For example, below is my code  to read records from my MS SQL database.
  Please note the tables from which I am reading data is continuously getting inserted with records.</p>
  
  <pre><code> //Extract Data from JDBC source
      val jdbcTable = sqlContext.read.format("jdbc").options(
        Map(
          "url" -&gt; jdcbUrl,
          "driver" -&gt; "net.sourceforge.jtds.jdbc.Driver",
          "dbtable" -&gt;
            s"(SELECT COLUMNS WITH INNER JOINS WHERE tbl.ID &gt; ${lastExtractUnixTime}) as t"))
         .load
  
       println(s"STEP 1] JDBC RECORDS COUNTS ---&gt; ${jdbcTable.count()}")
  
      val updateJdbcDF = jdbcTable
        .withColumn("ID-COL1", trim($"COl1"))
        .withColumn("ID-COL1", trim($"COl2"))
  
     println(s"STEP 2] UPDATE JDBC RECORDS COUNTS ---&gt; ${updateJdbcDF.count()}")
  </code></pre>
  
  <p>I get 2 different count values each time I run my program, for example I always get <code>${updateJdbcDF.count()}</code> count >  <code>${jdbcTable.count()}</code>.</p>
  
  <p>Can somebody explain me why is this happening? This is creating a lot of issues in my use case.  How to restrict count of <code>jdbcTable</code> DataFrame after it is created. I tried <code>jdbcTable.cache()</code> but no luck.</p>
  
  <p>The records just gets  bigger and bigger when I use any operation on other dataframe derived from <code>jdbcTable</code> DataFrame. Does <code>jdbcTable</code> dataframe call every time I use any dataframe derived from <code>jdbcTable</code> dataframe.</p>