cancel
Showing results for 
Search instead for 
Did you mean: 
Data Engineering
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 😞

Welcome to Databricks Community: Lets learn, network and celebrate together

Join our fast-growing data practitioner and expert community of 80K+ members, ready to discover, help and collaborate together while making meaningful connections. 

Click here to register and join today! 

Engage in exciting technical discussions, join a group with your peers and meet our Featured Members.