databricks to synapse

Vineet S 1,390 Reputation points
2024-05-21T09:20:54.4866667+00:00

Hi Team,

I am getting error while connecting databricks to synapse ... here is the code

com.databricks.spark.sqldw.SqlDWConnectorException: Exception encountered in Azure Synapse Analytics connector code.

def refresh_synapse_tables(databaseName="test", synapseSchema="fact", table_wildcard="table1"):
    start = timeit.default_timer()
    tbl_df = spark.sql(f"show tables in {databaseName}")

    if table_wildcard is not None:
        tbl_df = tbl_df.select('tableName').where(f"tableName like '{table_wildcard}'")
    
    for row in tbl_df.collect():
        print("Copying table: " + row['tableName'])
        table_content_df = spark.sql(f"select * from {databaseName}.{row['tableName']}")

        table_content_df.write \
            .mode('overwrite') \
            .format("com.databricks.spark.sqldw") \
            .option("useAzureMSI","true") \
            .option("url", "sqlDwUrl") \
            .option("tempDir", tempDir) \
            .option("dbTable", synapseSchema + "." + "tfaap_fact_quote") \
            .save()

    end = timeit.default_timer()        
    print(f"{databaseName} database tables refreshed: {(end - start):.3f} seconds") 
# Call the function with the required parameters
#refresh_synapse_tables(databaseName, synapseSchema, table_wildcard)

Azure Synapse Analytics
Azure Synapse Analytics
An Azure analytics service that brings together data integration, enterprise data warehousing, and big data analytics. Previously known as Azure SQL Data Warehouse.
5,373 questions
{count} votes

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.