Tutorial: your first rules
This tutorial writes the rulesRule It applies a pattern to a field; the pattern gives it its dimension and a default severity. The rules that count are the ones on main, the approved version. of one field, then a few more, explaining
each choice as it comes. It takes about half an hour. By the end you will
know how a rule is read, why it fails, passes or does not apply, and how it
reaches main.
Every key used here is described in Rule language, and every patternPattern A reusable way of validating (required, format, fresh and eleven more). Each rule is a pattern applied to a field with its condition. in Rule patterns. The datasetDataset One table of a source as Quality Data reads it: a name, its fields and the rules that check them., its fields and its values are synthetic.
The dataset
Section titled “The dataset”A dataset of customers, clients, whose mappingMapping How a dataset's table is read: which column each field reads and its type, the record key, each field's priority and the roles of some fields. has these fields:
| Field | Holds |
|---|---|
ClientType |
PERSON or COMPANY |
Mobile |
A mobile phone number |
Occupation |
EMPLOYEE, STUDENT, RETIRED… |
Employer |
The employer’s name, for employees |
BirthDate |
The customer’s birth date |
LastUpdate |
When the customer’s data was last updated |
HasIncome |
YES or NO |
Status |
ACTIVE or CLOSED |
ClosedOn |
When the customer’s account was closed |
RepDocument |
A company’s legal representative’s document |
The rulesRule It applies a pattern to a field; the pattern gives it its dimension and a default severity. The rules that count are the ones on main, the approved version. check the dataset at a cut: the date its data was taken. Keep that in mind; it comes back in step 6.
Before you start
Section titled “Before you start”- The datasetDataset One table of a source as Quality Data reads it: a name, its fields and the rules that check them. is mapped: its fields are in the Explorer, under Lake. MappingMapping How a dataset's table is read: which column each field reads and its type, the record key, each field's priority and the roles of some fields. a table is done once, by whoever manages datasets, and it takes the dataset’s first cutCut The dataset's data as it was on one date, copied into the lake so it can be measured again without touching the source. Every figure of a report refers to that moment. by itself, so Test has data to run on: see Map a table into a dataset.
- If the data of that first cut could not be extracted, Test says the dataset has no cut extracted yet: take one with Run now, under the dataset’s Cuts, as Run and schedule cuts explains.
- Your permissions: Edit rules on the dataset to write rulesRule It applies a pattern to a field; the pattern gives it its dimension and a default severity. The rules that count are the ones on main, the approved version.
(without it, the + beside a field does not show); Approve rules and
mappings and Manage datasets to deploy to
main. With only the first, you save draftsDraft A change to a dataset's rules kept apart from main, usually saved by an author who may edit rules but not approve them, until someone who may approve reviews it and approves or discards it. that someone else approves.
1. Open the field’s file
Section titled “1. Open the field’s file”Each field has its own rulesRule It applies a pattern to a field; the pattern gives it its dimension and a default severity. The rules that count are the ones on main, the approved version. file, named as the field: Mobile.yaml. In
the Explorer, + beside Mobile opens it (new if there is none) with a
rule ready to fill. A file always starts by naming its datasetDataset One table of a source as Quality Data reads it: a name, its fields and the rules that check them.:
dataset: clients
rules:2. A first rule: the mobile is required
Section titled “2. A first rule: the mobile is required”dataset: clients
rules: - id: MOB-01 field: Mobile check: required alert: The client has no mobile numberFour keys, and each says one thing:
idnames the rule for good. Results are kept by it over time, so keep it when the rule changes.fieldis the field it checks.checkis the pattern: hererequired, the field has a value.alertis what the person who fixes the record reads. Write it for them.
Nothing else is needed: required already has a dimensionDimension The kind of quality a rule measures (completeness, validity, timeliness…), given by its pattern. (completenessCompleteness Quality dimension: the data is present when it must be.)
and a severitySeverity A rule's weight in the ICD: blocking 1.0, major 0.6 and minor 0.3. The pattern gives a rule its default severity. (blocking). Empty means no value, an empty text, or only
spaces; a filler the datasetDataset One table of a source as Quality Data reads it: a name, its fields and the rules that check them. declares, such as UPDATE, counts as empty
too.
Look at As read beside the editor: it says the rule in words. Read it every time you write one; it is the quickest way to catch a rule that does not say what you meant.
3. A second rule: the mobile has its form
Section titled “3. A second rule: the mobile has its form”- id: MOB-02 field: Mobile check: format pattern: \d{10} alert: The number does not have ten digitsformat takes your own pattern, a regular expression that must match
the whole value (here, ten digits), or a named format Quality Data
maintains, such as email.
Notice what happens with an empty mobile: MOB-01 fails, and MOB-02
does not apply. Every rule gives one of three results for a record: it
fails, it passes, or it does not apply. PatternsPattern A reusable way of validating (required, format, fresh and eleven more). Each rule is a pattern applied to a field with its condition. other than required
skip an empty value, so a missing mobile is counted once, by the rule that
exists for it.
4. Say what the rule must do: examples
Section titled “4. Say what the rule must do: examples”- id: MOB-02 field: Mobile check: format pattern: \d{10} alert: The number does not have ten digits examples: fails: [{ Mobile: "12345" }, { Mobile: "555010123A" }] passes: { Mobile: "5550101234" } skips: { Mobile: null }examples are records the rule must fail, pass and skip. Writing them
makes you say what the rule must do, and tells whoever reviews it the same;
the editor does not run them yet, so check the rule’s behaviour with
Test (step 10). Write at least one of each for any rule with a
condition.
5. A rule with a condition: the employer of an employee
Section titled “5. A rule with a condition: the employer of an employee”Only employees have an employer. A rule for Employer, in
Employer.yaml:
dataset: clients
rules: - id: EMP-01 field: Employer check: required when: Occupation = 'EMPLOYEE' severity: major alert: The employer is missing for an employee examples: fails: { Occupation: EMPLOYEE, Employer: "" } passes: { Occupation: EMPLOYEE, Employer: ACME LTD } skips: { Occupation: STUDENT, Employer: "" }whenis a condition in plain SQLStructured Query Language The standard language for querying databases; the platform turns each rule into SQL for the engine that runs it. (Structured Query Language). Where it does not hold, the rule does not apply: a student without an employer is not a failure.severity: majorchanges the patternPattern A reusable way of validating (required, format, fresh and eleven more). Each rule is a pattern applied to a field with its condition.’s default (blocking): the record is usable, with reservations. SeveritySeverity A rule's weight in the ICD: blocking 1.0, major 0.6 and minor 0.3. The pattern gives a rule its default severity. weights a failure in the indicators.- Texts compare trimmed and without telling upper from lower case, so
'employee 'matches as well.
If many rules share a condition, such as “only people”, declare it once as
a population in the datasetDataset One table of a source as Quality Data reads it: a name, its fields and the rules that check them.’s global rulesGlobal rules A dataset's file reglas_globales.yaml: what several fields share, such as lists, populations and named rules, declared once for every rules file of the dataset., reglas_globales.yaml:
dataset: clients
populations: individuals: ClientType = 'PERSON'Then any rule says population: individuals. With both when and
population, both must hold.
6. Dates are compared with the cut
Section titled “6. Dates are compared with the cut”The customer’s data must have been updated within the last 13 months, in
LastUpdate.yaml:
dataset: clients
rules: - id: UPD-01 field: LastUpdate check: fresh max_age: 13 months alert: The contact data was not updated in the last year“Within the last 13 months” means before the cut, never before today.
A cut measured again next year gives the same result. When you need the
cut in an expression, write :cut; as a bound alone, quote it:
- id: BIR-01 field: BirthDate check: range min: "1900-01-01" max: ":cut" alert: The birth date is not plausible7. Allowed values: a list
Section titled “7. Allowed values: a list”The occupations that come with an income, declared once in the global rulesGlobal rules A dataset's file reglas_globales.yaml: what several fields share, such as lists, populations and named rules, declared once for every rules file of the dataset.:
lists: income_occupations: [EMPLOYEE, SELF-EMPLOYED, RETIRED]and checked in Occupation.yaml:
- id: OCC-01 field: Occupation check: domain in: { list: income_occupations } when: HasIncome = 'YES' alert: The occupation does not generate incomeA short list can go inline (in: [EMPLOYEE, RETIRED]). Over 50 values,
lint asks you to make it a catalog table (QR103).
8. A rule across fields
Section titled “8. A rule across fields”Some checks are about two fields together. implies says: when one
condition holds, another holds too.
- id: END-01 field: ClosedOn check: implies if: Status = 'CLOSED' then: not is_empty(ClosedOn) alert: A closed account needs the date it was closedimplies skips nothing: its conditions decide what an empty value means,
so say it with is_empty(x). As read marks the rule as cross-field,
because it reads more than its own field.
9. Write a check once, use it in many fields
Section titled “9. Write a check once, use it in many fields”Several fields hold documents with the same form. Write the check once as a named rule in the global rulesGlobal rules A dataset's file reglas_globales.yaml: what several fields share, such as lists, populations and named rules, declared once for every rules file of the dataset.:
named: valid_document: check: format pattern: \d{5,12} severity: major alert: The document has 5 to 12 digitsand start each field’s ruleRule It applies a pattern to a field; the pattern gives it its dimension and a default severity. The rules that count are the ones on main, the approved version. from it with extends, changing only what
differs:
- id: REPDOC-01 field: RepDocument extends: valid_document when: ClientType = 'COMPANY'A change to valid_document changes every rule that extends it, at the
next cutCut The dataset's data as it was on one date, copied into the lake so it can be measured again without touching the source. Every figure of a report refers to that moment.. Before you change or remove one, read Share rules across
fields.
10. Test, then take it to main
Section titled “10. Test, then take it to main”Fix what lint marks, choose Test to run the file on the latest cutCut The dataset's data as it was on one date, copied into the lake so it can be measured again without touching the source. Every figure of a report refers to that moment., and
read the counts: if a ruleRule It applies a pattern to a field; the pattern gives it its dimension and a default severity. The rules that count are the ones on main, the approved version. fails on half the datasetDataset One table of a source as Quality Data reads it: a name, its fields and the rules that check them., read it again. Then
choose Deploy, or Save as a draft if you may not approve. How each
step goes, and what it can refuse, is in Write, change and test a
rule and Take a change to
main. The rules on main are the ones the next cut is
evaluated with.
Common mistakes
Section titled “Common mistakes”| You wrote | What happens | Write instead |
|---|---|---|
required and on_empty: fail together |
Lint error: it does not apply | required alone |
| A date compared with today | Not possible | :cut |
max: :cut unquoted |
YAMLYAML Ain't Markup Language A plain-text format, easy for people to read and write, in which rules are written. reads it as something else | max: ":cut" |
A new id after changing a ruleRule It applies a pattern to a field; the pattern gives it its dimension and a default severity. The rules that count are the ones on main, the approved version. |
Its history starts again | Keep the id |
| A rule in another field’s file | Lint warning QR210 |
Move it to its field’s file |
No alert |
Lint warning | A sentence for whoever fixes the record |
- Rule language: every key, expressions and their functions, and what Quality Data decides for every ruleRule It applies a pattern to a field; the pattern gives it its dimension and a default severity. The rules that count are the ones on main, the approved version..
- Rule patterns: the fourteen patternsPattern A reusable way of validating (required, format, fresh and eleven more). Each rule is a pattern applied to a field with its condition., one by one.
- Lint findings: every message of the editor’s checker.
- The Tasks pages, from Write, change and test a rule to Export and import rules: sharing rules, draftsDraft A change to a dataset's rules kept apart from main, usually saved by an author who may edit rules but not approve them, until someone who may approve reviews it and approves or discards it., history.
Government Data · Guide v0.8.1