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

Earn a 50% discount on the DP-600 certification exam by completing the Fabric 30 Days to Learn It challenge.

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
RTI Forums Carousel3

New forum boards available in Real-Time Intelligence.

Ask questions in Eventhouse and KQL, Eventstream, and Reflex.

Expanding the Synapse Forums

New forum boards available in Synapse

Ask questions in Data Engineering, Data Science, Data Warehouse and General Discussion.

LearnSurvey

Fabric certifications survey

Certification feedback opportunity for the community.

Top Solution Authors
Top Kudoed Authors