Skip to content

Delta type widening

The type widening feature allows changing the type of columns in a Delta table to a wider type. This enables manual type changes using the ALTER TABLE ALTER COLUMN command and automatic type migration with schema evolution during write operations.

The feature introduces a limited set of supported type changes in Delta Lake 3.2 and expands it in Delta Lake 4.0 and above.

Source typeSupported wider types - Delta 3.2Supported wider types - Delta 4.0
byteshort, intshort, int, long, decimal, double
shortintint, long, decimal, double
intlong, decimal, double
longdecimal
floatdouble
decimaldecimal with greater precision and scale
datetimestampNTZ

To avoid accidentally promoting integer values to decimals, you must manually commit type changes from byte, short, int, or long to decimal or double. When promoting an integer type to decimal or double, if any downstream ingestion writes this value back to an integer column, Spark will truncate the fractional part of the values by default.

Type changes are supported for top-level columns as well as fields nested inside structs, maps and arrays.

You can enable type widening on an existing table by setting the delta.enableTypeWidening table property to true:

ALTER TABLE <table_name> SET TBLPROPERTIES ('delta.enableTypeWidening' = 'true')

Alternatively, you can enable type widening during table creation:

CREATE TABLE <table_name> USING DELTA TBLPROPERTIES('delta.enableTypeWidening' = 'true')

To disable type widening:

ALTER TABLE <table_name> SET TBLPROPERTIES ('delta.enableTypeWidening' = 'false')

Disabling type widening prevents future type changes from being applied to the table. It doesn’t affect type changes previously applied and in particular, it doesn’t remove the type widening table feature and doesn’t allow clients that don’t support the type widening table feature to read and write to the table.

To remove the type widening table feature from the table and allow other clients that don’t support this feature to read and write to the table, see Removing the type widening table feature.

When type widening is enabled on a Delta table, you can change the type of a column using the ALTER COLUMN command:

ALTER TABLE <table_name> ALTER COLUMN <col_name> TYPE <new_type>

The table schema is updated without rewriting the underlying Parquet files.

Type changes with automatic schema evolution

Section titled “Type changes with automatic schema evolution”

Schema evolution works with type widening to update data types in target tables to match the type of incoming data.

To use schema evolution to widen the data type of a column during ingestion, you must meet the following conditions:

  • The write command runs with automatic schema evolution enabled.
  • The target table has type widening enabled.
  • The source column type is wider than the target column type.
  • Type widening supports the type change.
  • The type change is not one of byte, short, int, or long to decimal or double. These type changes can only be applied manually using ALTER TABLE to avoid accidental promotion of integers to decimals.

Type mismatches that don’t meet all of these conditions follow normal schema enforcement rules.

The type widening feature can be removed from a Delta table using the DROP FEATURE command:

ALTER TABLE <table_name> DROP FEATURE 'typeWidening' [TRUNCATE HISTORY]

See Drop Delta table features for more information on dropping Delta table features.

When dropping the type widening feature, the underlying Parquet files are rewritten when necessary to ensure that the column types in the files match the column types in the Delta table schema. After the type widening feature is removed from the table, Delta clients that don’t support the feature can read and write to the table.

Iceberg doesn’t support all type changes covered by type widening, see Iceberg Schema Evolution. In particular, Iceberg V2 does not support the following type changes:

  • byte, short, int, long to decimal or double
  • decimal scale increase
  • date to timestampNTZ

When UniForm with Iceberg compatibility is enabled on a Delta table, applying one of these type changes results in an error.

If you apply one of these unsupported type changes to a Delta table, enabling Uniform with Iceberg compatibility on the table results in an error. To resolve the error, you must drop the type widening table feature.