<?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: Databricks SDP (Spark declarative Pipelins) Overwrite table in Data Engineering</title>
    <link>https://community.databricks.com/t5/data-engineering/databricks-sdp-spark-declarative-pipelins-overwrite-table/m-p/170660#M56332</link>
    <description>&lt;P data-pm-slice="1 1 []"&gt;If each file is a full snapshot, use AUTO CDC FROM SNAPSHOT with SCD Type 1; it processes files in numeric order and makes the target match the latest snapshot, including deleting absent keys (&lt;A href="https://docs.databricks.com/aws/en/ldp/cdc#example-process-snapshots-using-version-functions" target="_blank"&gt;version-function example&lt;/A&gt;, &lt;A href="https://docs.databricks.com/aws/en/ldp/developer/ldp-python-ref-apply-changes-from-snapshot" target="_blank"&gt;snapshot API&lt;/A&gt;). Use this code in place of the current &lt;CODE&gt;orders&lt;/CODE&gt; definition:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class="language-python"&gt;import re

from pyspark import pipelines as dp

ORDERS_DIR = "/Volumes/&amp;lt;catalog&amp;gt;/&amp;lt;schema&amp;gt;/&amp;lt;volume&amp;gt;/orders/"


def next_snapshot_and_version(latest_version):
    versions = sorted(
        int(m.group(1))
        for f in dbutils.fs.ls(ORDERS_DIR)
        if (m := re.fullmatch(r"orders_(\d+)\.csv", f.name))
    )
    newer = [v for v in versions if latest_version is None or v &amp;gt; latest_version]
    if not newer:
        return None
    df = spark.read.format("csv").option("header", True).load(f"{ORDERS_DIR}orders_{newer[0]}.csv")
    return df, newer[0]


