cancel
Showing results for 
Search instead for 
Did you mean: 
Data Engineering
Join discussions on data engineering best practices, architectures, and optimization strategies within the Databricks Community. Exchange insights and solutions with fellow data engineers.
cancel
Showing results for 
Search instead for 
Did you mean: 

Changing a Delta Live Table's schema

rcostanza
New Contributor III

I have a Delta Live Table whose source is a Kafka stream. One of the columns is a Decimal and I need to change its precision.

What's the correct approach to changing the DLT's schema?

Just changing the column's precision in the DLT definition will result in an error running the pipeline - the old and new columns are incompatible, even if it's the same type but a different precision. And the overwriteSchema/mergeSchema options are not valid for a Kafka stream.

My current options are:

- Deleting the DLT and letting the pipeline rebuild it

- Changing the DLT's column through ALTER TABLE

1 REPLY 1

Sidhant07
Databricks Employee
Databricks Employee

To change the precision of a Decimal column in a Delta Live Table (DLT) with a Kafka stream source, you can follow these steps:

1. Create a new column in the DLT with the desired precision.
2. Copy the data from the old column to the new column.
3. Drop the old column.
4. Rename the new column to the original column name.

Here's an example of how to do this using SQL:

```sql
-- Create a new column with the desired precision
ALTER TABLE your_table_name ADD COLUMNS (new_column Decimal(precision, scale));

-- Copy the data from the old column to the new column
UPDATE your_table_name SET new_column = old_column;

-- Drop the old column
ALTER TABLE your_table_name DROP COLUMN old_column;

-- Rename the new column to the original column name
ALTER TABLE your_table_name CHANGE COLUMN new_column old_column Decimal(precision, scale);
```

Replace `your_table_name` with the name of your DLT, `old_column` with the name of the column you want to change, `new_column` with a temporary name for the new column, and `precision` and `scale` with the desired precision and scale for the Decimal type.

This approach allows you to change the precision of the column without deleting the DLT or using the `overwriteSchema` or `mergeSchema` options.

Connect with Databricks Users in Your Area

Join a Regional User Group to connect with local Databricks users. Events will be happening in your city, and you won’t want to miss the chance to attend and share knowledge.

If there isn’t a group near you, start one and help create a community that brings people together.

Request a New Group