Apply data quality rules and run scans

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 global location.
  • Bulk metadata import jobs don't support importing data-rules aspects.

Before you begin

This document supports two workflows depending on your role and governance goals:

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.

Enable the API

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 @bigquery entry group in the table location
  • Attach rules to business glossary terms: Dataplex Catalog Editor (roles/dataplex.catalogEditor) on the @dataplex entry 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.create on the scan project
    • dataplex.datascans.delete on the scan project
    • dataplex.datascans.get on the scan project
    • dataplex.datascans.getData on the scan project
    • dataplex.datascans.list on the scan project
    • dataplex.datascans.run on the scan project
    • dataplex.datascans.update on the scan project
  • Attach the execution service account: iam.serviceAccounts.actAs on the execution service account
  • Attach rules to BigQuery tables:
    • dataplex.entries.update on the @bigquery entry group in the table location
    • dataplex.entryGroups.useDataRulesAspect on the @bigquery entry group in the table location
  • Attach rules to business glossary terms:
    • dataplex.entries.update on the @dataplex entry group
    • dataplex.entryGroups.useDataRulesAspect on the @dataplex entry group
  • Create catalog-based scans:
    • bigquery.tables.get on the BigQuery table
    • bigquery.tables.getData on 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) or bigquery.tables.update on the table and dataplex.entryGroups.useDataRulesAspect on @bigquery. The REST API and Terraform require dataplex.entries.update on @bigquery.
  • Attach rules to business glossary terms in the Google Cloud console: instead of Dataplex Catalog Editor on @dataplex, you can grant dataplex.glossaryTerms.update on the glossary term and dataplex.entryGroups.useDataRulesAspect on @dataplex. The REST API and Terraform require dataplex.entries.update on @dataplex.
  • Create catalog-based scans: instead of BigQuery Data Viewer on the table, you can grant a custom role with dataplex.entries.get and dataplex.entries.getData on the @bigquery entry 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.get on the BigQuery table to scan and any reference tables queried in SQL templates
    • bigquery.tables.getData on the BigQuery table to scan and any reference tables queried in SQL templates
  • Run validation query jobs: bigquery.jobs.create on the scan project
  • If you export scan results to BigQuery:
    • bigquery.datasets.get on the export dataset and table
    • bigquery.tables.create on the export dataset and table
    • bigquery.tables.get on the export dataset and table
    • bigquery.tables.getData on the export dataset and table
    • bigquery.tables.update on the export dataset and table
    • bigquery.tables.updateData on 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.iam.gserviceaccount.com

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

  1. In the Google Cloud console, go to the Data profiling & quality page.

    Go to Data profiling & quality

  2. Follow the initial steps to create a data quality scan, configuring the following settings in the Define scan pane:

    1. In the Credential type menu, select Service account, and then enter your execution service account.
    2. Click Continue.
  3. In the Data quality rules pane, click Add rules > Template rules.

  4. Select Attach rule to entire table, or in Choose columns, browse and select the target columns.

  5. 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.

  6. To configure template parameter values, click Edit rule, enter the parameter values, and then click Save.

  7. Select the configured rules, click Select, and then click Continue.

  8. 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, or dataplex-templates for a system rule template.
  • TEMPLATE_LOCATION: the location of the custom template, or global for a system template.
  • RULE_LIBRARY_ID: the custom rule library ID, or rule-library for 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, or dataplex-templates for a system rule template.
  • TEMPLATE_LOCATION: the location of the custom template, or global for a system template.
  • RULE_LIBRARY_ID: the custom rule library ID, or rule-library for 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

  1. In the Google Cloud console, go to the Knowledge Catalog Search page.

    Go to Search

  2. Search for and click the BigQuery table entry that you want to govern.

  3. Click the Data quality tab, click Rules management, and then click Create rules.

  4. In the Create rules pane, configure the rule:

    1. In the Choose create option menu, select Create new rule.
    2. In Choose columns, click Browse, and then select the target columns.
    3. In the Choose rule types menu, select one or more templates in the table's location or in global.
    4. To enter parameter values, click Edit rule, enter the required values, and then click Save.
  5. To attach the rules, click Save.

  6. 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-central1 or us).
  • 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, or dataplex-templates for a system template.
  • TEMPLATE_LOCATION: the location of the custom template, or global.
  • RULE_LIBRARY_ID: the custom rule library ID, or rule-library for 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, or dataplex-templates for a system template.
  • TEMPLATE_LOCATION: the location of the custom template, or global.
  • RULE_LIBRARY_ID: the custom rule library ID, or rule-library for 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

  1. In the Google Cloud console, go to the Knowledge Catalog Glossaries page.

    Go to Glossaries

  2. Search for and click the business glossary term that you want to govern.

  3. In the Data quality rules section, click Add.

  4. In the Create rules pane, configure the rule:

    1. In the Choose create option menu, select Create new rule.
    2. In the Choose rule types menu, select one or more templates in the glossary's location or in global.
    3. To enter parameter values, click Edit rule, enter the required values, and then click Save.
  5. To attach the rule to the term, click Save.

  6. 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, or dataplex-templates for a system template.
  • TEMPLATE_LOCATION: the location of the custom template, or global.
  • RULE_LIBRARY_ID: the custom rule library ID, or rule-library for 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, or dataplex-templates for a system template.
  • TEMPLATE_LOCATION: the location of the custom template, or global.
  • RULE_LIBRARY_ID: the custom rule library ID, or rule-library for 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

  1. In the Google Cloud console, go to the Knowledge Catalog Search page.

    Go to Search

  2. Search for and click the target BigQuery table.

  3. Click the Data quality tab, click Rules management, and then click Create rules.

  4. In the Create rules pane, import the rules:

    1. In the Choose create option menu, select Import rules from another table.
    2. In Table, click Browse, and then select the source table that contains the rules that you want to copy.
    3. Select the rules to import, edit parameters if needed, and then click Save.
  5. 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.

  1. Retrieve the source entry's data-rules aspects with view=CUSTOM using the projects.locations.entryGroups.entries.get method:

    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.
  2. Retrieve the target entry's existing data-rules aspects using the same entries.get request with the target table's project, location, dataset, and table IDs. Because PATCH replaces each aspect payload wholesale rather than merging nested rules arrays, include any existing target rules in your PATCH request to avoid deleting them.

  3. Copy the rules array from the source entry's dataplex-types.global.data-rules aspect for table-level rules, or from each relevant dataplex-types.global.data-rules@Schema.COLUMN_NAME aspect key for column-level rules. Merge the copied rules into the corresponding rules array from the target entry, ensuring that each rule has a unique name.

  4. Follow the steps in Attach rules to a BigQuery table to patch the combined rules arrays 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

  1. In the Google Cloud console, go to the Knowledge Catalog Search page.

    Go to Search

  2. Search for and click the BigQuery table.

  3. Click the Data quality tab, and then click Rules management.

  4. 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

  1. In the Google Cloud console, go to the Data profiling & quality page.

    Go to Data profiling & quality

  2. Follow the initial steps to create a data quality scan, configuring these fields in the Define scan pane:

    1. In the Credential type menu, select Service account, and then enter your execution service account.
    2. For Rule type, select Create with entry based rule.
    3. Click Continue.
  3. In the Data quality rules pane, verify the direct and glossary-inherited rules displayed for the table.

  4. Optional: To run a subset of rules, in the Filter items field, enter an AIP-160 filter, and then click Apply.

  5. 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:

  1. Trigger an on-demand run or wait for the configured schedule. For instructions, see Run a data quality scan.
  2. To inspect pass and fail statuses, dimension scores, assertionRowCount, and the resolvedSql statement 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.iam.gserviceaccount.com) 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 the dataplex.entries.get and dataplex.entries.getData permissions 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-rules aspect 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