Scala Synapse notebook dataframe.write.mode("append") Not working

Dheeraj 351 Reputation points
2021-07-20T17:12:02.45+00:00

I am trying to write spark sql table to Sql data warehouse. I am able to create a table from scratch but if I try to append the data to existing DW table, it fails.
Here is code:

*df.createOrReplaceTempView("vw_SampleTable")
val dfProject = spark.sql("SELECT * FROM vw_SampleTable")
dfProject.write.mode("append").
option(Constants.SERVER, "xyz-datawarehouse01.sql.azuresynapse.net").
synapsesql("Company_Pool1.dbo.TableReal", Constants.INTERNAL)*

The error it gives:
Operation on target ABC Imports from Blob failed: Error: java.sql.SQLException: com.microsoft.sqlserver.jdbc.SQLServerException: There is already an object named 'TableReal' in the database.
at com.microsoft.spark.sqlanalytics.utils.SQLAnalyticsJDBCWrapper.executeUpdateStatement(SQLAnalyticsJDBCWrapper.scala:92)

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

Accepted answer
  1. Vaibhav Chaudhari 38,916 Reputation points Volunteer Moderator
    2021-07-21T11:35:09.71+00:00

    As mentioned in the below document, If the table already exists the operation will fail with Table already exists error -

    https://learn.microsoft.com/en-us/azure/synapse-analytics/spark/synapse-spark-sql-pool-import-export#write-api

    Also see the similar question here -

    https://learn.microsoft.com/en-us/answers/questions/231636/azure-synapse-spark-function-dfwritesynapsesql.html

    You can vote for the feedback posted here - https://feedback.azure.com/forums/307516-azure-synapse-analytics/suggestions/42303991-synapsesql-formerly-sqlanalytics-supports-append

    ----------

    Please don't forget to Accept Answer and Up-vote if the response helped -- Vaibhav

    1 person found this answer helpful.
    0 comments No comments

0 additional answers

Sort by: Most helpful

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.