How to change the column datatype of a delta table
As per the discussion with internal team, unfortunately there is no ALTER TABLE ALTER COLUMN at this moment. The possible workaround suggested is to change a datatype by reading the data in datafram using PySpark as shown below:
df = df.withColumn("id", col("colname").cast("newdatatype")) # changes a column datatype.
Then to write it back to the delta table:
df.write.format("delta").mode("overwrite").option("overwriteSchema", "true").save(folder_path) # overwrites the delta table and is another version:
If you have any feedback regarding this, I would recommend you to please log a feature request in IDEAS forum here -
All the feedback shared in this forum are actively monitored and reviewed by product team who are responsible for building it and will take action accordingly. Please do share the feedback link once it is posted so that others can up-vote and comment on it to help increase the priority of the feature request.
Hope this info helps.
8 people are following this question.