<?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: Overwrite to a table taking 12+ hours in Data Engineering</title>
    <link>https://community.databricks.com/t5/data-engineering/overwrite-to-a-table-taking-12-hours/m-p/117216#M45456</link>
    <description>&lt;P&gt;We use Azure Databricks.&lt;/P&gt;</description>
    <pubDate>Wed, 30 Apr 2025 21:03:52 GMT</pubDate>
    <dc:creator>mehalrathod</dc:creator>
    <dc:date>2025-04-30T21:03:52Z</dc:date>
    <item>
      <title>Overwrite to a table taking 12+ hours</title>
      <link>https://community.databricks.com/t5/data-engineering/overwrite-to-a-table-taking-12-hours/m-p/117215#M45455</link>
      <description>&lt;P&gt;&lt;SPAN&gt;One of our Databricks notebook (using python, py-spark) has been running long for 12+ hours specifically on the overwrite command into a table. This notebook along with overwrite step has been completed within 10 mins in the past. But suddenly the overwrite step now takes 12+ hours and eventually times out.&lt;BR /&gt;There were no cluster changes or anything that would make it run this long. I wanted to see if anyone in the community faced anything similar or would be aware of any recent Databricks bugs/issues.&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Wed, 30 Apr 2025 21:01:51 GMT</pubDate>
      <guid>https://community.databricks.com/t5/data-engineering/overwrite-to-a-table-taking-12-hours/m-p/117215#M45455</guid>
      <dc:creator>mehalrathod</dc:creator>
      <dc:date>2025-04-30T21:01:51Z</dc:date>
    </item>
    <item>
      <title>Re: Overwrite to a table taking 12+ hours</title>
      <link>https://community.databricks.com/t5/data-engineering/overwrite-to-a-table-taking-12-hours/m-p/117216#M45456</link>
      <description>&lt;P&gt;We use Azure Databricks.&lt;/P&gt;</description>
      <pubDate>Wed, 30 Apr 2025 21:03:52 GMT</pubDate>
      <guid>https://community.databricks.com/t5/data-engineering/overwrite-to-a-table-taking-12-hours/m-p/117216#M45456</guid>
      <dc:creator>mehalrathod</dc:creator>
      <dc:date>2025-04-30T21:03:52Z</dc:date>
    </item>
    <item>
      <title>Re: Overwrite to a table taking 12+ hours</title>
      <link>https://community.databricks.com/t5/data-engineering/overwrite-to-a-table-taking-12-hours/m-p/117226#M45458</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://community.databricks.com/t5/user/viewprofilepage/user-id/162920"&gt;@mehalrathod&lt;/a&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;This sort of performance regression in Databricks (especially for overwrite) is usually caused by one or more of the following:&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;Common Causes of Overwrite Slowness&lt;/STRONG&gt;&lt;BR /&gt;1. &lt;STRONG&gt;Delta Table History or File Explosion&lt;/STRONG&gt;&lt;BR /&gt;- If the target table is a Delta table, check if the number of files/versions has grown significantly.&lt;BR /&gt;- Over time, Delta tables accumulate many small files, especially if OPTIMIZE and VACUUM haven't been run regularly.&lt;BR /&gt;- Overwrite may trigger file listing, conflict resolution, or transaction logs processing.&lt;/P&gt;&lt;P&gt;Check:&lt;BR /&gt;DESCRIBE HISTORY your_table_name;&lt;/P&gt;&lt;P&gt;Check the number of versions and look for high file count with:&lt;BR /&gt;spark.read.format("delta").load("/mnt/path/to/table").inputFiles().length&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;2. Partition Overwrite Behavior Change&lt;/STRONG&gt;&lt;BR /&gt;- If you are overwriting a partitioned Delta table, and the overwrite mode changed from `dynamic` to `static`, it could result in writing all partitions, not just affected ones.&lt;/P&gt;&lt;P&gt;Confirm mode:&lt;BR /&gt;spark.conf.get("spark.sql.sources.partitionOverwriteMode")&lt;BR /&gt;Should be 'dynamic' for best performance&lt;/P&gt;&lt;P&gt;Set it explicitly:&lt;BR /&gt;spark.conf.set("spark.sql.sources.partitionOverwriteMode", "dynamic")&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;3. Compaction or OPTIMIZE Running Concurrently&lt;/STRONG&gt;&lt;BR /&gt;- Check if any OPTIMIZE or ZORDER operations are running on the table in parallel (scheduled or manual).&lt;BR /&gt;- These operations can lock or block writes and make overwrites crawl or fail.&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;4. Concurrency or Lock Contention&lt;/STRONG&gt;&lt;BR /&gt;Delta Lake uses optimistic concurrency control — if another process is holding the lock or continuously modifying the table, your overwrite may be waiting.&lt;/P&gt;&lt;P&gt;ConcurrentAppendException&lt;BR /&gt;TransactionConflictException&lt;/P&gt;&lt;P&gt;Also check the _delta_log folder size and metadata load time.&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;5. Table Metadata or Schema Drift&lt;/STRONG&gt;&lt;BR /&gt;Large schema evolution, column reorderings, or misalignment between the DF schema and table schema can cause Spark to do heavy metadata planning and validation, which adds time.&lt;/P&gt;&lt;P&gt;Check if the dataframe schema has recently changed subtly (e.g., column types, order, nullability).&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;Quick Diagnostic Tips&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;1. Enable Spark UI and Logs Analysis: Look at Stage Details and Job DAG during the overwrite. Often, the issue is in a shuffle or file-level metadata operation.&lt;BR /&gt;2. Reproduce the Write on a Smaller Subset:&lt;BR /&gt;- Try .limit(10000) and overwrite to same table — does it still take long?&lt;BR /&gt;3. Try Write to a Temp Table:&lt;BR /&gt;- Same data, write to a new path/table → Is performance OK?&lt;BR /&gt;- If yes, the issue is with the target Delta table, not the data or compute.&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;Workarounds &amp;amp; Fixes:&lt;/STRONG&gt;&lt;BR /&gt;- Run VACUUM and OPTIMIZE on the table periodically.&lt;BR /&gt;- Repartition the DF before write to avoid file explosion:&lt;BR /&gt;df.repartition(200).write.mode("overwrite").format("delta").saveAsTable("...")&lt;BR /&gt;- Try replacing `.saveAsTable()` with direct path write if using external tables.&lt;BR /&gt;- Upgrade Runtime if you're on an older DBR version — file I/O and Delta writers are optimized in newer runtimes.&lt;/P&gt;</description>
      <pubDate>Wed, 30 Apr 2025 23:16:44 GMT</pubDate>
      <guid>https://community.databricks.com/t5/data-engineering/overwrite-to-a-table-taking-12-hours/m-p/117226#M45458</guid>
      <dc:creator>lingareddy_Alva</dc:creator>
      <dc:date>2025-04-30T23:16:44Z</dc:date>
    </item>
  </channel>
</rss>

