Skip to content

Validating nullability, cardinality, and ranges

Databricks enforces data quality through Delta Lake table constraints (NOT NULL, CHECK) that validate nullability and value ranges at write time, while cardinality and more complex business-rule checks are typically implemented using SQL aggregations or Lakeflow Declarative Pipelines (formerly Delta Live Tables) expectations. Understanding how constraint violations behave and where each validation technique fits is essential for building reliable data pipelines.

1 · Learn the must-know

  • Delta Lake supports NOT NULL and CHECK constraints via ALTER TABLE ADD CONSTRAINT, and any write violating them fails the entire transaction (no partial writes).
  • CHECK constraints use boolean SQL expressions (e.g., CHECK (age >= 0 AND age <= 120)) for range validation, but cannot reference subqueries or non-deterministic functions.
  • When adding a constraint to an existing table, Databricks first validates all existing rows and will fail the ALTER TABLE statement if any violate the new rule.
  • Cardinality checks (e.g., ensuring a column has expected distinct value counts or detecting unexpected duplicates) are not native Delta constraints and must be implemented with SQL (COUNT DISTINCT, GROUP BY HAVING) or custom validation logic.
  • Lakeflow Declarative Pipelines (formerly Delta Live Tables) offer built-in expectations (expect, expect_or_drop, expect_or_fail) that let you define nullability, range, and cardinality rules declaratively and choose whether to warn, drop, or fail on violations.
  • Constraints are metadata-level and enforced only on write; they do not retroactively validate data written before the constraint existed unless you explicitly run a validation pass.

2 · Check your understanding

Check this objectiveFree · always available

A data engineer manages a Delta table named sales that currently allows null values in the customer_id column. The engineer must guarantee that no future write, from any job or user, can insert a null customer_id into this table. Which statement accomplishes this?

Your objective map0 tried · 0 answered correctly · 77 untouched

What you have tried across DP-750's objectives, not a readiness score.

Set up and configure an Azure Databricks environment15-20% of the exam0 of 13 tried
Secure and govern Unity Catalog objects15-20% of the exam0 of 12 tried
Prepare and process data30-35% of the exam0 of 28 tried
Deploy and maintain data pipelines and workloads30-35% of the exam0 of 24 tried

3 · Keep going