Hi @Harikrishnan P H,
Delta Lake lets you update the schema of a table. The following types of changes are supported:
- Adding new columns (at arbitrary positions)
- Reordering existing columns
- Renaming existing columns
You can make these changes explicitly using DDL or implicitly using DML.
Important:-
When you update a Delta table schema, streams that read from that table terminate. If you want the stream to continue, you must restart it.
For recommended methods, see Production considerations for Structured Streaming applications on Databricks.
Explicitly update schema
You can use the following DDL to explicitly change the schema of a table.
To Add columns,
ALTER TABLE table_name ADD COLUMNS (col_name data_type [COMMENT col_comment] [FIRST|AFTER colA_name], ...)
By default, nullability is true.
To add a column to a nested field, use the following:
ALTER TABLE table_name ADD COLUMNS (col_name.nested_col_name data_type [COMMENT col_comment] [FIRST|AFTER colA_name], ...)
Example:-
If the schema before running ALTER TABLE boxes ADD COLUMNS (colB.nested STRING AFTER field1) is:
- root
| - colA
| - colB
| +-field1
| +-field2
The schema after is:
- root
| - colA
| - colB
| +-field1
| +-nested
| +-field2
Note:-
Adding nested columns is supported only for structs. Arrays and maps are not supported.
Rest you can find it here.
Source:- https://docs.databricks.com/delta/delta-batch.html#add-columns
---------------------------------------------------------------------
" I have tried the `ALTER TABLE ADD PARTITION,` but it didn't work. "
Would you mind sharing the code snippet here?