Forum Discussion
QuinnDatatyk
2 years agoFrequent 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
Then change col1 to data type int and use spark.write.mode("overwrite")
It return error
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
2 Replies
- frithjof_vCommunity Champion
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
- QuinnDatatykFrequent Visitor
I tried and successed. Thank you very much.