Home / Databricks on Azure

Databricks on AzureChecklistAdvanced

Delta type widening on Azure Databricks - a checklist for INT to BIGINT and other column type changes without a rewrite

Widen Delta column types in place, without rewriting the table. Covers prechecks for readers, streams and Delta Sharing, the ALTER and automatic paths, schema tracking for downstream streams, and how to back out.

Deepak Bhardwaj7 min read

Applies toAzure Databricks, Databricks Runtime 15.4 LTS and later (streaming support 16.4 LTS and later), Unity Catalog and Hive metastore Delta tables

An INT key overflows, a DECIMAL(10,2) column needs more precision, or a source changed FLOAT to DOUBLE. Before type widening, the only fix was to rewrite the table with overwriteSchema. That breaks streaming readers, resets file layout and can take hours on a large table. With type widening, Delta records the type change in the table metadata, and existing files are read with the new type without being rewritten. Use this checklist so the change does not break a downstream stream, a Power BI model or a Delta Sharing recipient.

Important

Enabling type widening adds the typeWidening table feature and upgrades the table's reader and writer protocol. Every client that reads or writes the table must support it, including older Databricks Runtimes, external Spark, Fabric, Synapse and Power BI connectors. Disabling the property later does not remove the feature.

1. Confirm the change is a supported widening

  • The change is in the supported list for your runtime. Typical supported changes:
From To
BYTE → SHORT → INT → BIGINT Any wider integer
FLOAT DOUBLE
DECIMAL(p,s) DECIMAL(p2,s2) with p2 >= p, s2 >= s and an integer-digit count that does not shrink
DATE TIMESTAMP_NTZ
  • You checked the restrictions for your runtime. Integer to DECIMAL or DOUBLE changes are limited on some runtimes and are not supported for Delta Sharing. Check the current "Type widening" page before you plan one.
  • Narrowing (BIGINT → INT) and unrelated changes (STRING → INT) are not widening. They still need a rewrite.
  • The column is not a partition column, and is not used in a generated column or constraint expression that would change meaning. Look at SHOW CREATE TABLE.
SHOW CREATE TABLE prod.sales.orders;
DESCRIBE DETAIL prod.sales.orders;   -- minReaderVersion, minWriterVersion, tableFeatures

2. Inventory every reader and writer

  • All jobs and pipelines that write the table run on DBR 15.4 LTS or later.
  • All Databricks readers run 15.4 LTS or later. Use lineage to find what reads the table, then check the runtime of the compute behind it:
-- Who read the table in the last 30 days (jobs, notebooks, pipelines, queries)
SELECT entity_type, entity_id, created_by, max(event_time) AS last_read
FROM system.access.table_lineage
WHERE source_table_full_name = 'prod.sales.orders'
  AND event_date >= current_date() - INTERVAL 30 DAYS
GROUP BY ALL
ORDER BY last_read DESC;

-- Clusters still on a runtime older than 15.4 (latest config per cluster)
SELECT cluster_id, cluster_name, dbr_version, owned_by
FROM system.compute.clusters
WHERE delete_time IS NULL
QUALIFY row_number() OVER (PARTITION BY cluster_id ORDER BY change_time DESC) = 1
  AND try_cast(regexp_extract(dbr_version, '^(\\d+\\.\\d+)', 1) AS DOUBLE) < 15.4;

Column names in system tables can change between releases. If a query fails, run DESCRIBE on the table to check the columns. SQL warehouses and serverless compute always run current runtimes, so only classic clusters need this check.

  • Streams reading this table run on 16.4 LTS or later. That is the minimum for streaming over a type change.
  • Delta Sharing: provider and recipients run 16.1 or later (Databricks-to-Databricks). Open-sharing recipients may not support the feature. Ask them first.
  • External engines (Fabric, Synapse serverless, open source Spark/Trino, Power BI Delta connectors) support typeWidening. If any don't, give them a typed view or a copy instead.

3. Enable and change the type

  • Run it in a maintenance window that has no concurrent writers to this table, and record the current version:
