Validity rules
Use validity rules to check whether data in your tables meets expected formats or value constraints.
How it works
A validity rule applies a metric to a column and compares the result against a threshold. Each rule has two parts:
Metric — what to measure:
invalid_count(number of invalid rows) orinvalid_percent(percentage of invalid rows)Valid data definition — what counts as valid, specified in the
validfield usingformat,regex, orvalues
Rows that do not match the valid definition are counted as invalid. For invalid_percent, the threshold is a percentage value — for example, < 5% means fewer than 5% of all rows are invalid.
Configuration example
The following example defines three validity rules on the tb_d_spec_demo table, one for each definition method:
datasets:
- type: Table
tables:
- tb_d_spec_demo
filter: dt=$[yyyymmdd]/hh=$[hh24-1/24]
dataSource:
name: odps_first
envType: Dev
rules:
- invalid_count(email_address) = 0
valid:
format: email
- invalid_percent(last_name) < 5%
valid:
regex: "(?:XX)"
- invalid_count(house_owner_flag) = 0
valid:
values:
- US
- CNDefine valid data
Use the valid field to specify what counts as valid. Three definition methods are available.
format
Match values against a built-in format. You can specify multiple formats for the same column.
Format | Description | Example value |
| Email address |
|
| ID card number for the Chinese mainland |
|
| Mobile phone number for the Chinese mainland |
|
| Landline phone number for the Chinese mainland |
|
| Numeric value |
|
| Date in |
|
| Date in |
|
| Date and time in |
|
| Date and time with milliseconds in |
|
| Date in |
|
| Date in |
|
| ISO 8601 date and time in |
|
| Time in |
|
| Chinese yuan amount |
|
| U.S. dollar amount |
|
| British pound amount |
|
| Euro amount |
|
| Japanese yen amount |
|
regex
Match values against a regular expression.
valid:
regex: "(?:XX)"values
Match values against a fixed set of allowed literal values.
valid:
values:
- US
- CN