EX-17: Delta Live Tables (DLT) Quality Expectations
Track: Quality & Assertions • Difficulty: Intermediate • Mastery Points: 150 PTS
Business Problem Scenario
In production lakehouse pipelines, Delta Live Tables (DLT) enforces data quality expectations in-flight during streaming ingestion. Fatal accounting flaws that violate core entity identity must immediately halt pipeline execution (ON VIOLATION FAIL UPDATE), preventing corrupted state from propagating. Conversely, minor non-critical anomalies, such as individual overdraft breaches, should drop the defective rows (ON VIOLATION DROP ROW). Note on Lakehouse architecture: ON VIOLATION DROP ROW discards invalid records from the target; true data quarantine requires a separate downstream streaming branch routing dropped records to an audit table.
Engineering Objective
Write a DLT streaming table definition for silver.core_balances_clean declaring tiered expectation constraints over STREAM(bronze.core_balances). • Tiered Expectations Specification: - Constraint valid_account: EXPECT (account_id IS NOT NULL) ON VIOLATION FAIL UPDATE - Constraint within_overdraft_limit: EXPECT (ledger_balance >= -5000.00) ON VIOLATION DROP ROW • Architectural Note: Discarding invalid rows (DROP ROW) prevents corrupt balance calculations, while identity nulls halt the update to prevent orphan records. Key Concepts: - DLT Expectations: Declarative quality rules embedded in streaming pipelines. - Fatal vs. Drop Row Violations: Halting execution on critical structural failures versus filtering individual non-fatal records.
Target Table: bronze.core_balances (account_id STRING, balance_date DATE, ledger_balance DECIMAL(18,2))
Verification & Architecture Insights
In Delta Live Tables and Lakeflow Spark Declarative Pipelines, distinguishing fatal pipeline halts from drop-row cleaning prevents corrupted records from entering gold aggregates (in production, drop actions are paired with quarantine logging).