DESCRIBE HISTORY prod.sales.orders LIMIT 1;   -- note the version number
  • Enable the feature and widen the column:
ALTER TABLE prod.sales.orders SET TBLPROPERTIES ('delta.enableTypeWidening' = 'true');

ALTER TABLE prod.sales.orders ALTER COLUMN order_line_id TYPE BIGINT;
ALTER TABLE prod.sales.orders ALTER COLUMN amount TYPE DECIMAL(20,2);
  • For automatic widening during writes (MERGE or INSERT with schema evolution), you have chosen whether you want it. With the property on, writes with schema evolution enabled can widen types on their own when the source has a wider type:
MERGE WITH SCHEMA EVOLUTION INTO prod.sales.orders t
USING staging.orders_delta s ON t.order_id = s.order_id
WHEN MATCHED THEN UPDATE SET *
WHEN NOT MATCHED THEN INSERT *;

Warning

Automatic widening means a source schema change can now change the production table's type without any review. If you want explicit control, widen only with ALTER TABLE ... ALTER COLUMN, and do not enable schema evolution on writes to this table.

  • Verify:
DESCRIBE TABLE prod.sales.orders;
DESCRIBE HISTORY prod.sales.orders LIMIT 3;   -- CHANGE COLUMN operation, no file rewrite
SELECT max(order_line_id), max(amount) FROM prod.sales.orders;

4. Downstream streams

A Delta stream that reads the table stops when it sees the type change. Prepare it before the change:

  • Each streaming read has a schemaTrackingLocation inside its checkpoint path:
cp = "/Volumes/prod/streaming/_chk/orders_to_gold"

df = (spark.readStream
        .option("schemaTrackingLocation", f"{cp}/_schema")
        .table("prod.sales.orders"))
  • After the change, the stream stops once. Update its sink to accept the wider type, for example by enabling type widening on the target table. Then allow the change and restart:
df = (spark.readStream
        .option("schemaTrackingLocation", f"{cp}/_schema")
        .option("allowSourceColumnTypeChange", "<source table version>")  # or "always"
        .table("prod.sales.orders"))

The same can be set as Spark conf spark.databricks.delta.streaming.allowSourceColumnTypeChange. You cannot set schemaTrackingLocation from SQL streaming syntax.

  • Lakeflow Declarative Pipelines that read the table: test in a dev pipeline first. Pipeline-managed tables handle schema changes differently, and a full refresh of the downstream table may be needed.
  • foreachBatch sinks: check that MERGE targets and any JDBC targets (Azure SQL, Synapse) accept the wider type. INT to BIGINT on a SQL Server target needs an ALTER TABLE there too.

5. Consumers outside the table

  • Power BI datasets: refresh the model metadata so the column is picked up as a 64-bit integer or wider decimal.
  • Views with explicit CAST(... AS INT): update them, or they will overflow and fail when ANSI mode is on.
  • Data contracts and schema registries: update the documented type.

6. Backing out

  • You understand that SET TBLPROPERTIES ('delta.enableTypeWidening' = 'false') blocks future type changes. It does not undo past changes and does not remove the feature.
  • To remove the feature completely, for example for an external reader that cannot be upgraded:
ALTER TABLE prod.sales.orders DROP FEATURE 'typeWidening';

This rewrites the files written with the old types, and it may need TRUNCATE HISTORY and a waiting period before the protocol downgrade completes. The DROP FEATURE docs give the exact steps for your runtime. Plan it like a rewrite.

Caution

RESTORE TABLE ... TO VERSION AS OF the version before the change brings back the old schema, but it also throws away every write made since then. Don't use it as a quick rollback on a table that is being written to.

Prevent it next time

  • Create surrogate and counter columns as BIGINT from the start. Running out of INT range is the most common reason for this change.
  • Turn on delta.enableTypeWidening when you create new tables, but only where all readers already support it. Then the change is a metadata operation when you need it.
  • Add a schemaTrackingLocation to every Delta streaming read now, so future type and column mapping changes stop the stream cleanly and can be resumed.
  • Alert when a column gets close to its type's limit. For example, check max(order_line_id) against 2,147,483,647 every day.