[ Web Proxy ]
URL:
Viewing: https://cloud.google.com/dataplex/docs/auto-data-quality-overview#predefined-rules [Back]  [Original]

Auto data quality overview  |  Knowledge Catalog  |  Google Cloud Documentation Skip to main content
Google Cloud Documentation [Google Cloud Documentation]
Send feedback

Auto data quality overview Stay organized with collections Save and categorize content based on your preferences.

Knowledge Catalog (formerly Dataplex Universal Catalog) lets you define and measure the quality of the data in your BigQuery and Iceberg REST Catalog tables. You can automate the data scanning, validate data against defined rules, and log alerts if your data doesn't meet quality requirements. Auto data quality lets you manage data quality rules and deployments as code, improving the integrity of data production pipelines.

To scan data for anomalies, see Knowledge Catalog data profile scan. The scan can generate data quality rules. You can also use built-in quality rules or build custom rules.

Knowledge Catalog provides monitoring, troubleshooting, and Cloud Logging alerting that's integrated with auto data quality.

Conceptual model

A data quality scan applies quality rules to table data to report results. [A data quality scan applies quality rules to table data to report results.]

A data quality scan is a type of Knowledge Catalog data scan that validates your data against a set of built-in rules. A data scan is a Knowledge Catalog job that samples data from BigQuery and Cloud Storage (through BigQuery external tables) and infers various types of metadata. To measure the quality of a table using auto data quality, you create a DataScan object of type data quality. The scan runs on only one BigQuery table. The scan uses resources in a Google tenant project, so you don't need to set up your own infrastructure.

Creating and using a data quality scan consists of the following steps:

  1. Define data quality rules
  2. Configure rule execution
  3. Analyze data quality scan results
  4. Set up monitoring and alerting
  5. Troubleshoot data quality failures

Rule definition

Data quality rules associated with a data quality scan define data expectations. You can create data quality rules in the following ways:

Built-in rules

Knowledge Catalog supports the following categories of built-in rules:

Row-level

For row-level category rules, the expectation is applied against each data row. Each row independently passes or fails the condition. For example, column_A_value < 1.

Row-level checks require you to specify a passing threshold. When the percentage of rows passing the rule falls below the threshold value, the rule fails.

Aggregate

For aggregate rules, the expectation is applied against a single value aggregated across the entire data. For example, Avg(someCol) >= 10. To pass, the check must evaluate to the boolean true. Aggregate rules don't provide an independent pass or fail count for each row.

For both of the rule categories, you can set the following parameters:

The following table lists the supported row-level and aggregate rule types:

Rule type
(Name in Google Cloud console)
Row-level or aggregate rule Description Supported column types Rule-specific parameters
RangeExpectation
(Range Check)
Row-level Check if the value is between min and max. All numeric, date, and timestamp type columns. Required:
  • Passing threshold percentage
  • min or max values: Specify at least one value.
Optional:
  • Enable strict min: If enabled, the rule check uses ">" instead of ">=".
  • Enable strict max: If enabled, the rule check uses "<" instead of "<=".
  • Enable ignore null: If enabled, null values are ignored in the rule check.
NonNullExpectation
(Null check)
Row-level Validate that column values are not NULL. All supported column types. Required:
  • Passing threshold percentage.
SetExpectation
(Set check)
Row-level Check if the values in a column are one of the specified values in a set. All supported column types, except Record and Struct. Required:
  • Set of string values to check against.
  • Passing threshold percentage.
Optional:
  • Enable ignore null: If enabled, null values are ignored in the rule check.
RegexExpectation
(Regular expression check)
Row-level Check the values against a specified regular expression. String Required:
  • Regular expression pattern used to check.
  • Passing threshold percentage.
  • Note: GoogleSQL provides regular expression support using the re2 library. See that documentation for its regular expression syntax.
Optional:
  • Enable ignore null: If enabled, null values are ignored in the rule check.