dp.create_streaming_table("orders")
dp.create_auto_cdc_from_snapshot_flow(
    target="orders",
    source=next_snapshot_and_version,
    keys=["order_id"],
    stored_as_scd_type=1,
)&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Set &lt;CODE&gt;keys&lt;/CODE&gt; to the column or columns that uniquely identify a row (&lt;A href="https://docs.databricks.com/aws/en/ldp/developer/ldp-python-ref-apply-changes-from-snapshot" target="_blank"&gt;snapshot API&lt;/A&gt;). Without &lt;CODE&gt;.schema(...)&lt;/CODE&gt;, this CSV read returns every column as a string; add the schema before &lt;CODE&gt;.load(...)&lt;/CODE&gt; for typed columns (&lt;A href="https://spark.apache.org/docs/latest/sql-data-sources-csv.html#data-source-option" target="_blank"&gt;CSV options&lt;/A&gt;, &lt;A href="https://docs.databricks.com/aws/en/query/formats/csv#specify-a-schema" target="_blank"&gt;specify a schema&lt;/A&gt;). The flow requires serverless or the Pro or Advanced edition (&lt;A href="https://docs.databricks.com/aws/en/ldp/cdc#requirements" target="_blank"&gt;requirements&lt;/A&gt;). For an existing streaming table, switch the code, then run a full refresh of only &lt;CODE&gt;orders&lt;/CODE&gt;; for an existing materialized view, switch the code, run &lt;CODE&gt;&lt;A href="https://docs.databricks.com/aws/en/sql/language-manual/sql-ref-syntax-ddl-drop-view" target="_self"&gt;DROP MATERIALIZED VIEW&lt;/A&gt;&lt;/CODE&gt;, then run the same full refresh (&lt;A href="https://docs.databricks.com/aws/en/error-messages/error-classes#cannot_change_dataset_type" target="_blank"&gt;type-change guidance&lt;/A&gt;, &lt;A href="https://docs.databricks.com/aws/en/ldp/multi-file-editor#run-pipeline-code" target="_blank"&gt;full-refresh action&lt;/A&gt;).&lt;/P&gt;</description>
    <pubDate>Mon, 05 Oct 2026 17:28:15 GMT</pubDate>
    <dc:creator>AbhilashNagilla</dc:creator>
    <dc:date>2026-10-05T17:28:15Z</dc:date>
    <item>
      <title>Databricks SDP (Spark declarative Pipelins) Overwrite table</title>
      <link>https://community.databricks.com/t5/data-engineering/databricks-sdp-spark-declarative-pipelins-overwrite-table/m-p/170550#M56316</link>
      <description>&lt;DIV&gt;1) Consider I have orders folder which orders_1.csv file&amp;nbsp; and it is loaded to orders tables&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;orders/&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;============&amp;gt; load to order table&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;orders_1.csv&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;2)&amp;nbsp;&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;next day new file (orders_2.csv) arrived&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;orders/&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;=========&amp;gt; take only 2nd file -----&amp;gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;overwrite the order table&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;orders_1.csv&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; orders_2.csv&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;Here streaming table only appending the data to orders table.&amp;nbsp; Materialized view is considering both files. &lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;My requirement is overwrite the orders table.&amp;nbsp;&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;Can you help me how to do that ??&amp;nbsp;&lt;/SPAN&gt;&lt;/DIV&gt;</description>
      <pubDate>Sun, 04 Oct 2026 15:21:10 GMT</pubDate>
      <guid>https://community.databricks.com/t5/data-engineering/databricks-sdp-spark-declarative-pipelins-overwrite-table/m-p/170550#M56316</guid>
      <dc:creator>pvrcloudtech</dc:creator>
      <dc:date>2026-10-04T15:21:10Z</dc:date>
    </item>
    <item>
      <title>Re: Databricks SDP (Spark declarative Pipelins) Overwrite table</title>
      <link>https://community.databricks.com/t5/data-engineering/databricks-sdp-spark-declarative-pipelins-overwrite-table/m-p/170552#M56317</link>
      <description>&lt;P&gt;Streaming tables are append-only by design, so they can't overwrite. Use a materialized view that keeps only the rows from the newest file, via the _metadata column:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;sql&lt;/P&gt;&lt;P&gt;CREATE OR REFRESH MATERIALIZED VIEW orders AS&lt;/P&gt;&lt;P&gt;SELECT * EXCEPT (file_time)&lt;/P&gt;&lt;P&gt;FROM (&lt;/P&gt;&lt;P&gt;&amp;nbsp; SELECT *,&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;_metadata.file_modification_time AS file_time&lt;/P&gt;&lt;P&gt;&amp;nbsp; FROM read_files('/path/orders/', format =&amp;gt; 'csv', header =&amp;gt; true)&lt;/P&gt;&lt;P&gt;)&lt;/P&gt;&lt;P&gt;QUALIFY file_time = MAX(file_time) OVER ();&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Each refresh then replaces the table contents with only the latest file (orders_2.csv, then orders_3.csv, and so on).&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;If the folder grows large, ingest with a streaming table (Auto Loader) into a bronze table, storing _metadata.file_name and _metadata.file_modification_time as columns, and build the same "latest file only" materialized view on top of it. That way all the files aren't re-read on every refresh.&lt;/P&gt;&lt;P&gt;Hope this helps&lt;/P&gt;</description>
      <pubDate>Sun, 04 Oct 2026 16:16:50 GMT</pubDate>
      <guid>https://community.databricks.com/t5/data-engineering/databricks-sdp-spark-declarative-pipelins-overwrite-table/m-p/170552#M56317</guid>
      <dc:creator>SumeshKashyap</dc:creator>
      <dc:date>2026-10-04T16:16:50Z</dc:date>
    </item>
    <item>
      <title>Re: Databricks SDP (Spark declarative Pipelins) Overwrite table</title>
      <link>https://community.databricks.com/t5/data-engineering/databricks-sdp-spark-declarative-pipelins-overwrite-table/m-p/170554#M56318</link>
      <description>&lt;P&gt;A Streaming Table may not be the right fit for this requirement. It is designed to process new files incrementally, so when &lt;STRONG&gt;orders2.csv&amp;nbsp;&lt;/STRONG&gt;arrives, it will append the new data.&lt;/P&gt;&lt;P&gt;If each new file is a full snapshot and should completely replace the previous data, you can use a batch job to read only the latest file and overwrite the target Delta table using:&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;df.write.mode("overwrite").saveAsTable("orders")&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;Another option is to keep only the latest file in a&amp;nbsp; &lt;STRONG&gt;current&lt;/STRONG&gt;/ folder and move older files to an &lt;STRONG&gt;archive&lt;/STRONG&gt;/ folder.&lt;/P&gt;&lt;P&gt;So in this case, I would prefer a batch overwrite approach rather than a Streaming Table.&lt;/P&gt;</description>
      <pubDate>Sun, 04 Oct 2026 16:25:25 GMT</pubDate>
      <guid>https://community.databricks.com/t5/data-engineering/databricks-sdp-spark-declarative-pipelins-overwrite-table/m-p/170554#M56318</guid>
      <dc:creator>VK210287</dc:creator>
      <dc:date>2026-10-04T16:25:25Z</dc:date>
    </item>
    <item>
      <title>Re: Databricks SDP (Spark declarative Pipelins) Overwrite table</title>
      <link>https://community.databricks.com/t5/data-engineering/databricks-sdp-spark-declarative-pipelins-overwrite-table/m-p/170660#M56332</link>
      <description>&lt;P data-pm-slice="1 1 []"&gt;If each file is a full snapshot, use AUTO CDC FROM SNAPSHOT with SCD Type 1; it processes files in numeric order and makes the target match the latest snapshot, including deleting absent keys (&lt;A href="https://docs.databricks.com/aws/en/ldp/cdc#example-process-snapshots-using-version-functions" target="_blank"&gt;version-function example&lt;/A&gt;, &lt;A href="https://docs.databricks.com/aws/en/ldp/developer/ldp-python-ref-apply-changes-from-snapshot" target="_blank"&gt;snapshot API&lt;/A&gt;). Use this code in place of the current &lt;CODE&gt;orders&lt;/CODE&gt; definition:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class="language-python"&gt;import re

