cancel
Showing results for 
Search instead for 
Did you mean: 
Data Engineering
Join discussions on data engineering best practices, architectures, and optimization strategies within the Databricks Community. Exchange insights and solutions with fellow data engineers.
cancel
Showing results for 
Search instead for 
Did you mean: 

Structured streaming from an overwrite delta path

Vu_QuangNguyen
New Contributor

Hi experts,

I need to ingest data from an existing delta path to my own delta lake.

The dataflow is as shown in the diagram:

  • Data team reads full snapshot of a database table and overwrite to a delta path. This is done many times per day, but not fixed schedule everyday.
I need to stream every data changes to my own delta lake for downstream consumption. Basically the same with source delta lake, but with increased log & data retention period to enable time travelling for 3 years.

0693f000007OoRcAAK

I have tried the following code:
def overwrite_microbatch(microdf, batchId):
  microdf.write.format("delta").mode("overwrite").save(sink_path)
(spark.readStream
  .format("delta")
  .option("ignoreChanges", "true")
  .load(source_path)
  .writeStream
  .foreachBatch(overwrite_microbatch)
  .option("checkpointLocation", checkpoint_path)
  .start())

(.writeStream.format("delta").outputMode("append") does not work because "append" mode causes duplication and writeStream does NOT support "overwrite" mode.)

Which works, but I ran into 2 problems:

  1. Sink path is not storage optimized, i.e each version stores a full table snapshot in a .snappy.parquet file instead of only incremental changes.
  2. If my streaming job fails to consume one or more versions, then the next microbatch contains a concat of 2+ versions that are not yet consumed. Which again causes duplication in sink path.

What should be the right approach for this scenario?

Any idea is very much appreciated. Thanks!

Best Regards,

Vu

0 REPLIES 0

Connect with Databricks Users in Your Area

Join a Regional User Group to connect with local Databricks users. Events will be happening in your city, and you won’t want to miss the chance to attend and share knowledge.

If there isn’t a group near you, start one and help create a community that brings people together.

Request a New Group