Load tables from JDBC in parallel
Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-13-2024 08:20 AM
I have a list of about 80 tables that I need to load from an Oracle database into Databricks via JDBC. I would like to do this in parallel, instead of looping through one table at a time.
I have a function defined to ingest the data:
def ingest_data (database, table, primary_key)
There is some logic in my function, but the main part of it is loading the dataframe from JDBC and writing to a table in Databricks:
df = spark.read \
.format("jdbc") \
.option("url", url) \
.option("dbtable", table) \
.option("user", user) \
.option("password", password) \
.option("driver", "oracle.jdbc.driver.OracleDriver") \
.option("partitionColumn", primary_key) \
.option("lowerBound", int(lowerBound)) \
.option("upperBound", int(upperBound)) \
.option("numPartitions", 8) \
.load()
df.write.mode("overwrite").saveAsTable(table_name)
What is the best way to call this function multiple times in parallel? I have looked at ThreadPoolExecutor, but have never used it. Also, I'm not sure how I would call it given that my function has more than 1 parameter.
Any help is appreciated.