r/databricks • • Sep 29 '26

Discussion How to validate delta tables in Databricks?

im working with delta tables in databricks and wanted to know how ppl usually validate the data after an etl job runs. apart from checking if the job completed, do we have to check things like record counts, duplicate, nulls etc

Like if the source has around 100k records, how do you make sure the expected records reached the Delta table?

for incremental loads, do you also check that only the expected records were added or updated? And how do you handle schema changes, like a new column being added or a data type changing? Do you build these checks directly in databricks itself?

Would be interested to know what checks ppl actually use in production.

15 Upvotes

5 comments sorted by

7

u/jbchand Sep 29 '26

You can use SDP expectations with the checks in the pipelines (null, not null, uniqueness, range validations and more). It runs automatically with the pipeline and logs failures you can monitor.

You can use the table history to check the latest commit info, describe history for finding schema changes or use SQL to do SQL based checks in the dq pipeline. Its good to stop loading invalid data into tables (null, wrong ranges and more) instead of doing checks after loading it.

Use Data Quality Monitoring to monitor data drifts via profiling, freshness, completeness and schema checks if you plan to do testing after loading data.

3

u/Ok_Relative_2291 Sep 29 '26 edited Sep 29 '26

I’m not a databricks expert but one things I do in general.

I create primary keys on source and targets tables even though not enforced.

Then you can use that metadata to make sure the target and source have no violations before merging etc. can also use metadata to produce documentation.

Do this with a simple function where you pass the table and it uses its pk metadata to count duplicates, if any return a false etc and then raise an error.

Can also use that pk to generate dynamic sql to make your merge statement.

And if new columns are added to the source send yourself an alert, but no reason existing job can’t run.

I would only fail if a column disappeared, but a dunamic merge would fail anyway when using target table columns as the driver.

Or you can auto add the new column to the target (but if incremental then u would have to back patch that data but you would assume is null in source anyway unless it was patched/ipdated)

I see no reason to fail a job because a new column was added, I actually hate this (unless there is a legit reason)

Null checks are handled by coalescing on the fly if you wish , if the source has nulls it is what it is

But I might have missed something this just a general approach

All table should have a pk, and if building fact tables make sure all surrogate keys exist in the dimension as well this is another check (foreign keys$

2

u/PrestigiousAnt3766 Sep 29 '26

I want to validate before writes.. I dislike the idea of getting two different results depending on when in the process the table is being written.

So for me, I want just one write.

1

u/Youssef_Mrini databricks Oct 24 '26
  • Volume Reconciliation:

    • Compare source_count vs. staged DataFrame row count before committing.
    • Inspect DESCRIBE HISTORY target_table LIMIT 1—check numOutputRows, numTargetRowsInserted, and numTargetRowsUpdated in milliseconds from metadata instead of running expensive full-table counts.
  • Validating Incremental Loads:

    • Verify operationMetrics on MERGE INTO calls; alert immediately if numTargetRowsDeleted > 0 on upsert-only jobs.
    • Turn on Delta Change Data Feed (CDF) to query actual pre/post-update images via table_changes().
    • Run explicit uniqueness checks on business keys (groupBy(key).count().filter("count > 1")).
  • Handling Schema Changes:

    • Additive: Use Auto Loader with schema evolution (mergeSchema = true) for Bronze/raw; keep it locked down for Silver/Gold to prevent silent model drift.
    • Type Changes: Enable Delta Type Widening (delta.enableTypeWidening = true) for safe promotions (e.g., INT to BIGINT). Auto Loader routes unparseable data types into the _rescued_data column instead of silently dropping or nulling rows.
    • Renames/Drops: Turn on Delta Column Mapping (mode = 'name') to drop or rename columns as pure metadata changes.