<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>question Re: df.cache() is not working on jdbc table in Archives of Support Questions (Read Only)</title>
    <link>https://community.cloudera.com/t5/Archives-of-Support-Questions/df-cache-is-not-working-on-jdbc-table/m-p/193000#M80863</link>
    <description>&lt;P&gt; &lt;A rel="user" href="https://community.cloudera.com/users/48475/papilpatil15.html" nodeid="48475"&gt;@Papil Patil&lt;/A&gt;&lt;/P&gt;&lt;P&gt;cache function is lazy, so in order to see the data cached you should actually perform an action that would trigger the execution of the dag. For example:&lt;/P&gt;&lt;PRE&gt;df = spark.read
	.format("jdbc")\
	.option("url","---------------------------")\
	.option("driver","com.sap.db.jdbc.Driver")
	.option("CharSet","iso_1")\
	.option("user","---------------------------")\
	.option("password", "---------------------------")\
	.option("dbtable","(select * from schema.table_name ) tmp ")\
	.load()
df.cache()
//this will trigger the dag and you should see data cache 
val count = df.count()
//next time it will just use the data in cache so it should be faster to execute
val count2 = df.count()

&lt;/PRE&gt;&lt;P&gt;HTH&lt;/P&gt;&lt;P&gt;*** If you found this answer addressed your question, please take a moment to login and click the "accept" link on the answer.&lt;/P&gt;</description>
    <pubDate>Thu, 19 Jul 2018 20:45:25 GMT</pubDate>
    <dc:creator>falbani</dc:creator>
    <dc:date>2018-07-19T20:45:25Z</dc:date>
    <item>
      <title>df.cache() is not working on jdbc table</title>
      <link>https://community.cloudera.com/t5/Archives-of-Support-Questions/df-cache-is-not-working-on-jdbc-table/m-p/192998#M80861</link>
      <description>&lt;P&gt;I am creating a dataframe using pyspark sql jdbc.read(). I want to cache the data read from jdbc table into a df to use it further in joins and agg. By using df.cache() I cannot see any query in rdbms executed for reading data unless I do df.show(). It means that data is not cached yet. Whenever I am using this cached df in further joins and unions, each time a SELECT is executed in rdbms which is not expected and needs to be reduced.&lt;/P&gt;&lt;P&gt;What could be the possible reason for this behaviour. Is there any other way to cache data in df ?&lt;/P&gt;&lt;PRE&gt;df = spark.read
	.format("jdbc")\
	.option("url","---------------------------")\
	.option("driver","com.sap.db.jdbc.Driver")
	.option("CharSet","iso_1")\
	.option("user","---------------------------")\
	.option("password", "---------------------------")\
	.option("dbtable","(select * from schema.table_name ) tmp ")\
	.load()
df.cache()&lt;/PRE&gt;&lt;P style="margin-left: 20px;"&gt;&lt;/P&gt;</description>
      <pubDate>Wed, 18 Jul 2018 15:08:27 GMT</pubDate>
      <guid>https://community.cloudera.com/t5/Archives-of-Support-Questions/df-cache-is-not-working-on-jdbc-table/m-p/192998#M80861</guid>
      <dc:creator>papil_patil15</dc:creator>
      <dc:date>2018-07-18T15:08:27Z</dc:date>
    </item>
    <item>
      <title>Re: df.cache() is not working on jdbc table</title>
      <link>https://community.cloudera.com/t5/Archives-of-Support-Questions/df-cache-is-not-working-on-jdbc-table/m-p/192999#M80862</link>
      <description>&lt;P&gt; You are experiencing sparks lazy execution.  When you execute your code, nothing in spark has been executed.  You need to cache post execution.  For example, a easy way to fix/test this is to run a something against your DF... (ie select * from df).  store the results in a another DF and cache it thereafter.&lt;/P&gt;</description>
      <pubDate>Thu, 19 Jul 2018 19:52:04 GMT</pubDate>
      <guid>https://community.cloudera.com/t5/Archives-of-Support-Questions/df-cache-is-not-working-on-jdbc-table/m-p/192999#M80862</guid>
      <dc:creator>sunile_manjee</dc:creator>
      <dc:date>2018-07-19T19:52:04Z</dc:date>
    </item>
    <item>
      <title>Re: df.cache() is not working on jdbc table</title>
      <link>https://community.cloudera.com/t5/Archives-of-Support-Questions/df-cache-is-not-working-on-jdbc-table/m-p/193000#M80863</link>
      <description>&lt;P&gt; &lt;A rel="user" href="https://community.cloudera.com/users/48475/papilpatil15.html" nodeid="48475"&gt;@Papil Patil&lt;/A&gt;&lt;/P&gt;&lt;P&gt;cache function is lazy, so in order to see the data cached you should actually perform an action that would trigger the execution of the dag. For example:&lt;/P&gt;&lt;PRE&gt;df = spark.read
	.format("jdbc")\
	.option("url","---------------------------")\
	.option("driver","com.sap.db.jdbc.Driver")
	.option("CharSet","iso_1")\
	.option("user","---------------------------")\
	.option("password", "---------------------------")\
	.option("dbtable","(select * from schema.table_name ) tmp ")\
	.load()
df.cache()
//this will trigger the dag and you should see data cache 
val count = df.count()
//next time it will just use the data in cache so it should be faster to execute
val count2 = df.count()

&lt;/PRE&gt;&lt;P&gt;HTH&lt;/P&gt;&lt;P&gt;*** If you found this answer addressed your question, please take a moment to login and click the "accept" link on the answer.&lt;/P&gt;</description>
      <pubDate>Thu, 19 Jul 2018 20:45:25 GMT</pubDate>
      <guid>https://community.cloudera.com/t5/Archives-of-Support-Questions/df-cache-is-not-working-on-jdbc-table/m-p/193000#M80863</guid>
      <dc:creator>falbani</dc:creator>
      <dc:date>2018-07-19T20:45:25Z</dc:date>
    </item>
  </channel>
</rss>

