Validity rules
Use validity rules to check whether data in your tables meets expected formats or value constraints.
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
- CN
Define valid data
Validity rules support the following two metrics:
-
invalid_count: the number of invalid rows. -
invalid_percent: the percentage of invalid rows in the total number of rows.
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