How Expected Values Checks Work
Definition
Asserts that the value in the selected field is contained in a predefined list of accepted values.
Overview
The Expected Values rule enforces a closed vocabulary on a single column. The check compares each row's value against a list configured on the rule and flags every row whose value is not in the list. Typical use cases include:
- Enforcing status enums (
order_status,payment_state). - Restricting a country, currency, or locale code to an allowed set.
- Validating short categorical fields (
tier,channel,segment). - Asserting that an array column contains only elements from a known vocabulary.
NULL values pass the check. The rule only evaluates non-NULL values against the list, so an Expected Values check on a nullable field never fires on missing values. Pair it with a Not Null check on the same field when missingness is also a violation.
Field Scope
Single: The rule evaluates one field per check.
Accepted Types
| Type | Supported |
|---|---|
Date |
|
Timestamp |
|
Integral |
|
Fractional |
|
String |
|
Boolean |
|
Array |
Every field type except Struct is accepted. For Date and Timestamp, the list is compared as strings against the column's rendered value; see Type Coercion and Matching Rules for the recommended formats. Array fields are evaluated element-wise, as described under Array Fields.
General Properties
| Name | Supported |
|---|---|
Filter Allows the targeting of specific data based on conditions |
|
Coverage Customization Allows adjusting the percentage of records that must meet the rule's conditions |
The filter allows you to define a subset of data upon which the rule will operate.
It requires a valid Spark SQL expression that determines the criteria rows in the DataFrame should meet. This means the expression specifies which rows the DataFrame should include based on those criteria. Since it's applied directly to the Spark DataFrame, traditional SQL constructs like WHERE clauses are not supported.
Examples
Direct Conditions
Simply specify the condition you want to be met.
Combining Conditions
Combine multiple conditions using logical operators like AND and OR.
Correct usage" collapsible="true
Incorrect usage" collapsible="true
Utilizing Functions
Leverage Spark SQL functions to refine and enhance your conditions.
Correct usage" collapsible="true
Incorrect usage" collapsible="true
Using scan-time variables
To refer to the current dataframe being analyzed, use the reserved dynamic variable {{_qualytics_self}}.
Correct usage" collapsible="true
Incorrect usage" collapsible="true
While subqueries can be useful, their application within filters in our context has limitations. For example, directly referencing other containers or the broader target container in such subqueries is not supported. Attempting to do so will result in an error.
Important Note on {{_qualytics_self}}
The {{_qualytics_self}} keyword refers to the dataframe that's currently under examination. In the context of a full scan, this variable represents the entire target container. However, during incremental scans, it only reflects a subset of the target container, capturing just the incremental data. It's crucial to recognize that in such scenarios, using {{_qualytics_self}} may not encompass all entries from the target container.
Specific Properties
Specify the predefined list of values that the field is allowed to contain.
| Name | Description |
|---|---|
List |
The predefined set of accepted values. Every non-NULL value in the selected field must match one of these entries exactly (case-sensitive, no whitespace trimming). |
Info
The List input flags entries with leading or trailing whitespace. A clean value like ship renders as a normal chip; values like ship or ship get a yellow chip background so the extra space stands out at a glance. A warning icon also appears next to the field title. Hover the icon to see the full list of values with extra spaces.
The chip is still saved exactly as typed. Re-enter the value without the surrounding spaces if the engine is meant to match it literally, since the comparison is exact and does not trim.
Anomaly Types
| Type | Supported |
|---|---|
| Record Flag inconsistencies at the row level |
|
| Shape Flag inconsistencies in the overall patterns and distributions of a field |
How the Check Evaluates Values
Every Expected Values check follows the same evaluation flow:
- Apply the filter clause. If the check has a
filterset, only the rows that match the filter expression continue to the next step. Rows outside the filter are ignored and cannot cause a violation. - Skip NULL values. Rows where the selected field is NULL pass the check automatically and are never reported as violations.
- Compare each non-NULL value to the list. A row passes when the value is exactly equal to one of the list entries (same type, same case, same whitespace). A row fails when the value is non-NULL and not in the list.
- Decide Record or Shape anomaly. On a scalar field this follows coverage: at 100% coverage every failing row becomes a Record Anomaly, and below 100% coverage the violation is rolled up into a single Shape Anomaly when the failing fraction exceeds the configured threshold (see Coverage and Tolerance). On an
Arrayfield the check is evaluated at field level and always reports a Shape Anomaly (see Array Fields).
The order of operations matters: the filter is applied before the value comparison, so rows that the filter excludes cannot contribute to the violation count.
NULL Handling
NULL values pass the Expected Values check. The engine evaluates column IS NULL OR column IN (list), so a NULL is treated as compliant regardless of what is in the list. This is intentional: Expected Values asserts membership in a vocabulary, not presence.
If missing values are also a violation, pair Expected Values with a Not Null check on the same field. Together they enforce "this field must be present and must match the vocabulary."
Type Coercion and Matching Rules
The list is interpreted according to its contents and the column type:
- All entries numeric → the list is treated as a numeric list. Integers and decimals are compared numerically.
100matches100.0. - All entries boolean (
true,false) → the list is treated as a boolean list. The column must be ofBooleantype. - Anything else (including mixed or empty) → the list is treated as strings and the column value is compared as a string.
A few practical consequences worth knowing:
- Case-sensitive.
"O"does not match"o". If you need case-insensitive matching, normalize the source data upstream or use a Satisfies Expression check withlower(field) IN (...). - Whitespace-sensitive.
" O "does not match"O". The Authored Check modal warns when an entry has leading or trailing whitespace, but it does not trim it for you. - Type mismatches fail. If the column is integer and the list is
["O", "F", "P"](strings), the platform cannot interpret"O"as an integer; every non-NULL row will fail the check. Keep the list's type aligned with the field's type. - Date and Timestamp. There is no native date list type; values are compared as strings against the column's rendered form. Prefer the ISO-8601 representation that matches how your engine serializes the column (
YYYY-MM-DDforDate,YYYY-MM-DD HH:MM:SSforTimestamp).
Array Fields
When the check targets an Array[String] field, the platform automatically switches to element-wise evaluation:
- The check tests every element of the array against the list, rather than the array as a whole.
- Every element of the array must be in the list. A row fails as soon as one element is outside the vocabulary, even if the other elements pass.
- An empty array passes (no elements to evaluate). A NULL array also passes (NULL handling rules above).
- The evaluation runs as a field-level check, so a failure is reported as one Shape Anomaly for the field, never as per-row Record Anomalies, whatever the coverage is set to.
Element-wise evaluation is supported only for string element lists today. Array fields with numeric or boolean lists fall through to scalar comparison and are not currently recommended. See Complex Data Types for the broader picture of how rule types interact with arrays.
The Filter Clause
The filter clause is a SQL WHERE expression applied before the value comparison. Use it to:
- Scope the check. Restrict the vocabulary requirement to a subset of the data (for example,
region = 'NA'to enforce a North-American country code vocabulary only on orders from that region). - Exclude legacy or pending rows. A filter such as
created_at >= '2024-01-01'keeps the check from flagging values that were valid under an earlier vocabulary.
The filter is part of the check definition, so the anomaly message includes the filter expression ([filter: <expression>]) when one is set, making it explicit which slice of data was evaluated when the anomaly fired.
Coverage and Tolerance
Coverage is a fractional value between 0 and 1 that controls whether failing rows produce Record anomalies (one per row) or a single Shape anomaly (the dataset-level rollup):
1.0(100%, default): every non-NULL row must match the list. Each failing row produces a Record Anomaly.< 1.0: the check tolerates a fraction of records failing the comparison. When the actual failing fraction exceeds the threshold, a single Shape Anomaly fires for the dataset. No Record Anomalies are produced in this mode.
Lower coverage values are useful when a small known fraction of out-of-vocabulary values is expected (a slow migration, a deprecation window, a legacy import). Use it with care: lowering coverage by 0.5% means a regression introducing failures in up to 0.5% of rows will look identical to the tolerated baseline and won't fire.
See Also
-
Anomaly Reporting
The anomaly messages the check produces, what the numbers mean, Source Records highlighting, and Custom Anomaly Description.
-
Examples
Three production scenarios with sample data, anomaly messages, and the SQL equivalent of what the check evaluates.
-
Best Practices
Guidelines for sizing the vocabulary, matching exactly, pairing rules, and keeping the signal clean.
-
Permissions
The team permission each action needs: view, create, edit, archive, restore, and delete.