Viewing labels
This page explains how to view labels on your BigQuery resources.
You can view labels by:
- Using the Google Cloud console
- Querying
INFORMATION_SCHEMA
views - Using the bq command-line tool's
bq show
command - Calling the
datasets.get
ortables.get
API methods - Using the client libraries
Because views are treated like table resources, you use the tables.get
method to get label information for both views and tables.
Before you begin
Grant Identity and Access Management (IAM) roles that give users the necessary permissions to perform each task in this document.
Required permissions
The permissions required for viewing labels depend on the types of resources you can access. To perform the tasks in this document, you need the following permissions.
Permissions to view dataset details
To view dataset details, you need the bigquery.datasets.get
IAM permission.
Each of the following predefined IAM roles includes the permissions that you need in order to view dataset details:
roles/bigquery.user
roles/bigquery.metadataViewer
roles/bigquery.dataViewer
roles/bigquery.dataOwner
roles/bigquery.dataEditor
roles/bigquery.admin
Additionally, if you have the bigquery.datasets.create
permission, you can view details of the datasets that you create.
For more information on IAM roles and permissions in BigQuery, see Predefined roles and permissions.
Permissions to view table or view details
To view table or view details, you need the bigquery.tables.get
IAM permission.
All predefined IAM roles include the permissions that you need in order to view table or view details except for roles/bigquery.user
and roles/bigquery.jobUser
.
Additionally, if you have the bigquery.datasets.create
permission, you can view details of the tables and views in the datasets that you create.
For more information on IAM roles and permissions in BigQuery, see Predefined roles and permissions.
Permissions to job details
To view job details, you need the bigquery.jobs.get
IAM
permission.
Each of the following predefined IAM roles includes the permissions that you need in order to view job details:
roles/bigquery.admin
(lets you view details of all the jobs in the project)roles/bigquery.user
(lets you view details of your jobs)roles/bigquery.jobUser
(lets you view details of your jobs)
For more information on IAM roles and permissions in BigQuery, see Predefined roles and permissions.
Viewing dataset, table, and view labels
To view a resource's labels, select one of the following options:
Console
For datasets, the dataset details page is automatically opened. For tables and views, click Details to open the details page. Label information appears in the information table for the resource.
SQL
Query the
INFORMATION_SCHEMA.SCHEMATA_OPTIONS
view
to see the labels on a dataset, or the
INFORMATION_SCHEMA.TABLE_OPTIONS
view
to see the labels on a table. For example, the following SQL query returns
the labels on the dataset named mydataset
:
In the Google Cloud console, go to the BigQuery page.
In the query editor, enter the following statement:
SELECT * FROM INFORMATION_SCHEMA.SCHEMATA_OPTIONS WHERE schema_name = 'mydataset' AND option_name = 'labels';
Click
Run.
For more information about how to run queries, see Run an interactive query.
bq
Use the bq show
command with the resource ID. The --format
flag can be
used to control the output. If the resource is in a project other than your
default project, add the project ID in the following format:
[PROJECT_ID]:[DATASET]
. For readability, the output is controlled by
setting the --format
flag to pretty
.
bq show --format=pretty [RESOURCE_ID]
Where [RESOURCE_ID]
is a valid dataset, table, view, or job ID.
Examples:
Enter the following command to display labels for mydataset
in your
default project.
bq show --format=pretty mydataset
The output looks like the following:
+-----------------+--------------------------------------------------------+---------------------+ | Last modified | ACLs | Labels | +-----------------+--------------------------------------------------------+---------------------+ | 11 Jul 19:34:34 | Owners: | department:shipping | | | projectOwners, | | | | Writers: | | | | projectWriters | | | | Readers: | | | | projectReaders | | +-----------------+--------------------------------------------------------+---------------------+
Enter the following command to display labels for mydataset.mytable
.
mydataset
is in myotherproject
, not your default project.
bq show --format=pretty myotherproject:mydataset.mytable
The output looks like the following for a clustered table:
+-----------------+------------------------------+------------+-------------+-----------------+------------------------------------------------+------------------+---------+ | Last modified | Schema | Total Rows | Total Bytes | Expiration | Time Partitioning | Clustered Fields | Labels | +-----------------+------------------------------+------------+-------------+-----------------+------------------------------------------------+------------------+---------+ | 25 Jun 19:28:14 | |- timestamp: timestamp | 0 | 0 | 25 Jul 19:28:14 | DAY (field: timestamp, expirationMs: 86400000) | customer_id | org:dev | | | |- customer_id: string | | | | | | | | | |- transaction_amount: float | | | | | | | +-----------------+------------------------------+------------+-------------+-----------------+------------------------------------------------+------------------+---------+
API
Call the datasets.get
method or the tables.get
method. The response includes all labels associated with that resource.
Alternatively, you can use datasets.list
to view the labels for multiple datasets or tables.list
to view the labels for multiple tables and views.
Because views are treated like table resources, you use the tables.get
and tables.list
methods to view label information for both views and
tables.
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 client libraries.
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 client libraries.
Node.js
Before trying this sample, follow the Node.js setup instructions in the BigQuery quickstart using client libraries. For more information, see the BigQuery Node.js API reference documentation.
To authenticate to BigQuery, set up Application Default Credentials. For more information, see Set up authentication for client libraries.
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 client libraries.
Viewing table labels
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 client libraries.
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 client libraries.
Node.js
Before trying this sample, follow the Node.js setup instructions in the BigQuery quickstart using client libraries. For more information, see the BigQuery Node.js API reference documentation.
To authenticate to BigQuery, set up Application Default Credentials. For more information, see Set up authentication for client libraries.
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 client libraries.
Viewing job labels
To see the labels on a job, select one of the following options:
SQL
Query the
INFORMATION_SCHEMA.JOB_BY_*
views
to see the labels on a job. For example, the following SQL query returns the
query text and labels on the jobs submitted by the current user in the
current project:
In the Google Cloud console, go to the BigQuery page.
In the query editor, enter the following statement:
SELECT query, labels FROM INFORMATION_SCHEMA.JOBS_BY_USER;
Click
Run.
For more information about how to run queries, see Run an interactive query.
bq
To see the labels for a query job using the bq command-line tool, enter
the bq show -j
command with the query job's job ID. The --format
flag
can be used to control the output. For example, if your query job has job ID
bqjob_r1234d57f78901_000023746d4q12_1
, enter the following command:
bq show -j --format=pretty bqjob_r1234d57f78901_000023746d4q12_1
The output should look like the following:
+----------+---------+-----------------+----------+-------------------+-----------------+--------------+----------------------+ | Job Type | State | Start Time | Duration | User Email | Bytes Processed | Bytes Billed | Labels | +----------+---------+-----------------+----------+-------------------+-----------------+--------------+----------------------+ | query | SUCCESS | 03 Dec 15:00:41 | 0:00:00 | [email protected] | 255 | 10485760 | department:shipping | | | | | | | | | costcenter:logistics | +----------+---------+-----------------+----------+-------------------+-----------------+--------------+----------------------+
API
Call the jobs.get
method. The response includes all labels associated with that resource.
What's next
- Learn how to add labels to BigQuery resources.
- Learn how to update labels on BigQuery resources.
- Learn how to filter resources using labels.
- Learn how to delete labels on BigQuery resources.
- Read about Using labels in the Resource Manager documentation.