Writing a single huge dataframe into Azure SQL Database using JDBC

yeungcase
New Contributor III

Hi All,

I am currently trying to read data from a materialized view as a single dataframe which contains around 10M of rows and then write it into an Azure SQL database. However, I don't see the spark job moving a bit even an hour is passed. I have already implemented several optimization measures, but it doesn't help at all.

 

 

 

numberCores = 4
df = spark.read.table(source_table)
df.count()

 

yeungcase_0-1719991764991.png

 

 

 

 

# Write spark dataframe into target SQL database
try:
    df.coalesce(numberCores).write \
    .format("jdbc") \
    .option("url", sql_db_url) \
    .option("batchsize", "10000") \
    .option("rewriteBatchedStatements", "true") \
    .option("compression", "snappy") \
    .option("numPartitions", numberCores) \
    .option("dbtable", target_table) \
    .option("user", username) \
    .option("password", password) \
    .option("tableLock", "true") \
    .mode("overwrite") \
    .save()

    print("Successfully write data into target SQL database")
except Exception as error:
    print("An exception occurred:", error)

 

 

 

Cluster config:

yeungcase_0-1719991355253.png

 

Spark UI:

yeungcase_1-1719991508190.png

 

Appreciate for any advice. Thank you.