Databricks - how to write dataframe to SQL Server as Service Principal

Viewed 29

I can read the data from Azure SQL as Service Principal using Python and Spark.

How can I write back into Azure SQL table the dataframe using the same tech?

This is the working code to read data:

context = adal.AuthenticationContext(authority)
token = context.acquire_token_with_client_credentials(resource_app_id_url, service_principal_id, service_principal_secret)
access_token = token["accessToken"]

Df = spark.read \
             .format("com.microsoft.sqlserver.jdbc.spark") \
             .option("url", azure_sql_url) \
             .option("dbtable", db_table) \
             .option("databaseName", database_name) \
             .option("accessToken", access_token) \
             .option("encrypt", "true") \
             .option("hostNameInCertificate", "*.database.windows.net") \
             .load()
0 Answers
Related