On this page
Row expectations (data_quality)¶
Applies expectation rules to the source view. mode: dqe emits a
@dp.temporary_view decorated with expectation decorators; mode: quarantine
emits a Delta dead-letter (DLQ) subsystem that routes violating rows to a
quarantine table. dqe reads a stream or a batch; quarantine reads only a
stream.
Minimal example¶
Add this entry to the actions list in your flowgroup.
- name: dq_orders
type: transform
transform_type: data_quality
source: v_orders
target: v_orders_validated
expectations_file: "expectations/orders.yaml"
mode: dqe
Options¶
Field |
Type |
Required |
Default |
Description |
|---|---|---|---|---|
|
string |
Yes |
— |
Input view name. |
|
string |
Yes |
— |
Path to a YAML expectations file, relative to project root. |
|
string |
No |
|
|
|
object |
Cond. |
— |
Required when |
|
string |
No |
inherited |
|
The expectations file holds the rules. The mapping format is shown here: each key
is a boolean SQL expression the row must satisfy, and each value sets a per-rule
action and optional name. Expectation formats
covers the list format and every check on a rule.
Key |
Type |
Default |
Description |
|---|---|---|---|
|
mapping key |
— |
A boolean SQL expression, e.g. |
|
string |
|
|
|
string |
the expression |
Rule name used as the key in the emitted expectation dict. |
Each action maps to a Lakeflow expectation decorator (dqe mode):
|
Decorator |
Behavior |
|---|---|---|
|
|
Logs a warning; keeps violating rows. Default. |
|
|
Drops violating rows. |
|
|
Fails the pipeline on any violation. |
In quarantine mode every rule is coerced to drop regardless of its
configured action; warn / fail rules trigger a validation warning. The
DLQ outbox table is derived as <dlq_table>_outbox. Create both tables with the
DDL in Quarantine (DLQ) configuration, which clusters them by
_dlq_source_table and enables deletion vectors.
# expectations/orders.yaml
order_id IS NOT NULL:
action: drop
name: valid_order_id
amount >= 0:
action: warn
name: non_negative_amount
Quarantine mode replaces the inline decorators with the DLQ subsystem:
- name: dq_orders
type: transform
transform_type: data_quality
source: v_orders
target: v_orders_validated
expectations_file: "expectations/orders.yaml"
mode: quarantine
quarantine:
dlq_table: main.ops.orders_dlq
source_table: main.bronze.orders
Read mode¶
A view is either streaming or batch, and Databricks requires a reader to read it
the same way (LHP-VAL-070, below). A dqe action with no readMode
takes the kind of the view it reads when another load or transform in the same
flowgroup produces that view:
a load or transform produces a view of the kind it reads: a
deltaload is batch unless it setsreadMode: stream, ajdbcload is batch, andcloudfilesandkafkaloads are streams;a
sqlload or transform is a stream exactly when its SQL readsSTREAM(...);a
schema,pythonordata_qualitytransform takes the kind of its own read, so a chain carries one kind through.
When the source is external to the flowgroup, or its kind is not known (a
python load, or a temp_table), the action defaults to stream. A
python load that returns a batch DataFrame therefore needs readMode: batch
on the data_quality action. An explicit readMode always wins.
A batch data_quality action that feeds a pass-through materialized view is
fused into the view; see Expectations.
A generated pipeline fails on Databricks when a view is read the other way, so
lhp validate checks every read of a view that a load or transform of the same
flowgroup produces, wherever both the view’s kind and the read are known. A
mismatch is LHP-VAL-070:
a stream read (
readStream, orSTREAM(view)in SQL) of a batch view fails;a batch read (
spark.read, or SQL withoutSTREAM()) of a streaming view fails;a standard streaming-table append flow that reads a batch view with
readMode: batchfails too, unless the write setsonce: true(a one-time backfill).
The message names both actions and suggests the readMode that fixes it.
Reads of external tables and of views from other flowgroups are not checked.
Test actions always read their source with batch SQL, so point them at tables or
batch views, not streaming views.
Common fields¶
Fields accepted by every transform_type. Type-specific fields are listed in
the options above.
Field |
Type |
Required |
Default |
Description |
|---|---|---|---|---|
|
string |
Yes |
— |
Action name, unique within the flowgroup. |
|
string |
Yes |
— |
Always |
|
string |
Yes |
— |
One of |
|
string |
Yes |
— |
Name of the produced view (or temporary table). Required for all transforms. |
|
string / list / mapping |
Yes |
— |
Upstream view name(s). Accepted shape and requirement vary per type — see this type’s options. |
|
string |
No |
auto |
Comment on the generated view/table. Defaults to an auto-generated string. |
|
bool / list |
No |
— |
Add operational metadata columns; a list selects column names. Honored by |
|
list |
No |
— |
Extra upstream table or view references added to the dependency graph. See Dependency analysis reference. |