Profile your data
This document explains how to use data profile scans to better understand your data. BigQuery uses Knowledge Catalog to analyze the statistical characteristics of your data, such as average values, unique values, and maximum values. Knowledge Catalog also uses this information to recommend rules for data quality checks.
For more information about data profiling, see About data profiling.
Before you begin
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.
Required roles
This section describes the IAM roles and permissions needed to use Knowledge Catalog data profile scans.
User roles and permissions
To get the permissions that you need to create and manage data profile scans, ask your administrator to grant you the following IAM roles:
-
Create, run, update, and delete data profile scans:
Dataplex DataScan Editor (
roles/dataplex.dataScanEditor) on the project containing the data scan -
View data profile scan results, jobs, and history:
Dataplex DataScan Viewer (
roles/dataplex.dataScanViewer) on the project containing the data scan -
Publish data profile scan results to Knowledge Catalog:
Dataplex Catalog Editor (
roles/dataplex.catalogEditor) on the@bigqueryentry group -
View published data profile scan results in BigQuery on the Data profile tab:
BigQuery Data Viewer (
roles/bigquery.dataViewer) on the table -
Run data profile scans:
- BigQuery Job User (
roles/bigquery.jobUser) on the project running the scan (all table types) - BigQuery Data Viewer (
roles/bigquery.dataViewer) on the BigQuery tables being scanned
- BigQuery Job User (
-
Run data profile scans against BigQuery external tables that use Cloud Storage data:
- Storage Object Viewer (
roles/storage.objectViewer) on the Cloud Storage bucket (Cloud Storage, Apache Hive, and Iceberg REST catalog) - Storage Legacy Bucket Reader (
roles/storage.legacyBucketReader) on the Cloud Storage bucket
- Storage Object Viewer (
-
Run data profile scans for Iceberg REST Catalog, SAP BDC Delta Lake, and Apache Hive tables on Google Cloud Lakehouse:
BigLake Viewer (
roles/biglake.viewer) on the tables being scanned -
Export data profile scan results to a BigQuery table:
BigQuery Data Editor (
roles/bigquery.dataEditor) on the table
For more information about granting roles, see Manage access to projects, folders, and organizations.
These predefined roles contain the permissions required to create and manage data profile scans. To see the exact permissions that are required, expand the Required permissions section:
Required permissions
The following permissions are required to create and manage data profile scans:
-
Create, run, update, and delete data profile scans:
-
dataplex.datascans.createon project -
dataplex.datascans.updateon data scan -
dataplex.datascans.deleteon data scan -
dataplex.datascans.runon data scan -
dataplex.datascans.geton data scan -
dataplex.datascans.liston project -
dataplex.dataScanJobs.geton data scan job -
dataplex.dataScanJobs.liston data scan
-
-
View data profile scan results, jobs, and history:
-
dataplex.datascans.getDataon data scan -
dataplex.datascans.liston project -
dataplex.dataScanJobs.geton data scan job -
dataplex.dataScanJobs.liston data scan
-
-
Publish data profile scan results to Knowledge Catalog:
-
dataplex.entryGroups.useDataProfileAspecton entry group -
bigquery.tables.updateon table -
dataplex.entries.updateon entry
-
-
View published data profile results for a table in BigQuery or Knowledge Catalog:
-
bigquery.tables.geton table -
bigquery.tables.getDataon table
-
You might also be able to get these permissions with custom roles or other predefined roles.
Knowledge Catalog service account roles and permissions
Whichever execution identity you select (the default Knowledge Catalog Service Agent, a custom service account, or End-User Credentials), that identity requires the following roles and permissions to run the data profile scan jobs in the backend and export results.
To ensure that the execution identity has the necessary permissions to run data profile scans and export results, ask your administrator to grant the following IAM roles to the execution identity:
-
Run data profile scans:
- BigQuery Job User (
roles/bigquery.jobUser) on the project running the scan (all table types) - BigQuery Data Viewer (
roles/bigquery.dataViewer) on the BigQuery tables being scanned
- BigQuery Job User (
-
Run data profile scans for BigQuery external tables that use Cloud Storage data:
- Storage Object Viewer (
roles/storage.objectViewer) on Cloud Storage bucket - Storage Legacy Bucket Reader (
roles/storage.legacyBucketReader) on the Cloud Storage bucket
- Storage Object Viewer (
-
Run data profile scans for Iceberg REST Catalog, SAP BDC Delta Lake, and Apache Hive tables on Google Cloud Lakehouse:
BigLake Viewer (
roles/biglake.viewer) on the tables being scanned -
Export data profile scan results to a BigQuery table:
BigQuery Data Editor (
roles/bigquery.dataEditor) on the table
For more information about granting roles, see Manage access to projects, folders, and organizations.
These predefined roles contain the permissions required to run data profile scans and export results. To see the exact permissions that are required, expand the Required permissions section:
Required permissions
The following permissions are required to run data profile scans and export results:
-
Run data profile scans against BigQuery data:
-
bigquery.jobs.createon project -
bigquery.tables.geton table -
bigquery.tables.getDataon table
-
-
Run data profile scans for BigQuery external tables that use Cloud Storage data:
-
storage.buckets.geton bucket -
storage.objects.geton object
-
-
Export data profile scan results to a BigQuery table:
-
bigquery.tables.createon dataset -
bigquery.tables.updateDataon table
-
Your administrator might also be able to give the execution identity these permissions with custom roles or other predefined roles.
If a table uses BigQuery row-level
security, then Knowledge Catalog
can only scan rows visible to the Knowledge Catalog service account. To
let Knowledge Catalog scan all rows, add its service account to a row
filter where the predicate is TRUE.
If a table uses BigQuery column-level security, then Knowledge Catalog
requires access to scan protected columns. To grant access, give the
Knowledge Catalog service account the
Data Catalog Fine-Grained Reader (roles/datacatalog.fineGrainedReader)
role on all policy tags used in the table. The user creating or updating a data
scan also needs permissions on protected columns.
Grant roles to the Knowledge Catalog service account
To run data profile scans, Knowledge Catalog uses a service account that requires permissions to run BigQuery jobs and read BigQuery table data. To grant the required roles, follow these steps:
Get the Knowledge Catalog service account email address. If you haven't created a data profile or data quality scan in this project before, run the following
gcloudcommand to generate the service identity:gcloud beta services identity create --service=dataplex.googleapis.comThe command returns the service account email, which has the following format: service-PROJECT_ID@gcp-sa-dataplex.iam.gserviceaccount.com.
If the service account already exists, you can find its email by viewing principals with the Dataplex name on the IAM page in the Google Cloud console.
Grant the service account the BigQuery Job User (
roles/bigquery.jobUser) role on your project. This role lets the service account run BigQuery jobs for the scan.gcloud projects add-iam-policy-binding PROJECT_ID \ --member="serviceAccount:service-PROJECT_NUMBER@gcp-sa-dataplex.iam.gserviceaccount.com" \ --role="roles/bigquery.jobUser"Replace the following:
PROJECT_ID: your Google Cloud project ID.service-PROJECT_NUMBER@gcp-sa-dataplex.iam.gserviceaccount.com: the email of the Knowledge Catalog service account.
Grant the service account the BigQuery Data Viewer (
roles/bigquery.dataViewer) role for each table that you want to profile. This role grants read-only access to the tables.gcloud bigquery tables add-iam-policy-binding DATASET_ID.TABLE_ID \ --member="serviceAccount:service-PROJECT_NUMBER@gcp-sa-dataplex.iam.gserviceaccount.com" \ --role="roles/bigquery.dataViewer"Replace the following:
DATASET_ID: the ID of the dataset containing the table.TABLE_ID: the ID of the table to profile.service-PROJECT_NUMBER@gcp-sa-dataplex.iam.gserviceaccount.com: the email of the Knowledge Catalog service account.
Create a data profile scan
Console
In the Google Cloud console, on the BigQuery Metadata curation page, go to the Data profiling & quality tab.
Click Create data profile scan.
Optional: Enter a Display name.
Enter an ID. See the Resource naming conventions.
Optional: Enter a Description.
In the Table field, click Browse. Choose the table to scan, and then click Select. Only standard BigQuery, Iceberg REST Catalog, SAP BDC Delta Lake, and Apache Hive on Google Cloud Lakehousetables are supported.
For tables in multi-region datasets, choose a region where to create the data scan.
To browse the tables organized within Knowledge Catalog lakes, click Browse within Knowledge Catalog Lakes.
In the Mode section, select one of the following options:
Standard: profiles your data with customizable scan settings. This is the default mode.
Lightweight: provides quick insights with a low-latency, low-fidelity scan.
If you chose the Standard mode, configure the following options. These options don't appear when you select Lightweight mode.
In the Scope field, choose Incremental or Entire data.
If you choose Incremental data, in the Timestamp column field, select a column of type
DATEorTIMESTAMPfrom your BigQuery table. Knowledge Catalog uses this column to identify new records as they're added. For tables partitioned on a column of typeDATEorTIMESTAMP, it's recommended to use this column as the partition column.Optional: To filter your data, do any of the following:
To filter by rows, select the Filter rows checkbox. Enter a valid SQL expression that can be used in a
WHEREclause in GoogleSQL syntax. For example:col1 >= 0.The filter can be a combination of SQL conditions over multiple columns. For example:
col1 >= 0 AND col2 < 10.To filter by columns, select the Filter columns checkbox.
To include columns in the profile scan, in the Include columns field, click Browse. Select the columns to include, and then click Select.
To exclude columns from the profile scan, in the Exclude columns field, click Browse. Select the columns to exclude, and then click Select.
To apply sampling to your data profile scan, in the Sampling size list, select a sampling percentage. Choose a percentage value that ranges between 0.0% and 100.0% with up to 3 decimal digits.
For larger datasets, choose a lower sampling percentage. For example, for a 1 PB table, if you enter a value between 0.1% and 1.0%, the data profile samples between 1-10 TB of data.
There must be at least 100 records in the sampled data to return a result.
For incremental data scans, the data profile scan applies sampling to the latest increment.
Optional: Publish the data profile scan results in the BigQuery and Knowledge Catalog pages in the Google Cloud console for the source table. Select the Publish results to Knowledge Catalog checkbox.
You can view the latest scan results in the Data profile tab in the BigQuery and Knowledge Catalog pages for the source table. To let users access the published scan results, see the Grant access to data profile scan results section of this document.
The publishing option might not be available in the following cases:
- You don't have the required permissions on the table.
- Another data profile scan is set to publish results.
In the Schedule section, choose one of the following options:
Repeat: Run the data profile scan on a schedule: hourly, daily, weekly, monthly, or custom. Specify how often the scan should run and at what time. If you choose custom, use cron format to specify the schedule.
On-demand: Run the data profile scan on demand.
One-time run: Run the data profile scan once now, and remove the scan after the auto-deletion time. This feature's in Preview.
- Set post-scan results auto-deletion: The auto-deletion time defines the duration a data profile scan remains active after execution. A data profile scan without a specified auto-deletion time is automatically removed after 24 hours. The auto-deletion time can range from 0 seconds (immediate deletion) to 365 days.
Click Continue.
Optional: Export the scan results to a BigQuery standard table. In the Export scan results to BigQuery table section, do the following:
In the Select BigQuery dataset field, click Browse. Select a BigQuery dataset to store the data profile scan results.
In the BigQuery table field, specify the table to store the data profile scan results. If you're using an existing table, make sure that it's compatible with the export table schema. If the specified table doesn't exist, Knowledge Catalog creates it for you.
Optional: Add labels. Labels are key-value pairs that let you group related objects together or with other Google Cloud resources.
To create the scan, click Create.
If you set the schedule to on-demand, you can also run the scan now by clicking Run scan.
gcloud
To create a data profile scan, use the
gcloud dataplex datascans create data-profile command.
If the source data is organized in a Knowledge Catalog lake, include
the --data-source-entity flag:
gcloud dataplex datascans create data-profile DATASCAN \ --location=LOCATION \ --data-source-entity=DATA_SOURCE_ENTITY
If the source data isn't organized in a Knowledge Catalog lake, include
the --data-source-resource flag:
gcloud dataplex datascans create data-profile DATASCAN \ --location=LOCATION \ --data-source-resource=DATA_SOURCE_RESOURCE
Replace the following variables:
DATASCAN: The name of the data profile scan.LOCATION: The Google Cloud region in which to create the data profile scan.DATA_SOURCE_ENTITY: The Knowledge Catalog entity that contains the data for the data profile scan. For example,projects/test-project/locations/test-location/lakes/test-lake/zones/test-zone/entities/test-entity.DATA_SOURCE_RESOURCE: The name of the resource that contains the data for the data profile scan. For example,//bigquery.googleapis.com/projects/test-project/datasets/test-dataset/tables/test-table.
C#
Before trying this sample, follow the C# setup instructions in the
BigQuery quickstart using
client libraries.
For more information, see the
BigQuery C# API
reference documentation.
To authenticate to BigQuery, set up Application Default Credentials.
For more information, see
Set up authentication for a local development environment.
C#
Go
Go
Before trying this sample, follow the Go setup instructions in the BigQuery quickstart using client libraries. For more information, see the BigQuery Go API reference documentation.
To authenticate to BigQuery, set up Application Default Credentials. For more information, see Set up authentication for a local development environment.
Java
Java
Before trying this sample, follow the Java setup instructions in the BigQuery quickstart using client libraries. For more information, see the BigQuery Java API reference documentation.
To authenticate to BigQuery, set up Application Default Credentials. For more information, see Set up authentication for a local development environment.
Python
Python
Before trying this sample, follow the Python setup instructions in the BigQuery quickstart using client libraries. For more information, see the BigQuery Python API reference documentation.
To authenticate to BigQuery, set up Application Default Credentials. For more information, see Set up authentication for a local development environment.
Ruby
Ruby
Before trying this sample, follow the Ruby setup instructions in the BigQuery quickstart using client libraries. For more information, see the BigQuery Ruby API reference documentation.
To authenticate to BigQuery, set up Application Default Credentials. For more information, see Set up authentication for a local development environment.
REST
To create a data profile scan, use the
dataScans.create method.
Create multiple data profile scans
You can configure data profile scans for multiple tables in a BigQuery dataset at the same time by using the Google Cloud console.
In the Google Cloud console, on the BigQuery Metadata curation page, go to the Data profiling & quality tab.
Click Create data profile scan.
Select the Multiple data profile scans option.
Enter an ID prefix. Knowledge Catalog automatically generates scan IDs by using the provided prefix and unique suffixes.
Enter a Description for all of the data profile scans.
In the Dataset field, click Browse. Select a dataset to pick tables from. Click Select.
If the dataset is multi-regional, select a Region in which to create the data profile scans.
In the Mode section, choose one of the following options:
Standard: profiles your data with customizable scan settings. This is the default mode.
Lightweight: provides quick insights with a low-latency, low-fidelity scan. This feature is in Preview.
If you chose the Standard mode, configure the following settings for the scans. These settings don't appear when Lightweight mode is selected.
In the Scope field, choose Incremental or Entire data.
If you choose Incremental data, you can select only tables that are partitioned on a column of type
DATEorTIMESTAMP.To apply sampling to the data profile scans, in the Sampling size list, select a sampling percentage.
Choose a percentage value between 0.0% and 100.0% with up to 3 decimal digits.
Optional: Publish the data profile scan results in the BigQuery and Knowledge Catalog pages in the Google Cloud console for the source table. Select the Publish results to Knowledge Catalog checkbox.
You can view the latest scan results in the Data profile tab in the BigQuery and Knowledge Catalog pages for the source table. To let users access the published scan results, see the Grant access to data profile scan results section of this document.
In the Schedule section, choose one of the following options:
Repeat: Run the data profile scans on a schedule: hourly, daily, weekly, monthly, or custom. Specify how often the scans should run and at what time. If you choose custom, use cron format to specify the schedule.
On-demand: Run the data profile scans on demand.
One-time run: Run the data profile scan once now, and remove the scan after the auto-deletion time. This feature's in Preview.
- Set post-scan results auto-deletion: The auto-deletion time defines the duration a data profile scan remains active after execution. A data profile scan without a specified auto-deletion time is automatically removed after 24 hours. The auto-deletion time can range from 0 seconds (immediate deletion) to 365 days.
Click Continue.
In the Choose tables field, click Browse. Choose one or more tables to scan, and then click Select.
Click Continue.
Optional: Export the scan results to a BigQuery standard table. In the Export scan results to BigQuery table section, do the following:
In the Select BigQuery dataset field, click Browse. Select a BigQuery dataset to store the data profile scan results.
In the BigQuery table field, specify the table to store the data profile scan results. If you're using an existing table, make sure that it's compatible with the export table schema. If the specified table doesn't exist, Knowledge Catalog creates it for you.
Knowledge Catalog uses the same results table for all of the data profile scans.
Optional: Add labels. Labels are key-value pairs that let you group related objects together or with other Google Cloud resources.
To create the scans, click Create.
If you set the schedule to on-demand, you can also run the scans now by clicking Run scan.
Run a data profile scan
Console
- In the Google Cloud console, on the BigQuery Metadata curation page, go to the Data profiling & quality tab.
Go to Data profiling & quality
