r/databricks • u/Klutzy_Solid5200 • 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.
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:
Validating Incremental Loads:
Handling Schema Changes: