https://delta.io logo
s

sabari dass

01/10/2023, 9:31 PM
Hi All, I need to add new fields in the existing delta table. I know how to add new fields in the existing hive table (using ‘alter cascade’) but not sure how to do it in delta table using pyspark. Can anyone please help me on this? Thanks in advance!
n

Nick Karpov

01/11/2023, 2:57 AM
Copy code
spark.sql("""
     ALTER TABLE tbl ADD COLUMNS (col1 DataType)
""")
g

Gerhard Brueckl

01/11/2023, 7:56 AM
another option would be to simply use schema evolution and write/append the new dataframe with the additional columns to the existing delta lake table by using
.option("mergeSchema", "true")
here are the official docs: https://docs.databricks.com/delta/update-schema.html (most if not all should also apply to Delta OSS)
👍 3
4 Views