Skip to content

Commit 3a775bc

Browse files
committed
Fold the Custom Quality Checks docs page into Custom Quality Rules as User-defined quality rules
1 parent 4f86eb6 commit 3a775bc

4 files changed

Lines changed: 130 additions & 149 deletions

File tree

‎docs/docs/quality-rules/custom-quality-checks.md‎

Lines changed: 0 additions & 133 deletions
This file was deleted.

‎docs/docs/quality-rules/custom.md‎

Lines changed: 124 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
---
22
sidebar_position: 4
33
title: "Custom Quality Rules"
4-
description: "Engine-specific quality checks expressed in the native syntax of an engine such as DQX, SodaCL, or Great Expectations."
4+
description: "Engine-specific quality checks expressed in the native syntax of an engine such as DQX, SodaCL, or Great Expectations, and user-defined SQL checks run by datacontract test."
55
---
66

77
# Custom Quality Rules
@@ -10,27 +10,138 @@ A `type: custom` rule carries a check written in the **native syntax of a specif
1010

1111
Custom rules are consumed by the matching engine — typically via the corresponding [exporter](../exports/index.md) — rather than being compiled to portable SQL.
1212

13-
:::note
14-
`datacontract test` does not run custom quality rules except for those with `engine: datacontract-cli`. Consider `type: sql` as an executed alternative.
15-
:::
13+
## User-defined quality rules
1614

17-
## Custom quality checks
15+
With `engine: datacontract-cli`, a custom rule uses a custom quality check: a SQL check defined **once**, outside any contract, and used **by its ID** from as many contracts as need it. The contract names the check and supplies its arguments; the check holds the query.
1816

