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: 

delete and append in delta path

KKo
Contributor III

I am deleting data from curated path based on date column and appending staged data on it on each run, using below script. My fear is, just after the delete operation, if any network issue appeared and the job stopped before it appended the staged data on curated_path. How does the delta lake (The ACID property) handles this situation, does this roll back to the previous state since it did not append the staged data?

OR how to do delete and append properly in delta lake to avoide any data loss?

Thanks in advance!!

df_curated = spark.read.format('delta').load(curated_path)

df_curated.createOrReplaceTempView("curated_view")

sqlString = "DELETE FROM curated_view WHERE Date >= "+"'{}'" .format(daysback_date)

spark.sql(sqlString)

df_staged.write.partitionBy("Year").format('delta').mode("append").save(curated_path)

2 REPLIES 2

Hubert-Dudek
Esteemed Contributor III

Yes, Delta is ACID, so it should work ok. As an alternative, you can always consider MERGE (as I bet that you want to replace Dates that are coming with updates)

https://learn.microsoft.com/en-us/azure/databricks/sql/language-manual/delta-merge-into

Aviral-Bhardwaj
Esteemed Contributor III

thanks man

AviralBhardwaj

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