What you will be able to do
- Run DESCRIBE HISTORY and read who changed a Delta table, when, and with which operation
- Use operationParameters and operationMetrics to explain exactly what a commit did
- Compare two table versions with EXCEPT or a key join to validate a change or measure a trend
- Explain why history can list a version whose data can no longer be queried
Key concept
Table version — Every write to a Delta table commits a new, numbered version to the transaction log. DESCRIBE HISTORY lists those commits, and time travel can read any version that is still retained, so a version is both an audit record and a snapshot you can query.
1.Auditing a table with DESCRIBE HISTORY
A Delta table records every change it receives. When a nightly load doubles a row count, or a column suddenly fills with nulls, the first thing to find out is what touched the table, who ran it and when. Every insert, update, delete, merge or OPTIMIZE commits a new numbered version to the table's transaction log, and DESCRIBE HISTORY reads that log back as a result set with one row per commit.
Newest commits come first, because rows are returned in reverse chronological order. That ordering gives LIMIT a useful meaning: LIMIT 1 returns only the most recent operation, and LIMIT 5 returns the last five. The table name has to be plain. A temporal specification such as VERSION AS OF is not allowed in the DESCRIBE HISTORY statement, because the command already covers every version. If you prefer a visual view, Catalog Explorer shows the same history on the table's History tab.
DESCRIBE HISTORY table_name -- get the full history of the table
DESCRIBE HISTORY table_name LIMIT 1 -- get the last operation onlyThe output has 14 columns, and each one answers a different audit question. For who and when, use userName, userId and timestamp. For where the change came from, use job and notebook: each is filled in only when the commit came from a Lakeflow job or a Databricks notebook, and is null otherwise. clusterId names the compute it ran on. readVersion is the version the write read before committing. In a long chain of edits you can follow it backwards: version 5 read version 4, which read version 3. Writes made over JDBC or ODBC, through the REST API, or from some job task types leave some of these columns empty.
| Audit question | Column | What it records |
|---|---|---|
| Which change? | version | The table version generated by the operation |
| When? | timestamp | When this version was committed |
| Who? | userId, userName | The ID and name of the user that ran the operation |
| What kind of change? | operation | The operation name, such as WRITE, UPDATE, DELETE, MERGE or OPTIMIZE |
| From where? | job, notebook, clusterId | The Lakeflow job or notebook (null if neither) and the cluster that ran it |
| Based on what? | readVersion | The table version read to perform the write |
| How exactly? | operationParameters, operationMetrics | The operation's parameters (for example, predicates) and its row and file counts |
| Anything else? | isolationLevel, isBlindAppend, userMetadata | Isolation level, whether the operation appended data, and user-defined commit metadata |
Checkpoint 1 of 8· Fill the gap
An analyst wants to see only the most recent commit to a Delta table. Which keyword completes the second statement?
DESCRIBE HISTORY table_name -- get the full history of the table
DESCRIBE HISTORY table_name ? 1 -- get the last operation onlyDESCRIBE HISTORY returns commits newest first, so LIMIT 1 returns the latest operation. A temporal specification such as VERSION AS OF is not allowed in DESCRIBE HISTORY because the command already covers every version.
Source: docs.databricks.comCheckpoint 2 of 8· Match them up
You are investigating a suspicious commit. Match each DESCRIBE HISTORY column to what it tells you.
Tap a term, then the definition that fits it.
operationParameters holds the inputs of the operation, such as predicates. operationMetrics holds the row and file counts that result from that one commit. readVersion lets you follow a chain of edits backwards, and notebook is filled in only for commits written from a Databricks notebook.
“operationMetrics | map | The metrics of the operation (for example, number of rows and files modified.)”Source: docs.databricks.com
2.Reading operationParameters and operationMetrics
The operation column gives only the type of change. Two map columns tell you what the change actually did. operationParameters holds the inputs the operation ran with. operationMetrics holds the measured result: how many rows and files the commit added, removed, updated or copied, plus timings. Neither column stores the SQL text of the statement, and neither holds the column statistics Delta uses for data skipping or the warehouse's configuration.
operationParameters depend on the operation. A DELETE or UPDATE records its predicate, so the history row for a cleanup step shows the condition it applied, for example (spark_catalog.myschema.t.c1 = 3). An append records mode as Append. A CREATE TABLE records things like isManaged and the table properties. One field is easy to misread. partitionBy only means something on CREATE and OVERWRITE operations, and on appends it can show [] even though the rows still land in the correct partitions.
operationParameters: {
"mode": "Append",
"partitionBy": "[]"
}operationMetrics have different keys for each operation, and the key names describe themselves. A MERGE is the richest. It reports numSourceRows, then numTargetRowsInserted, numTargetRowsUpdated and numTargetRowsDeleted, then numTargetFilesAdded and numTargetFilesRemoved, along with executionTimeMs. Suppose a MERGE of a 10,000-row source shows 9,500 updates and 500 inserts. That confirms it matched most keys, and tells you whether a jump in row count came from inserts or from somewhere else. A DELETE reports numDeletedRows, and an UPDATE reports numUpdatedRows. Both also report numCopiedRows: rows that weren't changed but had to be rewritten because they shared a file with rows that were.
| Operation | Key metrics | What they tell you |
|---|---|---|
| WRITE (append or create) | numFiles, numOutputRows, numOutputBytes | How many rows, files and bytes the load wrote |
| MERGE | numSourceRows, numTargetRowsInserted, numTargetRowsUpdated, numTargetRowsDeleted | How the source rows were applied to the target |
| UPDATE | numUpdatedRows, numCopiedRows | Rows changed, and unchanged rows rewritten alongside them |
| DELETE | numDeletedRows, numCopiedRows, numRemovedFiles | Rows removed, and files rewritten or dropped |
| OPTIMIZE | numRemovedFiles, numAddedFiles, numRemovedBytes, numAddedBytes | How many small files were compacted into how many larger ones |
History is a query result, so you can filter it and pull individual map keys out of it. Wrap the command as FROM (DESCRIBE HISTORY table_name) and read keys with dot notation. This matters for OPTIMIZE. Auto compaction, liquid clustering and Z-ordering all show up as the same OPTIMIZE operation, and only the parameters tell them apart. Liquid clustering fills clusterBy, Z-ordering fills zOrderBy, and auto compaction sets auto to true.
SELECT
version,
timestamp,
CASE
WHEN operationParameters.clusterBy IS NOT NULL AND operationParameters.clusterBy <> '[]' THEN 'Liquid clustering'
WHEN operationParameters.zOrderBy IS NOT NULL AND operationParameters.zOrderBy <> '[]' THEN 'Z-ordering'
WHEN operationParameters.auto = 'true' THEN 'Auto compaction'
ELSE 'Manual OPTIMIZE'
END AS optimize_type,
operationParameters.auto AS is_auto_compaction,
operationParameters.clusterBy AS cluster_by,
operationParameters.zOrderBy AS z_order_by,
operationMetrics.numRemovedFiles AS files_compacted,
operationMetrics.numAddedFiles AS files_added,
operationMetrics.numRemovedBytes AS bytes_removed,
operationMetrics.numAddedBytes AS bytes_added
FROM (DESCRIBE HISTORY table_name)
WHERE operation = 'OPTIMIZE'
ORDER BY version DESC;Checkpoint 3 of 8· Check yourself
A nightly job appends rows to a Delta table partitioned by date. In DESCRIBE HISTORY, that append's operationParameters show "mode": "Append" and "partitionBy": "[]". What should you conclude?
For appends, partitionBy can show an empty array even though Delta still writes the rows using the table's existing partition schema. Use this field to check CREATE and OVERWRITE operations, not appends.
“The empty partitionBy value is expected. The data is still written to the correct partitions based on the table's existing partition schema.”Source: docs.databricks.com
Checkpoint 4 of 8· Exam question
An analyst runs DESCRIBE HISTORY orders LIMIT 5; and wants to understand what the returned operationMetrics column contains for a row where operation is MERGE. What does that column represent?
Correct answer: A — Quantitative details about the operation, such as the number of rows and files inserted, updated, or deleted by that commit
- A. Correct:
operationMetricsreports numeric outcomes of the commit, such as rows and files affected by inserts, updates, and deletes, letting an analyst quantify the scale of a MERGE without re-scanning the table. - B. Incorrect: the raw SQL text submitted by the user is not stored in
operationMetrics; operation-specific configuration instead appears in the separateoperationParameterscolumn. - C. Incorrect: column-level min/max statistics used for data skipping are maintained internally in the Delta transaction log's add-file actions, not exposed through the
operationMetricsfield ofDESCRIBE HISTORY. - D. Incorrect: compute configuration such as node type or autoscaling settings is a property of the cluster or SQL warehouse that ran the job, not something
DESCRIBE HISTORYrecords per commit.
3.Comparing versions to validate a change or track a trend
History tells you how much a commit changed. To see which rows changed, compare the data itself. Delta time travel (VERSION AS OF / TIMESTAMP AS OF / @) reads a table as it was at an earlier version, and the version numbers you need come straight from the version column of DESCRIBE HISTORY. Put two snapshots of the same table side by side and ordinary SQL shows the differences.
EXCEPT gives you the row-level differences. It returns the rows of the first query that are missing from the second. Say Friday's load is version 11 and last night's job wrote version 12. Then SELECT * FROM inventory_counts VERSION AS OF 12 EXCEPT SELECT * FROM inventory_counts VERSION AS OF 11 returns rows that are new or changed in version 12. Swap the two queries to find rows that were removed or changed. Both sides need the same number of columns with compatible types. If a column was added between the two versions, list the columns explicitly instead of using *, or Databricks raises NUM_COLUMNS_MISMATCH. EXCEPT removes duplicates by default. Use EXCEPT ALL if you need to catch a row that was loaded twice.
This is why metrics and a data comparison do different jobs. An OPTIMIZE commit reports large file counts in operationMetrics, yet the rows are unchanged. Comparing file or row counts from two history entries only estimates the difference and never names the rows. Rerunning OPTIMIZE or computing statistics doesn't compare versions at all. When the question is whether rows were unexpectedly added or removed, run EXCEPT on the two snapshots.
A join on a business key compares values instead of whole rows. Join the current table to an earlier snapshot ON source.userId = target.userId and you can put each key's old and new values side by side, or filter to keys whose amount changed. The same pattern can repair a table: a MERGE whose source is the table as it was yesterday, joined on the key, puts back values that were updated by mistake.
To track a trend, compare aggregates across time. Subtract an aggregate computed on an earlier snapshot from the same aggregate on the current table. The query below counts customers added in the last seven days without needing a created-date column. Change the offset, or point VERSION AS OF at successive versions, to build a week-over-week series.
SELECT
(
SELECT count(distinct userId)
FROM my_table
)
-
(
SELECT count(distinct userId)
FROM my_table TIMESTAMP AS OF date_sub(current_date(), 7)
) AS new_customersCheckpoint 5 of 8· Check yourself
The Delta table my_table has no created-date column, but a manager wants the number of distinct customers (userId) added in the last seven days. Which approach gives that number?
To track a trend, you compute the same aggregate on the current table and on a time-travel snapshot from seven days ago, then subtract one from the other. VERSION AS OF 7 means the table's seventh commit, not seven days ago. operationMetrics counts the rows each commit wrote, not distinct new customers. DESCRIBE HISTORY does not accept a temporal specification, and its userId column is the user who ran the commit.
“To query the number of new customers added over the last week:”Source: docs.databricks.com
Checkpoint 6 of 8· Exam question
A finance analyst wants to compare last Friday's inventory_counts table against the version created by yesterday's overnight OPTIMIZE job, to check whether any rows were unexpectedly added or removed between the two loads. Which approach lets them compare the row-level differences between two specific historical versions of the same table?
Correct answer: A — Query each version separately with VERSION AS OF, then use EXCEPT between the two result sets to isolate rows that differ
- A. Correct: selecting each version with
VERSION AS OFand applyingEXCEPTreturns the actual rows present in one snapshot but not the other, giving a precise row-level comparison between the two loads. - B. Incorrect:
operationMetricsgives aggregate counts for what a single commit changed, not a row-level diff between two arbitrary historical versions, so it can only approximate rather than isolate the differing rows. - C. Incorrect: re-running
OPTIMIZEcompacts and reorders data files for file-layout efficiency; it creates a new version and does not compare or preserve the two versions the analyst is trying to examine. - D. Incorrect:
ANALYZE TABLE ... COMPUTE STATISTICSrefreshes summary statistics used by the query optimizer for the current table state; it does not retain or expose a comparable snapshot of last week's data.
4.How long history is kept, and why it can outlive the data
A table property sets how far back table history goes, not the table's age or a workspace rule. delta.logRetentionDuration controls how long the transaction log keeps history, and its default is interval 30 days. Log files are cleaned up automatically after checkpointing. So a table that has existed for a year normally shows about a month of entries in DESCRIBE HISTORY. Delta doesn't archive older commits to another table, and the command doesn't read from the warehouse's query history. To audit further back, raise the property with ALTER TABLE or set it when you create the table.
Reading an old version needs both its log entry and its data files. Those two are kept on separate clocks. Time travel retention and VACUUM is governed by delta.deletedFileRetentionDuration, which defaults to 7 days. Under the defaults, then, a version between 8 and 30 days old can still appear in DESCRIBE HISTORY, with its user, operation and metrics, while a VERSION AS OF query against it fails. You can still audit what happened, but you can no longer run an EXCEPT comparison against that version.
If you need a 30-day comparison window, raise data retention to match: setting delta.deletedFileRetentionDuration to interval 30 days lines it up with the log default. The cost is storage, because more old data files are kept. In Databricks Runtime 18.0 and above, the log retention must be at least as long as the deleted-file retention. Neither setting turns history into a backup. Plan on comparing versions from the past 7 days unless both retention settings have been raised.
Checkpoint 7 of 8· Check yourself
A team must be able to run EXCEPT comparisons against any version of a Delta table from the past 30 days. The table uses the default retention settings, and VACUUM runs regularly. What should they change?
Reading an old version needs its log entry and its data files. The log already keeps 30 days by default. VACUUM removes data files after 7 days unless deletedFileRetentionDuration is raised to match. Metrics only hold counts, so they can't stand in for the rows.
“For example, to access 30 days of historical data, set delta.deletedFileRetentionDuration = "interval 30 days", which matches the default setting for delta.logRetentionDuration.”Source: docs.databricks.com
Checkpoint 8 of 8· Exam question
A pipeline owner is auditing customer_events and finds that DESCRIBE HISTORY only returns entries going back 30 days, even though the table has existed for over a year. Why does the history stop at that point by default?
Correct answer: A — The logRetentionDuration table property defaults to 30 days and controls how long transaction log entries are kept before older ones are cleaned up
- A. Correct: the
delta.logRetentionDurationtable property defaults to 30 days, after which older commit entries in the transaction log become eligible for cleanup, which is whyDESCRIBE HISTORYno longer shows them. - B. Incorrect: Delta Lake does not move old commits into a separate audit table; entries are simply retained in the transaction log for the configured duration and then eligible for removal, not relocated.
- C. Incorrect:
DESCRIBE HISTORYreads directly from the Delta transaction log on the table's storage location, not from a SQL warehouse query-history cache, so warehouse caching settings do not explain the cutoff. - D. Incorrect: Unity Catalog governs access control and discovery metadata for the table, but the length of Delta's commit history is controlled by the table's own
logRetentionDurationproperty, not a fixed Unity Catalog policy.
Sources1
Sources
(6)
Every claim above is drawn from one of these pages, quoted as it was written on the date shown.
- 1.https://docs.databricks.com/aws/en/tables/historyOfficial docs
“Run the DESCRIBE HISTORY command to retrieve information including the operations, user, and timestamp for each write to a table.”
↩︎ Auditing a table with DESCRIBE HISTORY“The operations are returned in reverse chronological order.”
↩︎ Auditing a table with DESCRIBE HISTORY“Catalog Explorer shows table history visually on the History tab.”
↩︎ Auditing a table with DESCRIBE HISTORY“Auto compaction, liquid clustering, and Z-ordering all appear in table history as OPTIMIZE operations.”
↩︎ Reading operationParameters and operationMetrics“USING my_table TIMESTAMP AS OF date_sub(current_date(), 1) source ON source.userId = target.userId”
↩︎ Comparing versions to validate a change or track a trend“To query the number of new customers added over the last week:”
↩︎ Comparing versions to validate a change or track a trend“Table history retention is determined by the table setting logRetentionDuration, which is 30 days by default.”
↩︎ How long history is kept, and why it can outlive the data“Log files are removed automatically after checkpointing table versions.”
↩︎ How long history is kept, and why it can outlive the data“determines the threshold VACUUM uses to remove data files no longer referenced in the current table version. The default is interval 7 days.”
↩︎ How long history is kept, and why it can outlive the data“In Databricks Runtime 18.0 and above, logRetentionDuration must be greater than or equal to deletedFileRetentionDuration.”
↩︎ How long history is kept, and why it can outlive the data“Don't use table history as a long-term backup solution for data archival.”
↩︎ How long history is kept, and why it can outlive the data“each operation that modifies a table creates a new table version”
↩︎ Key concept“To query a previous table version, you must retain both the log and the data files for that version”
↩︎ Exam trap 4“No records. OPTIMIZE compaction does not change the data in the table.”
↩︎ Prediction“Time travel and table history are controlled by different retention thresholds.”
↩︎ Prediction“For example, to access 30 days of historical data, set delta.deletedFileRetentionDuration = "interval 30 days", which matches the default setting for delta.logRetentionDuration.”
↩︎ Checkpoint - 2.
“The name must not include a temporal specification or options specification.”
↩︎ Auditing a table with DESCRIBE HISTORY - 3.
“The DESCRIBE HISTORY command returns 14 columns for Apache Iceberg and Delta Lake tables that describe the history of table operations.”
↩︎ Auditing a table with DESCRIBE HISTORY“The version of the table that was read to perform the write operation.”
↩︎ Auditing a table with DESCRIBE HISTORY“If you write into a table using the following methods, some columns aren't available: JDBC or ODBC Run a command using the REST API”
↩︎ Auditing a table with DESCRIBE HISTORY“The parameters of the operation (for example, predicates.)”
↩︎ Reading operationParameters and operationMetrics“The metrics of the operation (for example, number of rows and files modified.)”
↩︎ Reading operationParameters and operationMetrics“numCopiedRows | The number of rows just copied over in the process of updating files.”
↩︎ Reading operationParameters and operationMetrics“The partitionBy field in table history is only meaningful for CREATE and OVERWRITE operations that define or change a table's partition schema.”
↩︎ Reading operationParameters and operationMetrics“The metrics of the operation (for example, number of rows and files modified.)”
↩︎ Exam trap 1“You shouldn't use it to validate append operations.”
↩︎ Exam trap 2“operationMetrics | map | The metrics of the operation (for example, number of rows and files modified.)”
↩︎ Checkpoint“The empty partitionBy value is expected. The data is still written to the correct partitions based on the table's existing partition schema.”
↩︎ Checkpoint - 4.
“{"predicate":"[\"(spark_catalog.myschema.t.c1 = 3)\"]"}”
↩︎ Reading operationParameters and operationMetrics - 5.
“version is a long value that can be obtained from the output of DESCRIBE HISTORY table_spec.”
↩︎ Comparing versions to validate a change or track a trend - 6.https://docs.databricks.com/aws/en/sql/language-manual/sql-ref-syntax-qry-select-setopsOfficial docs
“EXCEPT [ALL | DISTINCT ] Returns the rows in subquery1 which are not in subquery2.”
↩︎ Comparing versions to validate a change or track a trend“If the number of columns differs, Databricks raises NUM_COLUMNS_MISMATCH.”
↩︎ Comparing versions to validate a change or track a trend“Returns the rows in subquery1 which are not in subquery2.”
↩︎ Exam trap 3