Uniqueness
(Uniqueness Check)
Aggregate Check if all the values in a column are unique. All supported column types, except Record and Struct. Required:
  • Column and dimension from the supported parameters.
Optional:
  • Enable ignore null: If enabled, null values are ignored in the rule check.
StatisticRangeExpectation
(Statistic check)
Aggregate Check if the given statistical measure matches the range expectation. All supported numeric column types. Required:
  • mean, min, or max values: Specify at least one value.
Optional:
  • Enable strict min: If enabled, the rule check uses ">" instead of ">=".
  • Enable strict max: If enabled, the rule check uses "<" instead of "<=".

Supported custom SQL rule types

SQL rules provide flexibility to expand the validation with custom logic. These rules come in the following types.

Rule type Row-level or aggregate rule Description Supported column types Rule-specific parameters Example
Row condition Row-level Specify an expectation for every row by defining a SQL expression in a WHERE clause. The SQL expression should evaluate to true (pass) or false (fail) per row.

Knowledge Catalog computes the percentage of rows that pass this expectation and compares this value against the passing threshold percentage to determine the success or failure of the rule.

The expression can include a reference to another table, for example, to create referential integrity checks.
All columns Required:
  • SQL condition to use
  • Passing threshold percentage
  • Dimension
Optional:
  • Column to associate this rule with.
grossWeight <= netWeight
Table condition
(aggregate SQL expression)
Aggregate These rules are executed once per table. Provide a SQL expression that evaluates to boolean true (pass) or false (fail).

The SQL expression can include a reference to another table using expression subqueries.
All columns Required:
  • SQL condition to use
  • Dimension
Optional:
  • Column to associate this rule with
Simple aggregate example:
avg(price) > 100
Using an expression subquery to compare values across a different table:
(SELECT COUNT(*) FROM `example_project.example_dataset.different-table`) < COUNT(*)
SQL assertion Aggregate An assertion rule uses a data quality query to find rows that fail one or more conditions specified in the query. Provide a SQL statement that is evaluated to return rows that match the invalid state. If the query returns any rows, the rule fails.

Omit the trailing semicolon from the SQL statement. The SQL statement can include a reference to another table using expression subqueries.
All columns Required:
  • SQL statement to check invalid state
  • Dimension
Optional:
  • Column to associate this rule with.
Simple aggregate example to make sure that discount_pct is not greater than 100:
SELECT * FROM example_project.example_dataset.table WHERE discount_pct > 100

Using an expression subquery to compare values across a different table:
SELECT * FROM `example_project.example_dataset.different-table` WHERE gross_weight > (SELECT avg(gross_weight) FROM `example_project.example_dataset.different-table`)

For example rules, see auto data quality sample rules.

For SQL functions supported, see GoogleSQL reference.

Reuse data quality rules

You can reuse Knowledge Catalog data quality rules to share complex or standardized business rule definitions across multiple data quality rules by using rule templates. For example, you can create a rule template for an email validation or for foreign key validation between two tables, and then reuse those templates across your data scans.

Rule reusability provides the following key features:

For more information, see Reuse data quality rules.

Dimensions

Dimensions let you aggregate the results of multiple data quality rules for monitoring and alerting. You must associate every data quality rule with a dimension. Knowledge Catalog provides the following dimensions:

