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:ย 

preAction in databricks while writing into Google Big Query Table?

asif5494
New Contributor III

I am writing into Google Big Query table using append mode. I need to delete current day data before writing new data. I just want to know if there is any preActions parameter can be used to first delete data before writing into table? Below is the syntax but preActiones is not working in this:

(DF.write
 .format("bigquery")
 .option("temporaryGcsBucket", "Bucket-Name")
 .option("preActions","Truncate table `Table-Name`")
 .mode("append")
 .option("credentialsFile",credentialfilepath)
 .option("parentProject",projectName)
 .option("table", "Table-Name")
 .save()
 )

3 REPLIES 3

Cami
Contributor III

Can you use override mode instead append?

asif5494
New Contributor III

Thanks @Camilla Lokโ€‹ for your valuable response. As I have mentioned in I just need to delete the current day data not the entire table data, I mentioned the Truncate query just for reference but we need to run delete query instead of Truncate.

(DF.write
 .format("bigquery")
 .option("temporaryGcsBucket", "Bucket-Name")
 .option("preActions",'delete from Table_Name where Date_Col="2023-01-20"`')
 .mode("append")
 .option("credentialsFile",credentialfilepath)
 .option("parentProject",projectName)
 .option("table", "Table-Name")
 .save()
 )

But this delete query is not working in the above query.

Cami
Contributor III

Sorry, I didn't have to unread. Unfortunately I am not not sure if such option exists within the write command for data frame The only way out I can see is to delete the data before landin ๐Ÿ˜ž

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