I Have a Pypsark notebook that reads the data from SQL table and merge the changes into the Final layer.It works fine when it is triggers by a single user. But throws an error "Concurrent Update on the STG table has failed" when Multiple users triggers this notebook at the same time. Below is the Pyspark code that is being written
DF = StageData() //To Fetch the Data From Stage tables in SQL DB
DUMMY_TABLE = "DUMMY_TABLE"
spark.sql("DROP TABLE IF EXISTS "+DUMMY_TABLE)
DF.write.saveAsTable(DUMMY_TABLE) //Writing the Stage Data to a Temporary table
//Now Merge with the Delta table
Merge_Query = ("MERGE INTO delta_table.FACT_TABLE as SQL
USING DUMMY_TABLE as STAGE on
STAGE.CODE = SQL.CODE
when matched Then UPDATE Stmnt
when not matched then Insert Stmnt")
When 2 users or more user tries to trigger this notebook at the same time it encounters a Concurrent Update/append issue at the line "DF.write.saveAsTable(DUMMY_TABLE)" How can we achieve a thread.sleep or a retry method in the above case so that no user should fail in running thie code at the same time
Please Advise