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:ย 

MergeSchema Not Working

DJey
New Contributor III

Hi All,

I have a scenario where my Exisiting Delta Table looks like below:

imageNow I have an incremental data with an additional column i.e. owner:

Dataframe Name --> scdDFimageBelow is the code snippet to merge Incremental Dataframe to targetTable, but the new column is not getting added:

imagespark.conf.set("spark.databricks.delta.schema.autoMerge.enabled",True) --> this is also enabled.

But still no luck. Below is the final result which i'm currently getting:

Data looks correct, but the only issue is New Column i.e. Owner is still not merged in targetTable.image 

Someone please help.

Thanks!

1 ACCEPTED SOLUTION

Accepted Solutions

etsyal1e2r3
Honored Contributor

Just add that column to the table with an ALTER TABLE statement. You should capture each table/dataframe columns as a list with df.columns, compare them, and if the table is missing anything do the alter table. Then run your code.

View solution in original post

6 REPLIES 6

etsyal1e2r3
Honored Contributor

Just add that column to the table with an ALTER TABLE statement. You should capture each table/dataframe columns as a list with df.columns, compare them, and if the table is missing anything do the alter table. Then run your code.

Anonymous
Not applicable

Hi @Divyansh Jainโ€‹ 

Thank you for posting your question in our community! We are happy to assist you.

To help us provide you with the most accurate information, could you please take a moment to review the responses and select the one that best answers your question?

This will also help other community members who may have similar questions in the future. Thank you for your participation and let us know if you need any further assistance! 

DJey
New Contributor III

This is resolved. Thanks, everyone!

DJey
New Contributor III

@Vidula Khannaโ€‹  Enabling the below property resolved my issue:

spark.conf.set("spark.databricks.delta.schema.autoMerge.enabled",True) 

Thanks v much!

g96g
New Contributor III

sorry, can you please explain what was the problem? cause you have already that property enabled 

Amin112
New Contributor II

In Databricks Runtime 15.2 and above, you can specify schema evolution in a merge statement using SQL or Delta table APIs:

MERGE WITH SCHEMA EVOLUTION INTO target
USING source
ON source.key = target.key
WHEN MATCHED THEN
UPDATE SET *
WHEN NOT MATCHED THEN
INSERT *
WHEN NOT MATCHED BY SOURCE THEN
DELETE

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