19-
With `engine: datacontract-cli`, a custom rule uses a [custom quality check](./custom-quality-checks.md): a parameterised SQL check defined once in a folder and run by `datacontract test`.
17+
```yaml
18+
schema:
19+
- name: orders
20+
properties:
21+
- name: amount
22+
logicalType: number
23+
quality:
24+
- type: custom
25+
engine: datacontract-cli
26+
implementation:
27+
check: between
28+
arguments:
29+
min: 0
30+
max: 10000
31+
```
32+
33+
Point `datacontract test` at the folder the checks live in:
34+
35+
```bash
36+
datacontract test datacontract.yaml --custom-quality-checks ./custom-quality-checks
37+
```
38+
39+
or set `DATACONTRACT_CUSTOM_QUALITY_CHECKS`. See the [`test` command reference](../commands/test.md).
40+
41+
### Defining a check
42+
43+
The folder holds one YAML file per check. The file name is the check's ID (`between.yaml` defines `between`). IDs are unique and must not contain whitespace or any of `/ \ % ; # ?`.
44+
45+
```yaml
46+
# custom-quality-checks/between.yaml
47+
name: Value range
48+
description: All ${column} values are between ${arguments.min} and ${arguments.max}.
49+
owner: data-platform
50+
dimension: conformity
51+
arguments:
52+
min:
53+
max:
54+
queries:
55+
default: |
56+
SELECT COUNT(*) FROM ${table}
57+
WHERE ${column} < ${arguments.min} OR ${column} > ${arguments.max}
58+
mustBe: 0
59+
```
60+
61+
| Key | Meaning |
62+
|---|---|
63+
| `name` | A short display name (optional, only used when exporting to Entropy Data). |
64+
| `description` | What the check verifies. Becomes the check's name in the results, with the placeholders and arguments filled in, unless the rule has a `description` of its own. |
65+
| `owner` | Who maintains the check. Documentation only. |
66+
| `dimension` | The [quality dimension](./index.md#quality-dimensions) the check measures. A `dimension` on the rule takes precedence. |
67+
| `arguments` | The arguments the check takes, each with an optional `type` and `default`. See [Arguments](#arguments). |
68+
| `queries` | At least one query, keyed by SQL dialect or `default`. |
69+
| `mustBe`, `mustBeGreaterThan`, … | The default expected result, one of the [SQL rule comparators](./sql.md#comparators). |
70+
71+
### Arguments
72+
73+
A check declares its arguments under `arguments`, and a rule passes their values under `implementation.arguments`. `${arguments.<argumentName>}` in the check definition gets replaced by the respective value:
74+
75+
```yaml
76+
# custom-quality-checks/recent_rows.yaml
77+
arguments:
78+
timestamp_column: {type: identifier}
79+
days: {type: number, default: 1}
80+
queries:
81+
default: |
82+
SELECT COUNT(*) FROM ${table}
83+
WHERE ${arguments.timestamp_column} >= CURRENT_DATE - ${arguments.days} * INTERVAL '1' DAY
84+
mustBeGreaterThan: 0
85+
```
86+
87+
```yaml
88+
# datacontract.yaml
89+
implementation:
90+
check: recent_rows
91+
arguments:
92+
timestamp_column: created_at
93+
days: 7
94+
```
95+
96+
The `type` in the check definition specifies how arguments are parsed:
97+
98+
| Type | Becomes | Example |
99+
|---|---|---|
100+
| `any` (default) | An SQL literal; a list becomes comma-separated literals, as in `IN (...)` | `EUR` → `'EUR'`, `[A, B]` → `'A', 'B'` |
101+
| `number` | A number literal | `"7"` → `7` |
102+
| `identifier` | A column or table name, quoted where needed like the [placeholders](./sql.md#placeholders) | `order date` → `"order date"` |
103+
104+
Values are never inserted as raw SQL. Inside a single-quoted string, an `any` or `number` argument is inserted as escaped text, as in `LIKE '%${arguments.text}%'`.
105+
106+
### Placeholders
107+
108+
The queries use the same placeholders as [SQL rules](./sql.md#placeholders) — `${table}`, `${column}`, `${schema}`, and so on. A check whose queries use `${column}` (or `${field}`, `${property}`) can only be declared on a property. As in placeholders, the `$` in an argument reference is optional: `{arguments.min}` works the same as `${arguments.min}`.
109+
110+
### Dialects
111+
112+
A run uses the query for the [SQL dialect of the server](./sql.md#sql-dialect), and otherwise the `default` query (if it exists):
113+
114+
```yaml
115+
queries:
116+
default: |
117+
SELECT COUNT(*) FROM ${table}
118+
WHERE ${arguments.timestamp_column} >= CURRENT_DATE - ${arguments.days} * INTERVAL '1' DAY
119+
tsql: |
120+
SELECT COUNT(*) FROM ${table}
121+
WHERE ${arguments.timestamp_column} >= DATEADD(day, -${arguments.days}, CAST(GETDATE() AS date))
122+
```
123+
124+
The keys are the dialect names in the [SQL dialect table](./sql.md#sql-dialect), so a check for a `mysql` server needs a `duckdb` query. Write the `default` query in ANSI SQL. Note that on SAP HANA, only the `default` query runs.
125+
126+
### Overriding the expected result
127+
128+
The check's expected result is a default. A comparator on the rule replaces it:
20129

21130
```yaml
22131
quality:
23132
- type: custom
24133
engine: datacontract-cli
25134
implementation:
26-
check: between
135+
check: recent_rows
27136
arguments:
28-
min: 0
29-
max: 10000
137+
timestamp_column: created_at
138+
mustBeGreaterThan: 10000
30139
```
31140

32141
## Databricks DQX
33-
142+
:::note
143+
`datacontract test` does not run custom quality rules except [user-defined quality rules](#user-defined-quality-rules) (`engine: datacontract-cli`). Consider `type: sql` as an executed alternative.
144+
:::
34145
```yaml
35146
schema:
36147
- name: events
@@ -54,7 +165,9 @@ schema:
54165
Export these to a DQX check file with [`datacontract export dqx`](../exports/dqx.md).
55166

56167
## SodaCL
57-
168+
:::note
169+
`datacontract test` does not run custom quality rules except [user-defined quality rules](#user-defined-quality-rules) (`engine: datacontract-cli`). Consider `type: sql` as an executed alternative.
170+
:::
58171
```yaml
59172
schema:
60173
- name: orders
@@ -68,10 +181,6 @@ schema:
68181

69182
Export to a SodaCL file with [`datacontract export sodacl`](../exports/sodacl.md).
70183

71-
:::warning
72-
Raw SodaCL custom checks (`type: custom`, `engine: soda`) are **no longer executed** by `datacontract test` since `soda-core` was removed; such a rule is reported as a warning. Migrate it to a [SQL rule](./sql.md) (`type: sql`) to keep it executable, or keep it as a custom rule purely for the SodaCL export.
73-
:::
74-
75184
## Other engines
76185

77186
The same pattern applies to other engines (for example Great Expectations). Provide `engine` and an `implementation` understood by that engine, and use the matching [exporter](../exports/index.md) to generate its native artifact.

‎docs/docs/quality-rules/index.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ ODCS defines four `type`s of quality rule. Each has its own page:
4545
</a>
4646
<a className="doc-card" href="/quality-rules/custom">
4747
<img src="/img/icons/database.svg" alt="" />
48-
<span><span className="doc-card-title">Custom</span><span className="doc-card-desc">Engine-specific checks (e.g. DQX, SodaCL) and reusable custom quality checks.</span></span>
48+
<span><span className="doc-card-title">Custom</span><span className="doc-card-desc">Engine-specific checks (e.g. DQX, SodaCL) and user-defined quality rules.</span></span>
4949
</a>
5050
</div>
5151

‎docs/static/staticwebapp.config.json‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,11 @@
117117
"redirect": "/scheduling",
118118
"statusCode": 301
119119
},
120+
{
121+
"route": "/quality-rules/custom-quality-checks",
122+
"redirect": "/quality-rules/custom#user-defined-quality-rules",
123+
"statusCode": 301
124+
},
120125
{
121126
"route": "/assets/*",
122127
"headers": {

0 commit comments

Comments
 (0)