Check Results¶
A check tells you whether your data passed. Often you also want to know which rows broke it, and how many rows of the table are affected. This section explains how vowl gets from a check to those answers:
| Page | What it covers |
|---|---|
| This page | The check result types, what a check gives you, and the scalar and row queries |
| How Attributed Rows Work | How vowl attributes failed rows and adds them up |
| Counting Mechanisms | The attribution methods vowl uses to attribute rows, and what each one costs |
| Annotating the Source Table | How vowl writes the attributed rows into your table |
| Capping Failed Rows | What changes when you limit how many failed rows vowl downloads |
Check result types¶
A check passes or fails on its scalar count. A failed check is a check
with the status FAILED, because its scalar count broke its limit.
A failed check tells you the table did not pass. The row counts answer a second question: how many rows of the table have issues? Only some checks can help answer it, depending on their type.
vowl puts each check through four conditions, in order. The first condition a check fails sets its type:
flowchart LR
c1{"1. It ran"} -->|✗| t1["Errored check"]
c1 -->|✓| c2{"2. It has a<br/>row query"}
c2 -->|✗| t2["Non-row-level check"]
c2 -->|✓| c3{"3. It sets an<br/>upper limit"}
c3 -->|✗| t3["Non-limiting check"]
c3 -->|✓| c4{"4. Its row query can be<br/>attributed to the table"}
c4 -->|✗| t4["Not attributable<br/>row-level check"]
c4 -->|✓| t5["Attributable<br/>row-level check"]
| Type | Description |
|---|---|
| Errored check | The check could not run. You get a message on why. |
| Non-row-level check | The check returns one number, such as an average. No row is at fault. |
| Non-limiting check | The check counts rows, but a high count is not bad. |
| Not attributable row-level check | The check returns rows with issues, but vowl can't attribute them to the table. |
| Attributable row-level check | The check returns rows with issues, and vowl attributes each to the table. |
Only attributable row-level checks that failed add rows to the row counts.
get_dq_metrics_df(by="check") shows the type of each check in its
row_level, attribution_method and attribution_note columns. A check passes or fails as usual
whatever its type, and a passed check can be row-level too. By default vowl
does not attribute a passed check (see Tolerated rows).
Errored check¶
The check could not run, so it has no scalar count and no failed rows. The
message column of get_check_results_df() says why.
Example: an errored check
quantity_is_filled points at a column that does not exist:
| check_name | status | message |
|---|---|---|
quantity_is_filled |
ERROR |
column "qty" does not exist |
If the check would have been row-level, it may have had failed rows that vowl never saw. The row counts of its table and dimension are then marked approximate.
attribution_note: check ended in ERROR
Non-row-level check¶
The check returns one number that is not a count of rows, so no row is at fault.
Example: a non-row-level check
average_price_in_range runs:
| AVG(price) |
|---|
| 0.14 |
A SQL check points at rows when its query holds one COUNT, such as
COUNT(*), COUNT(quantity) or COUNT(DISTINCT item), or lists rows with
no aggregate. These checks don't:
| Check | Example |
|---|---|
An aggregate other than COUNT |
SELECT AVG(price) FROM orders, or SUM, MIN, MAX |
| More than one aggregate | SELECT COUNT(*), MAX(price) FROM orders |
| A distinct count of combined values | SELECT COUNT(DISTINCT (item, price)) FROM orders |
A query vowl can't parse, or with no FROM |
SELECT 1 |
A unit other than rows |
unit: percent |
| A check type with no SQL behind it | Custom and unsupported check types |
attribution_note: not a row-level check
Non-limiting check¶
The check counts rows, but a high count is not bad. Its rows are not rows with issues.
Example: a non-limiting check
Say a check needs at least 3 orders with a price above 0:
| order_id | item | price | quantity |
|---|---|---|---|
| 1 | apple | 1.50 | 3 |
| 4 | eggs | 3.20 | 2 |
The count is 2, so the check fails. But apple and eggs are the good rows.
A check only points at rows with issues when its operator means "no more than this many":
| Operator | Sets an upper limit |
|---|---|
mustBe: 0 |
Yes. No failed row is allowed. |
mustBeLessThan, mustBeLessOrEqualTo, mustBeBetween: [0, n] |
Yes. Some failed rows are allowed. |
mustBeGreaterThan, mustBeGreaterOrEqualTo |
No. The check counts good rows, such as "at least 100 are paid". |
mustBe: n with n above 0, mustNotBe, mustBeBetween: [a, b] with a above 0, mustNotBeBetween |
No. When the total is off, no single row is at fault. |
attribution_note: operator does not set an upper limit
Not attributable row-level check¶
The check returns rows with issues, but vowl can't tell which row of the table each one stands for.
Example: a not attributable row-level check
Say a check returns only the item column:
| item |
|---|
| bread |
| milk |
| bread |
The two bread rows could be any of the bread rows in orders.
A check can be not attributable in two ways:
| Kind | When | Its failed rows |
|---|---|---|
| Never attributable | Its failed rows lack the match key. This happens on every run. | Become a residue |
| Not attributable this run | Its failed rows have the match key, but something went wrong on this run. The table or the failed rows could not be downloaded, the values could not be turned into match keys, max_failed_rows cut the failed rows short, or its row query failed in the data source. See When something goes wrong. |
Are annotated as usual, unless the table could not be downloaded |
See Attributed rows for every reason.
The check still has a scalar count, reported in
vowl.check.row.scalar_count. It has no vowl.check.row.count, and it adds
nothing to the row counts of its dimension, its schema or the run, and
checks_not_attributable counts it.
Attributable row-level check¶
The check returns rows with the match key: every column of the table, or its primary key. vowl attributes each one to a row of the table. These are its attributed rows: exactly which rows of the table have issues.
Example: an attributable row-level check
quantity_is_filled runs:
| order_id | item | price | quantity |
|---|---|---|---|
| 3 | milk | 0.00 |
The failed row has every column of orders, so vowl finds the row of
orders with the same values. It is row 3:
| Row | order_id | item | price | quantity |
|---|---|---|---|---|
| 1 | 1 | apple | 1.50 | 3 |
| 2 | 2 | bread | -2.00 | 1 |
| 3 | 3 | milk | 0.00 | |
| 4 | 4 | eggs | 3.20 | 2 |
| 5 | 2 | bread | -2.00 | 1 |
order_id alone is not enough here, because rows 2 and 5 share
order_id 2. If the contract declared order_id as a primary key with no
repeats, a failed row would only need order_id.
Tolerated rows¶
A tolerated row is a failed row of a row-level check that passed.
Example: a tolerated row
Say quantity_is_filled allows fewer than 2 empty quantities:
| order_id | item | price | quantity |
|---|---|---|---|
| 3 | milk | 0.00 |
Its scalar count is 1, so it passes, and milk is a tolerated row.
By default the completeness dimension has failed_rows 0. With
fetch_tolerated_rows=True, it has failed_rows 1. If milk also
fails a check that failed, such as price_must_be_positive, the totals
for orders don't change either way.
A passed check still reports its scalar count in
vowl.check.row.scalar_count. Its vowl.check.row.count follows the same
rule as its tolerated rows: FAILED is 0 by default, and its attributed rows
with fetch_tolerated_rows=True. By default vowl does not attribute its rows. It runs no extra query for it,
adds nothing to the row counts and leaves its rows out of every output.
Its attribution_note is passed, not attributed, and it is not counted in
checks_not_attributable.
fetch_tolerated_rows
attributes passed checks too, so the row counts hold every row that broke a
row-level check, whatever the tolerance. You set it per run, not in the
contract:
from vowl import ValidationConfig, validate_data
config = ValidationConfig(fetch_tolerated_rows=True)
result = validate_data("orders.yaml", df=df, config=config)
Every output then holds the rows of the passed checks too, and marks them per check, so you can tell them apart from failed checks. All of them read the check's rows from one fetch, so they agree.
| Output | Setting off (default) | fetch_tolerated_rows=True |
|---|---|---|
get_annotated_output() |
Failed checks only | Adds tolerated checks, their check_info items "tolerated": true |
get_output_dfs() |
Failed checks only | Adds tolerated checks, with a tolerated column |
get_consolidated_output_dfs() and the grouped failed-rows CSVs |
Failed checks only | Adds tolerated rows, with a tolerated_check_ids column |
show_failed_rows() |
Failed checks only | Adds tolerated checks, labelled (tolerated) |
| DQ metrics | Failed checks only | A row picked out by any of these checks counts as failing |
OpenTelemetry failed_rows_sample |
Failed and errored checks | Failed and errored checks |
The OpenTelemetry failed_rows_sample is off by default
(max_failed_rows_sample=0). When you
turn it on, it
samples the failed rows of FAILED and ERROR checks, never of passed
checks.
A row picked out only by a tolerated check counts as failing in the DQ metrics. That is what the setting asks for.
Example: a tolerated check in check_info
With fetch_tolerated_rows=True, the milk row of orders lists both
checks it broke:
| order_id | item | check_info |
|---|---|---|
| 3 | milk | [{"check_name": "price_must_be_positive"}, {"check_name": "quantity_is_filled", "tolerated": true}] |
quantity_is_filled passed, so its item is marked tolerated.
In the grouped failed-rows view, the same row has check_ids
price_must_be_positive, quantity_is_filled and tolerated_check_ids
quantity_is_filled. In the DQ metrics it fails, because
price_must_be_positive failed.
A passed check is attributed the same way as a failed one, so it can need the table downloaded. On an untested data source, the plain-filter checks of that table are then matched on the downloaded table too (see Counting Mechanisms).
What a check gives you¶
Every check gives its query output: the scalar count and the failed rows. vowl then attributes the failed rows to get the attributed rows. Each one feeds a different part of the results:
flowchart LR
check["A check"] --> sc["Scalar count"]
check --> fr["Failed rows"]
fr -->|attribute| ar["Attributed rows"]
sc --> u1["Pass or fail,<br/>scalar_count DQ metrics"]
fr --> u2["show_failed_rows(),<br/>get_output_dfs(), residues"]
ar --> u3["Row counts, annotated output,<br/>row count DQ metrics at every level"]
| Result | Where you see it |
|---|---|
| Scalar count | actual in the summary, failed_rows_count (failed checks only), scalar_count in get_dq_metrics_df(by="check") |
| Failed rows | show_failed_rows(), get_output_dfs(), residues |
| Attributed rows | attributed_rows in get_dq_metrics_df(by="check"), and failed_rows per schema and per dimension |
Scalar and row queries¶
You write one query per SQL check, and vowl gets two queries out of it. One returns the scalar count, and the other returns the failed rows.
| Query | What it returns | When it runs |
|---|---|---|
| Scalar query | The number that decides pass or fail | Always |
| Row query | The rows behind that number | When something needs the rows. A default save() runs it for every row-level check |
The row query returns the rows of its own result. They are rows of the source
table only when the query is a plain filter of that table. A DISTINCT, a
GROUP BY or a join changes what its rows are, and that decides whether vowl
can attribute them. A check
that returns an average, a sum, a minimum or a maximum has no row query.
You can write either one, and vowl builds the other:
So a check written as COUNT(*) with mustBe: 0 still gives you the rows
behind the count. This works for a check that joins two tables too, such as
"every payroll row has a matching employee":
SELECT COUNT(*)
FROM demo_employee_payroll payroll
LEFT JOIN demo_employee_list ref
ON payroll.employee_id = ref.employee_id
WHERE ref.employee_id IS NULL
The scalar query tells you that some payroll rows have no matching employee. The row query tells you which ones. The columns those rows hold depend on how the query is written, and decide whether vowl can attribute them to the source table. See Annotating the failed rows of a cross-table check.
How vowl builds the other query
vowl does not search and replace the text COUNT(*). It reads your query
with sqlglot, a Python library that
parses and translates SQL, and swaps the selected columns in the parsed
query. Subqueries, WITH clauses and syntax specific to one database come
through unchanged.
When each query runs¶
The scalar query always runs, because vowl needs it to pass or fail the check. A check that passes costs one query, unless something asks for the rows of passed checks too.
The row query runs when a check fails and something needs its rows:
- The row counts, such as
get_dq_metrics_df()and the DQ metrics. Where it can, vowl runs the row queries inside the data source as part of one attribution query, so only numbers come back. - The annotated output, from
get_annotated_output()orsave(). show_failed_rows()andget_output_dfs().
It also runs for a passed check under
fetch_tolerated_rows, and for
get_output_dfs(scope="all"). A default save() writes all_query_outputs,
so it runs the row query of every row-level check, passed or failed. Leave
all_query_outputs out of outputs to skip that.
Query performance
The wrapping vowl adds, a subquery or SELECT * in place of COUNT(*),
does not slow the query down. Databases flatten these standard shapes
when they plan the query. A LEFT JOIN ... WHERE ref.key IS NULL, which
finds rows with no match in the other table, usually runs as one pass
over the join key. By default the row query returns every failed
row. On a very large table with many failed rows, see
Capping Failed Rows.
Attributed rows¶
The query output can't give the row counts on its own, because a row can fail more than one check.
Example: adding up the scalar counts
Three checks run on an orders table. A ✗ marks a failed row of the
check:
| Row | order_id | item | price | quantity | price_must_be_positive |
quantity_is_filled |
order_id_is_unique |
|---|---|---|---|---|---|---|---|
| 1 | 1 | apple | 1.50 | 3 | |||
| 2 | 2 | bread | -2.00 | 1 | ✗ | ✗ | |
| 3 | 3 | milk | 0.00 | ✗ | ✗ | ||
| 4 | 4 | eggs | 3.20 | 2 | |||
| 5 | 2 | bread | -2.00 | 1 | ✗ | ✗ |
Rows 2, 3 and 5 each fail more than one check:
| Check | Scalar count | Rows of orders |
|---|---|---|
price_must_be_positive |
3 | 2, 3, 5 |
quantity_is_filled |
1 | 3 |
order_id_is_unique |
2 | 2, 5 |
| Total | 6 | 2, 3, 5 |
The scalar counts add up to 6, but only 3 rows have issues.
A check can also change the rows it returns, for example with DISTINCT or a join (see
Checks can change the rows they return).
So vowl attributes each failed row to a row of the table, then counts each row once per dimension, schema and run:
flowchart LR
fr["Failed rows of a row-level check"] --> a{"Attributable?"}
a -->|Yes| ar["Attributed rows"] --> rc["Row counts"]
a -->|"No, never attributable"| res["Residue,<br/>left out and flagged"]
a -->|"No, not this run"| skip["Left out and flagged"]
| Outcome | Example | Row counts | Annotated output |
|---|---|---|---|
| Attributed | WHERE price <= 0 |
Counted, each row once | Each row marked with its checks |
| Never attributable | The failed rows lack some columns of the table | Left out, marked approximate | The failed rows become a residue |
| Not attributable this run | The failed rows were cut off by max_failed_rows |
Left out, marked approximate | Annotated as usual |
How Attributed Rows Work explains how vowl
attributes the rows, every attribution_note a check can be left out for, and how the
attributed rows add up to the row counts at each level.