from pyspark import pipelines as dp

ORDERS_DIR = "/Volumes/&amp;lt;catalog&amp;gt;/&amp;lt;schema&amp;gt;/&amp;lt;volume&amp;gt;/orders/"


def next_snapshot_and_version(latest_version):
    versions = sorted(
        int(m.group(1))
        for f in dbutils.fs.ls(ORDERS_DIR)
        if (m := re.fullmatch(r"orders_(\d+)\.csv", f.name))
    )
    newer = [v for v in versions if latest_version is None or v &amp;gt; latest_version]
    if not newer:
        return None
    df = spark.read.format("csv").option("header", True).load(f"{ORDERS_DIR}orders_{newer[0]}.csv")
    return df, newer[0]


dp.create_streaming_table("orders")
dp.create_auto_cdc_from_snapshot_flow(
    target="orders",
    source=next_snapshot_and_version,
    keys=["order_id"],
    stored_as_scd_type=1,
)&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Set &lt;CODE&gt;keys&lt;/CODE&gt; to the column or columns that uniquely identify a row (&lt;A href="https://docs.databricks.com/aws/en/ldp/developer/ldp-python-ref-apply-changes-from-snapshot" target="_blank"&gt;snapshot API&lt;/A&gt;). Without &lt;CODE&gt;.schema(...)&lt;/CODE&gt;, this CSV read returns every column as a string; add the schema before &lt;CODE&gt;.load(...)&lt;/CODE&gt; for typed columns (&lt;A href="https://spark.apache.org/docs/latest/sql-data-sources-csv.html#data-source-option" target="_blank"&gt;CSV options&lt;/A&gt;, &lt;A href="https://docs.databricks.com/aws/en/query/formats/csv#specify-a-schema" target="_blank"&gt;specify a schema&lt;/A&gt;). The flow requires serverless or the Pro or Advanced edition (&lt;A href="https://docs.databricks.com/aws/en/ldp/cdc#requirements" target="_blank"&gt;requirements&lt;/A&gt;). For an existing streaming table, switch the code, then run a full refresh of only &lt;CODE&gt;orders&lt;/CODE&gt;; for an existing materialized view, switch the code, run &lt;CODE&gt;&lt;A href="https://docs.databricks.com/aws/en/sql/language-manual/sql-ref-syntax-ddl-drop-view" target="_self"&gt;DROP MATERIALIZED VIEW&lt;/A&gt;&lt;/CODE&gt;, then run the same full refresh (&lt;A href="https://docs.databricks.com/aws/en/error-messages/error-classes#cannot_change_dataset_type" target="_blank"&gt;type-change guidance&lt;/A&gt;, &lt;A href="https://docs.databricks.com/aws/en/ldp/multi-file-editor#run-pipeline-code" target="_blank"&gt;full-refresh action&lt;/A&gt;).&lt;/P&gt;</description>
      <pubDate>Mon, 05 Oct 2026 17:28:15 GMT</pubDate>
      <guid>https://community.databricks.com/t5/data-engineering/databricks-sdp-spark-declarative-pipelins-overwrite-table/m-p/170660#M56332</guid>
      <dc:creator>AbhilashNagilla</dc:creator>
      <dc:date>2026-10-05T17:28:15Z</dc:date>
    </item>
  </channel>
</rss>

