<?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 Re: Liquid Clustering - Implementing with Spark Streaming’s foreachBatch Upsert in Data Engineering</title>
    <link>https://community.databricks.com/t5/data-engineering/liquid-clustering-implementing-with-spark-streaming-s/m-p/103273#M41392</link>
    <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://community.databricks.com/t5/user/viewprofilepage/user-id/137921"&gt;@theron&lt;/a&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;If you have enabled LC while table creation, you must have already specified the cluster column. Thus I don't see a reason to mention&amp;nbsp;&lt;SPAN&gt; .&lt;/SPAN&gt;&lt;FONT color="#FF0000"&gt;&lt;STRONG&gt;clusterBy(key)&amp;nbsp;&lt;/STRONG&gt;&lt;/FONT&gt;&lt;FONT color="#000000"&gt;again.&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#000000"&gt;Let me know if any questions&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#000000"&gt;Cheers!&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#000000"&gt;If you want to create a brand new table with LC enabled or enable LC while writing to that table use the .clusterBy(key) method.&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#000000"&gt;&lt;STRONG&gt;OPTIMIZE FULL&amp;nbsp;&lt;/STRONG&gt;should only be ran if you change the cluster keys or enabling clustering for the first time on a delta table. If you run &lt;STRONG&gt;OPTIMIZE FULL&lt;/STRONG&gt;&amp;nbsp;regularly, it's same as running OPTIMIZE.&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#FF6600"&gt;&lt;FONT color="#000000"&gt;Usually, &lt;A href="https://docs.databricks.com/en/optimizations/predictive-optimization.html" target="_self"&gt;predictive&amp;nbsp;&lt;/A&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT color="#000000"&gt;&lt;A href="https://docs.databricks.com/en/optimizations/predictive-optimization.html" target="_self"&gt;optimization&lt;/A&gt;&amp;nbsp;&lt;SPAN&gt;automatically runs &lt;/SPAN&gt;&lt;/FONT&gt;&lt;FONT color="#FF6600"&gt;OPTIMIZE&lt;/FONT&gt;&lt;FONT color="#000000"&gt;&lt;SPAN&gt; commands for all LC enabled tables. To trigger it manually, you can run the OPTIMIZE command explicitly.&lt;/SPAN&gt;&lt;/FONT&gt;&lt;/P&gt;</description>
    <pubDate>Fri, 27 Dec 2024 03:06:35 GMT</pubDate>
    <dc:creator>RiyazAliM</dc:creator>
    <dc:date>2024-12-27T03:06:35Z</dc:date>
    <item>
      <title>Liquid Clustering - Implementing with Spark Streaming’s foreachBatch Upsert</title>
      <link>https://community.databricks.com/t5/data-engineering/liquid-clustering-implementing-with-spark-streaming-s/m-p/103243#M41376</link>
      <description>&lt;P&gt;Hi there!&lt;/P&gt;&lt;P&gt;I’d like to use Liquid Clustering in a Spark Streaming process with &lt;STRONG&gt;&lt;FONT color="#FF0000"&gt;foreachBatch(upsert)&lt;/FONT&gt;&lt;/STRONG&gt;. However, I’m not sure of the correct approach.&lt;/P&gt;&lt;P&gt;The Databricks documentation suggests using .&lt;FONT color="#FF0000"&gt;&lt;STRONG&gt;clusterBy(key)&lt;/STRONG&gt;&lt;/FONT&gt; when writing streaming data. In my case, I'm using foreachBatch with a SQL query that performs a MERGE by a specific key or inserts all records if they don’t match.&lt;/P&gt;&lt;P&gt;Now that the table has been created with Liquid Clustering enabled, what is the right way to set this up? Should I use:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;DIV class=""&gt;&lt;DIV class=""&gt;&lt;DIV class=""&gt;&lt;DIV class=""&gt;&amp;nbsp;&lt;/DIV&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;PRE&gt;df&lt;SPAN class=""&gt;.writeStream&lt;/SPAN&gt;&lt;SPAN class=""&gt;.clusterBy&lt;/SPAN&gt;(key)&lt;SPAN class=""&gt;.foreachBatch&lt;/SPAN&gt;(upsert_method)&lt;/PRE&gt;&lt;/DIV&gt;&lt;P&gt;Or just:&lt;/P&gt;&lt;DIV class=""&gt;&lt;PRE&gt;df&lt;SPAN class=""&gt;.writeStream.&lt;/SPAN&gt;&lt;SPAN class=""&gt;foreachBatch&lt;/SPAN&gt;(upsert_method)&lt;/PRE&gt;&lt;/DIV&gt;&lt;P&gt;Also, do I need to run &lt;FONT color="#FF0000"&gt;&lt;STRONG&gt;OPTIMIZE FULL&lt;/STRONG&gt;&lt;/FONT&gt; frequently, or is it run automatically during the streaming process?&lt;/P&gt;&lt;P&gt;I’m currently using Liquid Clustering with Spark Streaming and the &lt;FONT color="#FF0000"&gt;&lt;STRONG&gt;foreachBatch&lt;/STRONG&gt;&lt;/FONT&gt; clause, but I'm unsure how exactly to apply &lt;FONT color="#FF0000"&gt;&lt;STRONG&gt;clusterBy(key)&lt;/STRONG&gt;&lt;/FONT&gt;. I saw some references in the documentation, but it's still not clear.&lt;/P&gt;</description>
      <pubDate>Thu, 26 Dec 2024 15:55:31 GMT</pubDate>
      <guid>https://community.databricks.com/t5/data-engineering/liquid-clustering-implementing-with-spark-streaming-s/m-p/103243#M41376</guid>
      <dc:creator>theron</dc:creator>
      <dc:date>2024-12-26T15:55:31Z</dc:date>
    </item>
    <item>
      <title>Re: Liquid Clustering - Implementing with Spark Streaming’s foreachBatch Upsert</title>
      <link>https://community.databricks.com/t5/data-engineering/liquid-clustering-implementing-with-spark-streaming-s/m-p/103273#M41392</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://community.databricks.com/t5/user/viewprofilepage/user-id/137921"&gt;@theron&lt;/a&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;If you have enabled LC while table creation, you must have already specified the cluster column. Thus I don't see a reason to mention&amp;nbsp;&lt;SPAN&gt; .&lt;/SPAN&gt;&lt;FONT color="#FF0000"&gt;&lt;STRONG&gt;clusterBy(key)&amp;nbsp;&lt;/STRONG&gt;&lt;/FONT&gt;&lt;FONT color="#000000"&gt;again.&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#000000"&gt;Let me know if any questions&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#000000"&gt;Cheers!&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#000000"&gt;If you want to create a brand new table with LC enabled or enable LC while writing to that table use the .clusterBy(key) method.&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#000000"&gt;&lt;STRONG&gt;OPTIMIZE FULL&amp;nbsp;&lt;/STRONG&gt;should only be ran if you change the cluster keys or enabling clustering for the first time on a delta table. If you run &lt;STRONG&gt;OPTIMIZE FULL&lt;/STRONG&gt;&amp;nbsp;regularly, it's same as running OPTIMIZE.&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#FF6600"&gt;&lt;FONT color="#000000"&gt;Usually, &lt;A href="https://docs.databricks.com/en/optimizations/predictive-optimization.html" target="_self"&gt;predictive&amp;nbsp;&lt;/A&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT color="#000000"&gt;&lt;A href="https://docs.databricks.com/en/optimizations/predictive-optimization.html" target="_self"&gt;optimization&lt;/A&gt;&amp;nbsp;&lt;SPAN&gt;automatically runs &lt;/SPAN&gt;&lt;/FONT&gt;&lt;FONT color="#FF6600"&gt;OPTIMIZE&lt;/FONT&gt;&lt;FONT color="#000000"&gt;&lt;SPAN&gt; commands for all LC enabled tables. To trigger it manually, you can run the OPTIMIZE command explicitly.&lt;/SPAN&gt;&lt;/FONT&gt;&lt;/P&gt;</description>
      <pubDate>Fri, 27 Dec 2024 03:06:35 GMT</pubDate>
      <guid>https://community.databricks.com/t5/data-engineering/liquid-clustering-implementing-with-spark-streaming-s/m-p/103273#M41392</guid>
      <dc:creator>RiyazAliM</dc:creator>
      <dc:date>2024-12-27T03:06:35Z</dc:date>
    </item>
  </channel>
</rss>

