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:ย 

How to track the history of schema changes for a Delta table

brickster_2018
Databricks Employee
Databricks Employee

I have a Delta table that had schema changes in multiple commits. I wanted to track all these schema changes that happened on the Delta table. The "DESCRIBE HISTORY" is not useful as it logs the schema change made by ALTER TABLE operations.

1 ACCEPTED SOLUTION

Accepted Solutions

brickster_2018
Databricks Employee
Databricks Employee

When a write operation is performed with columns added. we are not explicitly showing that in 

DESCRIBE HISTORY output. Only an entry is made for write. and in the operation Parameters, it's not showing anything about schema evolution. whereas if we do alter table then that is shown explicitly. 

Below code snippet queries the Delta transaction logs to give us the details about all the schema changes done on the table (Replace the table location with your Delta table location)

spark.read.json("dbfs:/tmp/hari/delta/caching/test/2/_delta_log/*.json").createOrReplaceTempView("delta_log")
display(spark.sql("select metadata.schemaString,input_file_name() from delta_log where metadata is not null"))

View solution in original post

1 REPLY 1

brickster_2018
Databricks Employee
Databricks Employee

When a write operation is performed with columns added. we are not explicitly showing that in 

DESCRIBE HISTORY output. Only an entry is made for write. and in the operation Parameters, it's not showing anything about schema evolution. whereas if we do alter table then that is shown explicitly. 

Below code snippet queries the Delta transaction logs to give us the details about all the schema changes done on the table (Replace the table location with your Delta table location)

spark.read.json("dbfs:/tmp/hari/delta/caching/test/2/_delta_log/*.json").createOrReplaceTempView("delta_log")
display(spark.sql("select metadata.schemaString,input_file_name() from delta_log where metadata is not null"))

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