cancel
Showing results for 
Search instead for 
Did you mean: 
Data Engineering
Join discussions on data engineering best practices, architectures, and optimization strategies within the Databricks Community. Exchange insights and solutions with fellow data engineers.
cancel
Showing results for 
Search instead for 
Did you mean: 

Unable to change the index, when writing to a Azure SQL Data Warehouse

Rajesh_M
New Contributor III

Hi,

I have some data in a spark data frame and I am trying to write it to a table in Azure SQL Data Warehouse. If I use df.write.mode(saveMode="overwrite") I get this error:

com.microsoft.sqlserver.jdbc.SQLServerException: The statement failed. Column 'code' has a data type that cannot participate in a columnstore index.

I guess its trying to create the end table using with a columnstore index. I need a way to specify that the create statement not create the end table with a column store index.

The other issue is if I change that to df.write.option("truncate",True).mode(saveMode="append") and run it a few times (after manually creating the table the first time), I end up with duplicate records in the end table. That basically means that the "truncate" option isn't working

Best,

Rajesh

1 ACCEPTED SOLUTION

Accepted Solutions

Hubert-Dudek
Esteemed Contributor III

For avoiding duplicates during append you can set index in sql with options: "is Unique"=Yes and "Ignore Duplicate Keys"=Yes.

Spark/databricks don't know what is in database that's why you have duplicates.

Truncate option is for overwrite mode only as than instead of DROP TABLE in SQL it makes TRUNCATE TABLE so schema survive.

Regarding error probably in SQL you have separated CLUSTERED index but I am not sure.

View solution in original post

4 REPLIES 4

Hubert-Dudek
Esteemed Contributor III

For avoiding duplicates during append you can set index in sql with options: "is Unique"=Yes and "Ignore Duplicate Keys"=Yes.

Spark/databricks don't know what is in database that's why you have duplicates.

Truncate option is for overwrite mode only as than instead of DROP TABLE in SQL it makes TRUNCATE TABLE so schema survive.

Regarding error probably in SQL you have separated CLUSTERED index but I am not sure.

Rajesh_M
New Contributor III

Thanks @Hubert Dudek​ .

Do you know if there is a way to run a create table statement on Azure Synapse/Azure SQL Datawarehouse from Databricks?

Hubert-Dudek
Esteemed Contributor III

Yes, it is possible, as they both use blob storage. As architecture like this is more complex, you need to go through the manual; there are a lot of examples: https://docs.microsoft.com/en-us/azure/databricks/data/data-sources/azure/synapse-analytics

Kaniz_Fatma
Community Manager
Community Manager

Hi @Rajesh Mangipudi​ , Just a friendly follow-up. Do you still need help, or @Hubert Dudek (Customer)​ 's response help you to find the solution? Please let us know.

Connect with Databricks Users in Your Area

Join a Regional User Group to connect with local Databricks users. Events will be happening in your city, and you won’t want to miss the chance to attend and share knowledge.

If there isn’t a group near you, start one and help create a community that brings people together.

Request a New Group