I'm currently working on a requirement where we need to bring data from REST API using pyspark. We deal with good amount of data and hence need to do paginating and usually takes good amount of time to retrieve all data. The REST API uses Oauth2.0 and the issued token expires in 15minutes.
I created a UDF to run the API call which is called from dataframe as below. I feed the list of URLs along with access token to the UDF.
df2 = df.withColumn('output', test_udf(col("url"),col("id")))
I'm still trying to figure out how to pass the renewed access token when the initial one expires. I thought of storing the access token in databricks delta table instead of passing through function and update it when it expires but looks like that approach doesn't work. Any thoughts are highly appreciated.