Freshness
Freshness measures when the data was last updated. Having this information can help you determine whether the data is recent enough to be useful.
Volume
Volume measures whether all of the expected data is present.
Completeness
Completeness assesses whether the data contains all of the information that's required for its intended purpose.
Validity
Validity evaluates whether the data conforms to built-in standards for format, acceptable ranges, or other criteria. For example, if a valid date needs to have the format YYYY/mm/dd, then 08-12-2019 is invalid data. As another example, if a valid sales price for an item is between $10 and $20, then a sales price of $100 is invalid data.
Consistency
Consistency refers to having the same values for data across multiple instances, such as tables and columns. Inconsistency in data arises when, for example, the revenue of a product differs when it is read from a sales database or a usage database.
Accuracy
Accuracy reflects the correctness of the data. Note that data that is valid isn't necessarily accurate. For example, a valid hair color might be brown, but if a person doesn't have brown hair, that is inaccurate data.
Uniqueness
Uniqueness measures whether the data is distinct with no duplicates.
Note: You can create a custom dimension name when you use the gcloud CLI or the REST API to create a data scan. You can use dimension names that reflect your organization's terminology. For example, instead of freshness, you might use timeliness.

Typed input in rules

All value parameters are passed as string values to the API. Knowledge Catalog requires inputs to follow the BigQuery specified format.

Binary-typed parameters can be passed as a base64-encoded string.

Type Supported formats Examples
Binary Base64 encoded value YXBwbGU=
Timestamp YYYY-[M]M-[D]D[( |T)[H]H:[M]M:[S]S[.F]] [time_zone]
OR YYYY-[M]M-[D]D[( |T)[H]H:[M]M:[S]S[.F]][time_zone_offset]
2014-09-27 12:30:00.45-08
Date YYYY-M[M]-D[D] 2014-09-27
Time [H]H:[M]M:[S]S[.DDDDDD] 12:30:00.45
DateTime YYYY-[M]M-[D]D [[H]H:[M]M:[S]S[.DDDDDD]] 2014-09-27 12:30:00.45

Data reference parameter

When you create a custom SQL rule, you can refer to a data source table and all of its precondition filters by using the data reference parameter ${data()} in the rule, instead of explicitly mentioning the source table and its filters. Knowledge Catalog interprets the parameter as a reference to the source table and its filters. Examples of precondition filters include row filters, sampling percents, and incremental filters.

For example, say that you have a data source table called my_project_id.dim_dataset.dim_currency. You want to run an incremental data quality scan that scans only on new daily data. A row filter that filters for today's entries, transaction_timestamp >= current_date(), is applied on the table.

A custom SQL rule to find rows with discount_pct for today looks like this:

discount_pct IN (SELECT discount_pct FROM my_project_id.dim_dataset.dim_currency WHERE transaction_timestamp >= current_date())

If you use the data reference parameter, you can simplify the rule. Replace the mention of the table and its precondition filters with the ${data()} parameter:

discount_pct IN (SELECT discount_pct FROM ${data()})

Knowledge Catalog interprets the ${data()} parameter as a reference to the data source table with today's entries, my_project_id.dim_dataset.dim_currency WHERE transaction_timestamp >= current_date(). In this example, the data reference parameter refers only to the incremental data.

The ${data()} parameter is case sensitive.

When you use an alias within a subquery to refer to columns in the source table, either use the data reference parameter to refer to the source table, or omit the table reference. Don't refer to the columns in the source table by using a direct table reference in the WHERE clause.

Recommended:

Not recommended:

Valid use of different tables:

Debug queries

Preview

This product or feature is subject to the "Pre-GA Offerings Terms" in the General Service Terms section of the Service Specific Terms. Pre-GA products and features are available "as is" and might have limited support. For more information, see the launch stage descriptions.

When you create a rule, you can optionally include a debug query to run alongside the rule. A debug query is a SQL statement that returns up to 10 scalar values. These values can help diagnose the cause if the rule fails. You can add at most one debug query per rule, and it must not exceed 1024 characters in length.

Consider the following SQL assertion rule on the example_project.example_dataset.table table that checks whether the average revenue per item exceeds 100:

SELECT
  *
FROM
  `example_project.example_dataset.table`
WHERE
  SUM(revenue) / COUNT(DISTINCT item_id) > 100

If the preceding rule fails, you can view metrics such as total revenue, number of distinct items, and average revenue per item to help diagnose the issue. The following debug query returns these metrics:

