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 😞

Join 100K+ Data Experts: Register Now & Grow with Us!

Excited to expand your horizons with us? Click here to Register and begin your journey to success!

Already a member? Login and join your local regional user group! If there isn’t one near you, fill out this form and we’ll create one for you to join!