<?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>topic How can I force a data frame to evaluate without saving it? in Data Engineering</title>
    <link>https://community.databricks.com/t5/data-engineering/how-can-i-force-a-data-frame-to-evaluate-without-saving-it/m-p/100671#M40375</link>
    <description>&lt;P&gt;The problem in my hand requires me to take a set of actions on a very large data frame &lt;EM&gt;df_1&lt;/EM&gt;. This set of actions results in a second data frame &lt;EM&gt;df_2&lt;/EM&gt;, and from this second data frame, I have multiple downstream tasks, &lt;EM&gt;task_1, task_2 ...&amp;nbsp;&lt;/EM&gt;&amp;nbsp;By default, these tasks will repeat the computation between &lt;EM&gt;df_1&lt;/EM&gt; and &lt;EM&gt;df_2.&amp;nbsp;&lt;/EM&gt;Is there a way to force evaluation at &lt;EM&gt;df_2 &lt;/EM&gt;so that I don't need to repeat the same costly calculations again and again. I know I could save &lt;EM&gt;df_2 &lt;/EM&gt;to force the evaluation, but wonder if there is another way to avoid writing and reading? Thanks!&lt;/P&gt;</description>
    <pubDate>Mon, 02 Dec 2024 23:36:52 GMT</pubDate>
    <dc:creator>100databricks</dc:creator>
    <dc:date>2024-12-02T23:36:52Z</dc:date>
    <item>
      <title>How can I force a data frame to evaluate without saving it?</title>
      <link>https://community.databricks.com/t5/data-engineering/how-can-i-force-a-data-frame-to-evaluate-without-saving-it/m-p/100671#M40375</link>
      <description>&lt;P&gt;The problem in my hand requires me to take a set of actions on a very large data frame &lt;EM&gt;df_1&lt;/EM&gt;. This set of actions results in a second data frame &lt;EM&gt;df_2&lt;/EM&gt;, and from this second data frame, I have multiple downstream tasks, &lt;EM&gt;task_1, task_2 ...&amp;nbsp;&lt;/EM&gt;&amp;nbsp;By default, these tasks will repeat the computation between &lt;EM&gt;df_1&lt;/EM&gt; and &lt;EM&gt;df_2.&amp;nbsp;&lt;/EM&gt;Is there a way to force evaluation at &lt;EM&gt;df_2 &lt;/EM&gt;so that I don't need to repeat the same costly calculations again and again. I know I could save &lt;EM&gt;df_2 &lt;/EM&gt;to force the evaluation, but wonder if there is another way to avoid writing and reading? Thanks!&lt;/P&gt;</description>
      <pubDate>Mon, 02 Dec 2024 23:36:52 GMT</pubDate>
      <guid>https://community.databricks.com/t5/data-engineering/how-can-i-force-a-data-frame-to-evaluate-without-saving-it/m-p/100671#M40375</guid>
      <dc:creator>100databricks</dc:creator>
      <dc:date>2024-12-02T23:36:52Z</dc:date>
    </item>
    <item>
      <title>Re: How can I force a data frame to evaluate without saving it?</title>
      <link>https://community.databricks.com/t5/data-engineering/how-can-i-force-a-data-frame-to-evaluate-without-saving-it/m-p/100710#M40387</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://community.databricks.com/t5/user/viewprofilepage/user-id/131072"&gt;@100databricks&lt;/a&gt;,&lt;/P&gt;&lt;P&gt;Hi, yes, you can run df_2.cache() or df_2.persist()&lt;/P&gt;&lt;P&gt;(df_2.cache() is a shortcut for&amp;nbsp;&lt;SPAN&gt;df_2.&lt;/SPAN&gt;&lt;SPAN&gt;persist&lt;/SPAN&gt;&lt;SPAN&gt;(StorageLevel.&lt;SPAN&gt;MEMORY_ONLY&lt;/SPAN&gt;)&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;Here is the pseudo-code:&lt;/P&gt;&lt;LI-CODE lang="python"&gt;# df_1 is your large initial DataFrame
df_1 = ...

# Perform expensive transformations to get df_2
df_2 = df_1.filter(...).join(...).groupBy(...).agg(...)

# Cache df_2
df_2.persist(StorageLevel.MEMORY_AND_DISK)

# Now use df_2 in multiple tasks
result_task_1 = df_2.select(...).where(...).collect()
result_task_2 = df_2.groupBy(...).sum().show()&lt;/LI-CODE&gt;</description>
      <pubDate>Tue, 03 Dec 2024 07:55:22 GMT</pubDate>
      <guid>https://community.databricks.com/t5/data-engineering/how-can-i-force-a-data-frame-to-evaluate-without-saving-it/m-p/100710#M40387</guid>
      <dc:creator>filipniziol</dc:creator>
      <dc:date>2024-12-03T07:55:22Z</dc:date>
    </item>
    <item>
      <title>Re: How can I force a data frame to evaluate without saving it?</title>
      <link>https://community.databricks.com/t5/data-engineering/how-can-i-force-a-data-frame-to-evaluate-without-saving-it/m-p/100815#M40430</link>
      <description>&lt;P&gt;Thank you! This is exactly what I need.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 03 Dec 2024 18:25:09 GMT</pubDate>
      <guid>https://community.databricks.com/t5/data-engineering/how-can-i-force-a-data-frame-to-evaluate-without-saving-it/m-p/100815#M40430</guid>
      <dc:creator>100databricks</dc:creator>
      <dc:date>2024-12-03T18:25:09Z</dc:date>
    </item>
  </channel>
</rss>

