Knowledge Catalog (formerly Dataplex Universal Catalog) lets you reuse data quality rules by applying system or custom rule templates directly in scans for BigQuery tables. You can also attach rules as catalog metadata on table entries and business glossary terms so policies are searchable and glossary checks propagate automatically to linked columns.
To compare direct scan references with catalog-based governance models, see About reusing data quality rules. To author custom SQL templates before applying them, see Create and manage rule templates.
Limitations
The following limitations apply when reusing data quality rules and running scans:
- Scans that reference rule templates or catalog-based rules require a customer-managed execution service account.
- A scan or catalog entry can reference only rule templates stored in the same
region or in the
globallocation. - Bulk metadata import jobs don't
support importing
data-rulesaspects.
Before you begin
This document supports two workflows depending on your role and governance goals:
- Direct scan reference (data engineers): skip directly to Create a scan using template rules to apply system or custom templates to a single scan without attaching catalog aspects.
- Catalog-based governance (data stewards and engineers): first attach rules to BigQuery tables or business glossary terms and verify the attached rules. Then create a scan using catalog-based rules to evaluate direct and inherited rules dynamically at runtime.
Before you begin, review the following concepts:
Enable the Dataplex API, if it is not already enabled.
Roles required to enable APIs
To enable APIs, you need the serviceusage.services.enable permission. If you
created the project, then you likely already have this permission through the
Owner role (roles/owner). Otherwise, you can get this permission through the
Service Usage Admin role (roles/serviceusage.serviceUsageAdmin).
Learn how to grant roles.
Set up an execution service account
Because template-based and catalog-based scans run resolved GoogleSQL validation jobs in BigQuery on your behalf under least-privilege boundaries, you must configure a customer-managed execution service account. Create a service account in your project, and then grant the roles listed in Required roles to your user account, the execution service account, and the Dataplex Service Agent.
Required roles
Reusing data quality rules and running template-based or catalog-based scans involve three identities, each requiring specific Identity and Access Management (IAM) roles:
- Your user account: creates data scans, attaches rules to BigQuery tables or business glossary terms, and attaches the execution service account to the scan.
- The execution service account (customer-managed): reads target BigQuery tables, runs validation query jobs, and optionally exports scan results.
- The Dataplex Service Agent (Google-managed): impersonates your execution service account during scan runs.
Your user account
To get the permissions that you need to create scans and attach data quality rules, ask your administrator to grant you the following IAM roles:
-
Create and manage data quality scans:
Dataplex DataScan Editor (
roles/dataplex.dataScanEditor) on the scan project -
Attach the execution service account to a scan:
Service Account User (
roles/iam.serviceAccountUser) on the execution service account -
Attach rules to BigQuery tables:
Dataplex Catalog Editor (
roles/dataplex.catalogEditor) on the@bigqueryentry group in the table location -
Attach rules to business glossary terms:
Dataplex Catalog Editor (
roles/dataplex.catalogEditor) on the@dataplexentry group -
Create catalog-based scans:
BigQuery Data Viewer (
roles/bigquery.dataViewer) on the BigQuery table
These predefined roles contain the permissions required to create scans and attach data quality rules. To see the exact permissions that are required, expand the Required permissions section:
Required permissions
The following permissions are required to create scans and attach data quality rules:
-
Create and manage data quality scans:
-
dataplex.datascans.createon the scan project -
dataplex.datascans.deleteon the scan project -
dataplex.datascans.geton the scan project -
dataplex.datascans.getDataon the scan project -
dataplex.datascans.liston the scan project -
dataplex.datascans.runon the scan project -
dataplex.datascans.updateon the scan project
-
-
Attach the execution service account:
iam.serviceAccounts.actAson the execution service account -
Attach rules to BigQuery tables:
-
dataplex.entries.updateon the@bigqueryentry group in the table location -
dataplex.entryGroups.useDataRulesAspecton the@bigqueryentry group in the table location
-
-
Attach rules to business glossary terms:
-
dataplex.entries.updateon the@dataplexentry group -
dataplex.entryGroups.useDataRulesAspecton the@dataplexentry group
-
-
Create catalog-based scans:
-
bigquery.tables.geton the BigQuery table -
bigquery.tables.getDataon the BigQuery table
-
To reference custom rule templates without granting write or delete access to
shared templates, ask your administrator for a
custom role on the rule library entry group
or project. Include only the dataplex.entries.get and
dataplex.entries.getData permissions. If you browse custom templates in the
Google Cloud console, then also include dataplex.entries.list on the rule library
and dataplex.projects.search on the scan or table project. Alternatively,
pair the Dataplex Catalog Viewer (roles/dataplex.catalogViewer) role with a
custom role containing dataplex.entries.getData. The Dataplex Catalog Viewer
role doesn't include dataplex.entries.getData. Predefined roles that include
dataplex.entries.getData—such as Dataplex Entry and EntryLink Owner
(roles/dataplex.entryOwner) and Dataplex Catalog Editor
(roles/dataplex.catalogEditor)—also grant write and delete permissions on
entries.
You can also use these alternative role and permission options:
- Manage scans: Dataplex DataScan Administrator
(
roles/dataplex.dataScanAdmin) on the scan project also grants scan management permissions. For additional scan roles, see Required roles for data quality scans. - Attach rules to BigQuery tables in the
Google Cloud console: instead of Dataplex Catalog Editor on
@bigquery, you can grant BigQuery Data Editor (roles/bigquery.dataEditor) orbigquery.tables.updateon the table anddataplex.entryGroups.useDataRulesAspecton@bigquery. The REST API and Terraform requiredataplex.entries.updateon@bigquery. - Attach rules to business glossary terms in the Google Cloud console:
instead of Dataplex Catalog Editor on
@dataplex, you can grantdataplex.glossaryTerms.updateon the glossary term anddataplex.entryGroups.useDataRulesAspecton@dataplex. The REST API and Terraform requiredataplex.entries.updateon@dataplex. - Create catalog-based scans: instead of BigQuery Data Viewer on the
table, you can grant a custom role with
dataplex.entries.getanddataplex.entries.getDataon the@bigqueryentry group in the table location.
The execution service account
To ensure that the execution service account has the necessary permissions to read target tables, run validation jobs, and optionally export scan results, ask your administrator to grant the following IAM roles to the execution service account:
-
Read data from the table to scan:
BigQuery Data Viewer (
roles/bigquery.dataViewer) on the BigQuery table to scan and any reference tables queried in SQL templates -
Run validation query jobs:
BigQuery Job User (
roles/bigquery.jobUser) on the scan project -
If you export scan results to BigQuery:
BigQuery Data Editor (
roles/bigquery.dataEditor) on the export dataset
These predefined roles contain the permissions required to read target tables, run validation jobs, and optionally export scan results. To see the exact permissions that are required, expand the Required permissions section:
Required permissions
The following permissions are required to read target tables, run validation jobs, and optionally export scan results:
-
Read table data:
-
bigquery.tables.geton the BigQuery table to scan and any reference tables queried in SQL templates -
bigquery.tables.getDataon the BigQuery table to scan and any reference tables queried in SQL templates
-
-
Run validation query jobs:
bigquery.jobs.createon the scan project -
If you export scan results to BigQuery:
-
bigquery.datasets.geton the export dataset and table -
bigquery.tables.createon the export dataset and table -
bigquery.tables.geton the export dataset and table -
bigquery.tables.getDataon the export dataset and table -
bigquery.tables.updateon the export dataset and table -
bigquery.tables.updateDataon the export dataset and table
-
The Dataplex Service Agent
The Dataplex Service Agent for your scan project uses the following email format:
service-PROJECT_NUMBER@gcp-sa-dataplex.
Replace PROJECT_NUMBER with the project number of your
scan project.
To ensure that the Dataplex Service Agent has the necessary
permission to impersonate the execution service account during scan runs,
ask your administrator to grant the
Service Account Token Creator (roles/iam.serviceAccountTokenCreator) IAM role to the Dataplex Service Agent on the execution service account.
For more information about granting roles, see Manage access to projects, folders, and organizations.
This predefined role contains the
iam.serviceAccounts.getAccessToken
permission,
which is required to
impersonate the execution service account during scan runs.
Your administrator might also be able to give the Dataplex Service Agent this permission with custom roles or other predefined roles.
Create a scan using template rules
To validate a single table without storing data-rules metadata in the catalog,
reference
system rule templates
or custom rule templates directly inside the scan definition. Before you start,
configure your execution service account. Custom
templates use your project's entry group path, while system templates use the
global path
projects/dataplex-templates/locations/global/entryGroups/rule-library/entries/TEMPLATE_ID.
Select one of the following options:
Console
In the Google Cloud console, go to the Data profiling & quality page.
Follow the initial steps to create a data quality scan, configuring the following settings in the Define scan pane:
- In the Credential type menu, select Service account, and then enter your execution service account.
- Click Continue.
In the Data quality rules pane, click Add rules > Template rules.
Select Attach rule to entire table, or in Choose columns, browse and select the target columns.
In Choose rule templates, select one or more custom templates in the scan's location or in
global, or select system rule templates, and then click OK.To configure template parameter values, click Edit rule, enter the parameter values, and then click Save.
Select the configured rules, click Select, and then click Continue.
Complete the remaining scan configuration. To create the scan without running it, click Create. To create and run the scan immediately, click Run scan.
REST
To create a data quality scan that references a rule template, send a POST
request to the
projects.locations.dataScans.create
method with templateReference:
curl -X POST \
-H "Authorization: Bearer $(gcloud auth print-access-token)" \
-H "Content-Type: application/json" \
"https://dataplex.googleapis.com/v1/projects/PROJECT_ID/locations/LOCATION/dataScans?dataScanId=DATASCAN_ID" \
-d '{
"data": {
"resource": "//bigquery.googleapis.com/projects/BIGQUERY_PROJECT_ID/datasets/DATASET_ID/tables/TABLE_ID"
},
"executionIdentity": {
"serviceAccount": {
"email": "SERVICE_ACCOUNT_EMAIL"
}
},
"executionSpec": {
"trigger": {
"onDemand": {}
}
},
"dataQualitySpec": {
"rules": [
{
"templateReference": {
"name": "projects/TEMPLATE_PROJECT_ID/locations/TEMPLATE_LOCATION/entryGroups/RULE_LIBRARY_ID/entries/TEMPLATE_ID",
"values": {
"PARAMETER_NAME": {
"value": "PARAMETER_VALUE"
}
}
},
"column": "COLUMN_NAME",
"name": "RULE_NAME"
}
],
"filter": "FILTER_CONDITION"
}
}'
Replace the following:
PROJECT_ID: the scan project ID (for example,test-project).LOCATION: the region for the data scan (for example,us-central1).DATASCAN_ID: a unique ID for the data quality scan.BIGQUERY_PROJECT_ID: the project ID that contains the BigQuery table.DATASET_ID: the BigQuery dataset ID.TABLE_ID: the BigQuery table ID.SERVICE_ACCOUNT_EMAIL: the email address of the execution service account.TEMPLATE_PROJECT_ID: the project ID of the custom rule library, ordataplex-templatesfor a system rule template.TEMPLATE_LOCATION: the location of the custom template, orglobalfor a system template.RULE_LIBRARY_ID: the custom rule library ID, orrule-libraryfor a system rule template.TEMPLATE_ID: the custom or system rule template ID (for example,non_null_expectation).PARAMETER_NAME: the name of an input parameter defined in the template.PARAMETER_VALUE: the string value for the input parameter.COLUMN_NAME: the target column name (omit for table-level rules).RULE_NAME: a unique name for the rule instance. The name must be 1–63 characters, contain only letters, numbers, or hyphens, start with a letter, and end with a letter or number.FILTER_CONDITION: an optional AIP-160 filter string to selectively run rules.
Terraform
To create a data quality scan that references a rule template, use the
google_dataplex_datascan
resource in the Terraform Registry:
resource "google_dataplex_datascan" "template_scan" {
project = "PROJECT_ID"
location = "LOCATION"
data_scan_id = "DATASCAN_ID"
data {
resource = "//bigquery.googleapis.com/projects/BIGQUERY_PROJECT_ID/datasets/DATASET_ID/tables/TABLE_ID"
}
execution_spec {
trigger {
on_demand {}
}
}
execution_identity {
service_account {
email = "SERVICE_ACCOUNT_EMAIL"
}
}
data_quality_spec {
rules {
column = "COLUMN_NAME"
name = "RULE_NAME"
dimension = "VALIDITY"
template_reference {
name = "projects/TEMPLATE_PROJECT_ID/locations/TEMPLATE_LOCATION/entryGroups/RULE_LIBRARY_ID/entries/TEMPLATE_ID"
values {
name = "PARAMETER_NAME"
value = "PARAMETER_VALUE"
}
}
}
filter = "FILTER_CONDITION"
}
}
Replace the following:
PROJECT_ID: the scan project ID (for example,test-project).LOCATION: the region for the data scan (for example,us-central1).DATASCAN_ID: a unique ID for the data quality scan.BIGQUERY_PROJECT_ID: the project ID that contains the BigQuery table.DATASET_ID: the BigQuery dataset ID.TABLE_ID: the BigQuery table ID.SERVICE_ACCOUNT_EMAIL: the email address of the execution service account.COLUMN_NAME: the target column name.RULE_NAME: a unique name for the rule instance. The name must be 1–63 characters, contain only letters, numbers, or hyphens, start with a letter, and end with a letter or number.TEMPLATE_PROJECT_ID: the project ID of the custom rule library, ordataplex-templatesfor a system rule template.TEMPLATE_LOCATION: the location of the custom template, orglobalfor a system template.RULE_LIBRARY_ID: the custom rule library ID, orrule-libraryfor a system rule template.TEMPLATE_ID: the custom or system rule template ID.PARAMETER_NAME: the name of an input parameter defined in the template.PARAMETER_VALUE: the string value for the input parameter.FILTER_CONDITION: an optional AIP-160 filter string to selectively run rules.
After creating a template-based scan, skip catalog attachment and continue to Run scans and verify results.
Attach rules to catalog entries
Attaching data quality rules as data-rules metadata aspects makes validation
policies searchable, auditable, and easy to reuse across scans. Choose one or
more of the attachment methods in the following sections: attach rules directly
to a BigQuery table, attach rules to a business glossary term for
automatic inheritance, or import verified rules from an existing table. After
attaching rules, verify the attached rules and
create a catalog-based scan to evaluate them
automatically.
Attach rules to a BigQuery table
Attach rules directly to a BigQuery table entry when validation logic applies to a specific dataset or column.
Select one of the following options:
Console
In the Google Cloud console, go to the Knowledge Catalog Search page.
Search for and click the BigQuery table entry that you want to govern.
Click the Data quality tab, click Rules management, and then click Create rules.
In the Create rules pane, configure the rule:
- In the Choose create option menu, select Create new rule.
- In Choose columns, click Browse, and then select the target columns.
- In the Choose rule types menu, select one or more templates in
the table's location or in
global. - To enter parameter values, click Edit rule, enter the required values, and then click Save.
To attach the rules, click Save.
Verify that the attached rules appear on the Rules management tab.
REST
To attach rules to a specific BigQuery column, send a PATCH
request to the
projects.locations.entryGroups.entries.patch
method to update the data-rules aspect at the column's schema path
(@Schema.COLUMN_NAME):
curl -X PATCH \
-H "Authorization: Bearer $(gcloud auth print-access-token)" \
-H "Content-Type: application/json" \
"https://dataplex.googleapis.com/v1/projects/PROJECT_ID/locations/LOCATION/entryGroups/@bigquery/entries/bigquery.googleapis.com/projects/PROJECT_ID/datasets/DATASET_ID/tables/TABLE_ID?updateMask=aspects&aspectKeys=projects/dataplex-types/locations/global/aspectTypes/data-rules@Schema.COLUMN_NAME" \
-d '{
"aspects": {
"dataplex-types.global.data-rules@Schema.COLUMN_NAME": {
"aspectType": "projects/dataplex-types/locations/global/aspectTypes/data-rules",
"data": {
"rules": [
{
"name": "RULE_NAME",
"dimension": "VALIDITY",
"type": "TEMPLATE_REFERENCE",
"templateReference": {
"name": "projects/TEMPLATE_PROJECT_ID/locations/TEMPLATE_LOCATION/entryGroups/RULE_LIBRARY_ID/entries/TEMPLATE_ID",
"values": {
"PARAMETER_NAME": {
"value": "PARAMETER_VALUE"
}
}
}
}
]
}
}
}
}'
Replace the following:
PROJECT_ID: the project ID of the BigQuery table.LOCATION: the BigQuery dataset location (for example,us-central1orus).DATASET_ID: the BigQuery dataset ID.TABLE_ID: the BigQuery table ID.COLUMN_NAME: the target column name on which to attach the aspect.RULE_NAME: a unique name for the rule. The name must be 1–63 characters, contain only letters, numbers, or hyphens, start with a letter, and end with a letter or number.TEMPLATE_PROJECT_ID: the project ID of the custom rule library, ordataplex-templatesfor a system template.TEMPLATE_LOCATION: the location of the custom template, orglobal.RULE_LIBRARY_ID: the custom rule library ID, orrule-libraryfor a system template.TEMPLATE_ID: the rule template ID.PARAMETER_NAME: the name of an input parameter defined in the template.PARAMETER_VALUE: the string value for the input parameter.
Terraform
To attach rules to a BigQuery table column, use the
google_dataplex_entry
resource in the Terraform Registry. Use 655216118709 (the project number
for dataplex-types) in entry_type and aspect_key:
resource "google_dataplex_entry" "bq_table_rules" {
project = "PROJECT_NUMBER"
location = "LOCATION"
entry_group_id = "@bigquery"
entry_id = "bigquery.googleapis.com/projects/PROJECT_ID/datasets/DATASET_ID/tables/TABLE_ID"
entry_type = "projects/655216118709/locations/global/entryTypes/bigquery-table"
fully_qualified_name = "bigquery:PROJECT_ID.DATASET_ID.TABLE_ID"
parent_entry = "projects/PROJECT_NUMBER/locations/LOCATION/entryGroups/@bigquery/entries/bigquery.googleapis.com/projects/PROJECT_ID/datasets/DATASET_ID"
aspects {
aspect_key = "655216118709.global.data-rules@Schema.COLUMN_NAME"
aspect {
data = jsonencode({
rules = [
{
name = "RULE_NAME"
dimension = "VALIDITY"
type = "TEMPLATE_REFERENCE"
templateReference = {
name = "projects/TEMPLATE_PROJECT_ID/locations/TEMPLATE_LOCATION/entryGroups/RULE_LIBRARY_ID/entries/TEMPLATE_ID"
values = {
"PARAMETER_NAME" = {
value = "PARAMETER_VALUE"
}
}
}
}
]
})
}
}
}
Replace the following:
PROJECT_NUMBER: the project number of the BigQuery table.PROJECT_ID: the project ID of the BigQuery table.LOCATION: the BigQuery dataset location.DATASET_ID: the BigQuery dataset ID.TABLE_ID: the BigQuery table ID.COLUMN_NAME: the target column name.RULE_NAME: a unique name for the rule. The name must be 1–63 characters, contain only letters, numbers, or hyphens, start with a letter, and end with a letter or number.TEMPLATE_PROJECT_ID: the project ID of the custom rule library, ordataplex-templatesfor a system template.TEMPLATE_LOCATION: the location of the custom template, orglobal.RULE_LIBRARY_ID: the custom rule library ID, orrule-libraryfor a system template.TEMPLATE_ID: the rule template ID.PARAMETER_NAME: the name of an input parameter defined in the template.PARAMETER_VALUE: the string value for the input parameter.
Attach rules to a business glossary term
To enforce organization-wide semantic standards, attach rules to a business glossary term. Every BigQuery column linked to that term automatically inherits its attached rules when you run a catalog-based scan.
Select one of the following options:
Console
In the Google Cloud console, go to the Knowledge Catalog Glossaries page.
Search for and click the business glossary term that you want to govern.
In the Data quality rules section, click Add.
In the Create rules pane, configure the rule:
- In the Choose create option menu, select Create new rule.
- In the Choose rule types menu, select one or more templates in
the glossary's location or in
global. - To enter parameter values, click Edit rule, enter the required values, and then click Save.
To attach the rule to the term, click Save.
To propagate the rules to data assets, link the glossary term to your target BigQuery tables or columns. For instructions, see Manage links between terms and data assets.
REST
To attach rules to a business glossary term, send a PATCH request to the
projects.locations.entryGroups.entries.patch
method on the term's @dataplex entry:
curl -X PATCH \
-H "Authorization: Bearer $(gcloud auth print-access-token)" \
-H "Content-Type: application/json" \
"https://dataplex.googleapis.com/v1/projects/PROJECT_ID/locations/LOCATION/entryGroups/@dataplex/entries/projects/PROJECT_NUMBER/locations/LOCATION/glossaries/GLOSSARY_ID/terms/TERM_ID?updateMask=aspects&aspectKeys=projects/dataplex-types/locations/global/aspectTypes/data-rules" \
-d '{
"aspects": {
"dataplex-types.global.data-rules": {
"aspectType": "projects/dataplex-types/locations/global/aspectTypes/data-rules",
"data": {
"rules": [
{
"name": "RULE_NAME",
"dimension": "VALIDITY",
"type": "TEMPLATE_REFERENCE",
"templateReference": {
"name": "projects/TEMPLATE_PROJECT_ID/locations/TEMPLATE_LOCATION/entryGroups/RULE_LIBRARY_ID/entries/TEMPLATE_ID",
"values": {
"PARAMETER_NAME": {
"value": "PARAMETER_VALUE"
}
}
}
}
]
}
}
}
}'
Replace the following:
PROJECT_ID: the project ID of the business glossary.PROJECT_NUMBER: the project number of the business glossary.LOCATION: the location of the business glossary.GLOSSARY_ID: the business glossary ID.TERM_ID: the glossary term ID.RULE_NAME: a unique name for the rule. The name must be 1–63 characters, contain only letters, numbers, or hyphens, start with a letter, and end with a letter or number.TEMPLATE_PROJECT_ID: the project ID of the custom rule library, ordataplex-templatesfor a system template.TEMPLATE_LOCATION: the location of the custom template, orglobal.RULE_LIBRARY_ID: the custom rule library ID, orrule-libraryfor a system template.TEMPLATE_ID: the rule template ID.PARAMETER_NAME: the name of an input parameter defined in the template.PARAMETER_VALUE: the string value for the input parameter.
Terraform
To attach rules to a business glossary term, use the
google_dataplex_entry
resource in the Terraform Registry. Use 655216118709 (the project number
for dataplex-types) in entry_type and aspect_key:
resource "google_dataplex_entry" "glossary_term_rules" {
project = "PROJECT_NUMBER"
location = "LOCATION"
entry_group_id = "@dataplex"
entry_id = "projects/PROJECT_NUMBER/locations/LOCATION/glossaries/GLOSSARY_ID/terms/TERM_ID"
entry_type = "projects/655216118709/locations/global/entryTypes/glossary-term"
parent_entry = "projects/PROJECT_NUMBER/locations/LOCATION/entryGroups/@dataplex/entries/projects/PROJECT_NUMBER/locations/LOCATION/glossaries/GLOSSARY_ID"
aspects {
aspect_key = "655216118709.global.data-rules"
aspect {
data = jsonencode({
rules = [
{
name = "RULE_NAME"
dimension = "VALIDITY"
type = "TEMPLATE_REFERENCE"
templateReference = {
name = "projects/TEMPLATE_PROJECT_ID/locations/TEMPLATE_LOCATION/entryGroups/RULE_LIBRARY_ID/entries/TEMPLATE_ID"
values = {
"PARAMETER_NAME" = {
value = "PARAMETER_VALUE"
}
}
}
}
]
})
}
}
}
Replace the following:
PROJECT_NUMBER: the project number of the business glossary.LOCATION: the location of the business glossary.GLOSSARY_ID: the business glossary ID.TERM_ID: the glossary term ID.RULE_NAME: a unique name for the rule. The name must be 1–63 characters, contain only letters, numbers, or hyphens, start with a letter, and end with a letter or number.TEMPLATE_PROJECT_ID: the project ID of the custom rule library, ordataplex-templatesfor a system template.TEMPLATE_LOCATION: the location of the custom template, orglobal.RULE_LIBRARY_ID: the custom rule library ID, orrule-libraryfor a system template.TEMPLATE_ID: the rule template ID.PARAMETER_NAME: the name of an input parameter defined in the template.PARAMETER_VALUE: the string value for the input parameter.
Import rules from another BigQuery table
To accelerate setup for tables with similar schemas, copy verified rules from an existing BigQuery table entry onto another table.
Select one of the following options:
Console
In the Google Cloud console, go to the Knowledge Catalog Search page.
Search for and click the target BigQuery table.
Click the Data quality tab, click Rules management, and then click Create rules.
In the Create rules pane, import the rules:
- In the Choose create option menu, select Import rules from another table.
- In Table, click Browse, and then select the source table that contains the rules that you want to copy.
- Select the rules to import, edit parameters if needed, and then click Save.
Verify that the imported rules appear on the Rules management tab.
REST
To import rules using the API, retrieve the data-rules aspects from both
the source and target table entries, merge the rules arrays, and patch the
combined aspects onto the target table entry.
Retrieve the source entry's
data-rulesaspects withview=CUSTOMusing theprojects.locations.entryGroups.entries.getmethod:curl -X GET \ -H "Authorization: Bearer $(gcloud auth print-access-token)" \ "https://dataplex.googleapis.com/v1/projects/PROJECT_ID/locations/LOCATION/entryGroups/@bigquery/entries/bigquery.googleapis.com/projects/PROJECT_ID/datasets/SOURCE_DATASET_ID/tables/SOURCE_TABLE_ID?view=CUSTOM&aspectTypes=projects/dataplex-types/locations/global/aspectTypes/data-rules"Replace the following:
PROJECT_ID: the project ID of the source BigQuery table.LOCATION: the location of the source BigQuery dataset.SOURCE_DATASET_ID: the source BigQuery dataset ID.SOURCE_TABLE_ID: the source BigQuery table ID.
Retrieve the target entry's existing
data-rulesaspects using the sameentries.getrequest with the target table's project, location, dataset, and table IDs. BecausePATCHreplaces each aspect payload wholesale rather than merging nestedrulesarrays, include any existing target rules in yourPATCHrequest to avoid deleting them.Copy the
rulesarray from the source entry'sdataplex-types.global.data-rulesaspect for table-level rules, or from each relevantdataplex-types.global.data-rules@Schema.COLUMN_NAMEaspect key for column-level rules. Merge the copied rules into the correspondingrulesarray from the target entry, ensuring that each rule has a uniquename.Follow the steps in Attach rules to a BigQuery table to patch the combined
rulesarrays onto your target table entry.
View rules attached to a BigQuery table
Before running a catalog-based scan, verify all rules applicable to a table—both rules attached directly and rules inherited from linked business glossary terms.
Select one of the following options:
Console
In the Google Cloud console, go to the Knowledge Catalog Search page.
Search for and click the BigQuery table.
Click the Data quality tab, and then click Rules management.
Verify that all expected direct and glossary-inherited rules appear in the rules table along with their target columns, dimensions, and sources.
REST
To inspect the data-rules aspects attached directly to a
BigQuery table entry, send a GET request to the
projects.locations.entryGroups.entries.get
method with view=CUSTOM:
curl -X GET \
-H "Authorization: Bearer $(gcloud auth print-access-token)" \
"https://dataplex.googleapis.com/v1/projects/PROJECT_ID/locations/LOCATION/entryGroups/@bigquery/entries/bigquery.googleapis.com/projects/PROJECT_ID/datasets/DATASET_ID/tables/TABLE_ID?view=CUSTOM&aspectTypes=projects/dataplex-types/locations/global/aspectTypes/data-rules"
Replace the following:
PROJECT_ID: the project ID of the BigQuery table.LOCATION: the BigQuery dataset location.DATASET_ID: the BigQuery dataset ID.TABLE_ID: the BigQuery table ID.
In the response, inspect each aspects key matching
dataplex-types.global.data-rules (for table-level rules) or
dataplex-types.global.data-rules@Schema.COLUMN_NAME
(for column-level rules) to verify the rule name, dimension, and
templateReference. Rules inherited from linked business glossary terms
appear in the Google Cloud console and resolve automatically when a
catalog-based scan runs.
After confirming that all expected rules appear on the table, continue to Create a scan using catalog-based rules.
Create a scan using catalog-based rules
After attaching rules to a BigQuery table or its linked glossary
terms, create a catalog-based scan using your
execution service account to evaluate those rules
dynamically on every run. You can optionally apply an
AIP-160 filter,
such as attributes.environment = "prod", to run only matching rules.
Select one of the following options:
Console
In the Google Cloud console, go to the Data profiling & quality page.
Follow the initial steps to create a data quality scan, configuring these fields in the Define scan pane:
- In the Credential type menu, select Service account, and then enter your execution service account.
- For Rule type, select Create with entry based rule.
- Click Continue.
In the Data quality rules pane, verify the direct and glossary-inherited rules displayed for the table.
Optional: To run a subset of rules, in the Filter items field, enter an AIP-160 filter, and then click Apply.
Complete the remaining scan configuration. To create the scan without running it, click Create. To create and run the scan immediately, click Run scan.
Subsequent scan runs automatically evaluate the active direct and glossary-inherited rules observed on the table entry at execution time.
REST
To create a catalog-based scan, send a POST request to the
projects.locations.dataScans.create
method with enableCatalogBasedRules set to true:
curl -X POST \
-H "Authorization: Bearer $(gcloud auth print-access-token)" \
-H "Content-Type: application/json" \
"https://dataplex.googleapis.com/v1/projects/PROJECT_ID/locations/LOCATION/dataScans?dataScanId=DATASCAN_ID" \
-d '{
"data": {
"resource": "//bigquery.googleapis.com/projects/BIGQUERY_PROJECT_ID/datasets/DATASET_ID/tables/TABLE_ID"
},
"executionIdentity": {
"serviceAccount": {
"email": "SERVICE_ACCOUNT_EMAIL"
}
},
"executionSpec": {
"trigger": {
"onDemand": {}
}
},
"dataQualitySpec": {
"enableCatalogBasedRules": true,
"filter": "FILTER_CONDITION"
}
}'
Replace the following:
PROJECT_ID: the scan project ID (for example,test-project).LOCATION: the region for the data scan (for example,us-central1).DATASCAN_ID: a unique ID for the data quality scan.BIGQUERY_PROJECT_ID: the project ID that contains the BigQuery table.DATASET_ID: the BigQuery dataset ID.TABLE_ID: the BigQuery table ID.SERVICE_ACCOUNT_EMAIL: the email address of the execution service account.FILTER_CONDITION: an optional AIP-160 filter string to selectively run rules.
Terraform
To create a catalog-based scan, use the
google_dataplex_datascan
resource in the Terraform Registry:
resource "google_dataplex_datascan" "catalog_scan" {
project = "PROJECT_ID"
location = "LOCATION"
data_scan_id = "DATASCAN_ID"
data {
resource = "//bigquery.googleapis.com/projects/BIGQUERY_PROJECT_ID/datasets/DATASET_ID/tables/TABLE_ID"
}
execution_spec {
trigger {
on_demand {}
}
}
execution_identity {
service_account {
email = "SERVICE_ACCOUNT_EMAIL"
}
}
data_quality_spec {
enable_catalog_based_rules = true
filter = "FILTER_CONDITION"
}
}
Replace the following:
PROJECT_ID: the scan project ID (for example,test-project).LOCATION: the region for the data scan (for example,us-central1).DATASCAN_ID: a unique ID for the data quality scan.BIGQUERY_PROJECT_ID: the project ID that contains the BigQuery table.DATASET_ID: the BigQuery dataset ID.TABLE_ID: the BigQuery table ID.SERVICE_ACCOUNT_EMAIL: the email address of the execution service account.FILTER_CONDITION: an optional AIP-160 filter string to selectively run rules.
Run scans and verify results
After you create a template-based or catalog-based scan, run the scan to validate your BigQuery table and inspect the results:
- Trigger an on-demand run or wait for the configured schedule. For instructions, see Run a data quality scan.
- To inspect pass and fail statuses, dimension scores,
assertionRowCount, and theresolvedSqlstatement generated from each rule template, open the scan job results. For instructions, see View the data quality scan results.
Troubleshoot
If a scan fails or expected rules don't run, then check the following common issues:
- Service account impersonation fails: verify that you have the Service
Account User (
roles/iam.serviceAccountUser) role on the execution service account. Also verify that the Dataplex Service Agent (service-PROJECT_NUMBER@gcp-sa-dataplex.) has the Service Account Token Creator (roles/iam.serviceAccountTokenCreator) role on that service account. - Rule template not found: confirm that custom rule templates reside in
the same region as the scan or in
global, and that you have thedataplex.entries.getanddataplex.entries.getDatapermissions on the template's entry group or project. For read-only scan consumers, grant these permissions through a custom role. - Glossary rules don't appear on a table: verify that the business
glossary term has a
data-rulesaspect attached and is explicitly linked to the target BigQuery table or column through an entry link. - Rule fails with a
${column()}error: check that templates referencing${column()}are attached to a specific column path (@Schema.COLUMN_NAME) rather than at the table level.
What's next
- Author and update custom SQL templates in Create and manage rule templates.
- Browse predefined validation checks in System rule templates list.
- Review architecture, SQL syntax, and metric differences in About reusing data quality rules.
- Follow an end-to-end use case in Build a policy-as-code data quality workflow.
- Configure alerts and export scan results in Use auto data quality.