SELECT
  SUM(revenue),
  COUNT(DISTINCT item_id),
  SUM(revenue) / COUNT(DISTINCT item_id)
FROM `example_project.example_dataset.table`

Rule execution

You can schedule data quality scans to run at a specific interval, or you can run a scan on demand.

Execution identity

By default, Knowledge Catalog uses a centralized service agent (service-PROJECT_NUMBER@gcp-sa-dataplex.iam.gserviceaccount.com) to run data quality scans.

You can override this default execution identity by specifying a custom service account or by using your own End-User Credentials (EUC). This provides several benefits:

For instructions on how to configure a custom execution identity, see Configure execution identity.

Networking requirements

To run a scan, you must enable Private Google Access on the VPC subnet that you use for the scan. If you don't specify a subnet, make sure your default subnet has Private Google Access enabled.

When you run a data quality scan, Knowledge Catalog creates a job. If a job is misconfigured or running longer than expected, you can cancel the job.

As part of the specification of a data quality scan, you can specify the scope of a job to be one of the following:

Full Table
Each job validates the entire table.
Incremental
Each job validates incremental data. To determine increments, provide a Date / Timestamp column in the table that can be used as a marker. Typically, this is the column on which the table is partitioned.

Filter data

You can filter data to be scanned for data quality by using a row filter. Creating a row filter lets you focus on data within a specific time period or specific segment, such as a certain region. Using filters can reduce the run time and cost. For example, you can filter out data with a timestamp before a certain date.

Sample data

You can specify a percentage of records from your data to sample for running a data quality scan. Creating data quality scans on a smaller sample of data can reduce the run time and the cost relative to querying the entire dataset.

Filter rules

When you run a data quality scan, you can use AIP-160 filter syntax to selectively execute specific rules. Knowledge Catalog performs filtering on the metadata of the rules defined in the scan or rules attached to the catalog entry through the data-rules aspect.

Filter syntax

The filter syntax follows AIP-160 guidelines. You can use standard AIP-160 operators (such as =, !=, >, <, =~) and combine multiple conditions using AND or OR.

When you use an AIP-160 filter string, do the following:

Filterable fields

You can filter on most fields available in the rule definition:

The following examples show common filter patterns. Numeric and boolean values aren't quoted.

Filter by name

Filter by dimension

Filter by column and threshold

Filter by ignore_null

Filter by custom attributes

Data quality scan results

The results of your data quality scans are available in Knowledge Catalog and BigQuery. You can also review and analyze the scan results by using the following methods:

For more information, see View the data quality scan results.

Monitoring and alerting

You can monitor and get alerts about data quality scans by using the following methods:

Troubleshoot data quality failures

When a rule execution fails, Knowledge Catalog provides a query to get the failed records. Run this query to see the records that didn't match your rule. For more information, see Troubleshoot a data quality failure.

Note: The query returns all of the columns of the table, including the failed column.

Limitations

Pricing

For more information about pricing, see Knowledge Catalog pricing.

What's next

Send feedback

Except as otherwise noted, the content of this page is licensed under the Creative Commons Attribution 4.0 License, and code samples are licensed under the Apache 2.0 License. For details, see the Google Developers Site Policies. Java is a registered trademark of Oracle and/or its affiliates.

Last updated 2026-08-11 UTC.

Need to tell us more? [[["Easy to understand","easyToUnderstand","thumb-up"],["Solved my problem","solvedMyProblem","thumb-up"],["Other","otherUp","thumb-up"]],[["Hard to understand","hardToUnderstand","thumb-down"],["Incorrect information or sample code","incorrectInformationOrSampleCode","thumb-down"],["Missing the information/samples I need","missingTheInformationSamplesINeed","thumb-down"],["Other","otherDown","thumb-down"]],["Last updated 2026-08-11 UTC."],[],[]]

Web Proxy Viewer  |  New URL  |  Original Page