Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
QuinnDatatyk
Frequent Visitor

Spark Write to OneLake cannot overwrite data schema

I cannot overwrite table schema using spark.write.mode("overwrite")

For example, create a table with 2 column: col1 as int and col2 as string

QuinnDatatyk_0-1713088635792.png

Then change col1 to data type int and use spark.write.mode("overwrite")

QuinnDatatyk_2-1713088720743.png

It return error 

QuinnDatatyk_3-1713088773822.png

 

 

 

1 ACCEPTED SOLUTION
frithjof_v
Continued Contributor
Continued Contributor

I think if you want to overwrite the schema while overwriting the data, you could write like this:

 

df\
   .write\
   .mode("overwrite")\
   .option("overwriteSchema", "true")\
   .saveAsTable("tableName")

 

So I think you only need to add .option("overwriteSchema", "true") in your code

 

 

Ref. https://community.fabric.microsoft.com/t5/General-Discussion/Dropping-and-recreating-lakehouse-table...

 

View solution in original post

2 REPLIES 2
frithjof_v
Continued Contributor
Continued Contributor

I think if you want to overwrite the schema while overwriting the data, you could write like this:

 

df\
   .write\
   .mode("overwrite")\
   .option("overwriteSchema", "true")\
   .saveAsTable("tableName")

 

So I think you only need to add .option("overwriteSchema", "true") in your code

 

 

Ref. https://community.fabric.microsoft.com/t5/General-Discussion/Dropping-and-recreating-lakehouse-table...

 

I tried and successed. Thank you very much.

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

March 2024  FBC Gallery Image

Fabric Monthly Update - March 2024

Check out the March 2024 Fabric update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

Find out what's new and trending in the Fabric Community.

Top Kudoed Authors