Writing a single huge dataframe into Azure SQL Database using JDBC
Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-03-2024 12:25 AM - edited 07-03-2024 12:29 AM
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()
# 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:
Spark UI:
Appreciate for any advice. Thank you.