Create and manage logical views
In Bigtable, alogical view is the result of a SQL query thatfunctions as a virtual table that can be queried by other SQL queries. Dataremains in the source table.
This document describes logical views and how to create and perform operationson them. For a comparison with continuous materialized views and authorized views, seeTables and views.
Logical views let you do the following with your Bigtable data:
- Avoid query repetition: You can store and evolve column mapping and castlogic in a logical view, which additional logical views can use instead ofcopying and pasting that logic or needing to understand it.
- Integrate with systems designed to read from relational databases:Logical views let you make your Bigtable data read like arelational database table or Cassandra table.
- Run the same logical view against many tables: By modifying the
FROMclause, you can use the same view to query any table in yourBigtable instance. - Provide a consistent interface: Your application can use a logical vieweven if the source table changes.
- Limit read access to specific columns or rows: You can expose only thedata that you want to allow users to read, without giving them access to theentire table.
A logical view is an instance-level resource. You can create a logical viewusing the Google Cloud CLI or the Bigtable Studio query editor inthe Google Cloud console. To query a logical view, you can use theBigtable Studio query editor or any of the Bigtableclient libraries that supportSQL.
A logical view has the following characteristics:
- Must use SQL features supported byGoogleSQL forBigtable
- Read-only
- Must be read with SQL rather than with a call to
ReadRows - Can be queried using any of the Bigtableclient libraries that supportSQL
- Usesdefiner rights. You can query a logical view if you have permissionsto read from it even if you don't have permission to read from the sourcetable.
The row key, column qualifier, and column values that you use to define alogical view are treated as service data. For this reason, don'tcreate a logical view using row key, column qualifier, orcolumn values that containsensitiveinformation. For information about howservice data is handled, see theGoogle Cloud PrivacyNotice.
Before you begin
Take the following steps if you plan to use the gcloud CLI:
Install the Google Cloud CLI.
Note: If you installed the gcloud CLI previously, make sure you have the latest version by runninggcloud components update.If you're using an external identity provider (IdP), you must first sign in to the gcloud CLI with your federated identity.
Toinitialize the gcloud CLI, run the following command:
Note: You can run the gcloud CLI in the Google Cloud console without installing the Google Cloud CLI. To run the gcloud CLI in the Google Cloud console,use Cloud Shell.gcloudinit
Method not found message, runthegcloud auth login command again.Required roles
To work with logical views, you need the following permissions:
To manage logical views:
- To create, update, or delete logical views, you need theBigtable Admin (
roles/bigtable.admin) role on the instance. - Alternatively, you can ask your administrator to grant you the followingpermissions at the instance level:
- Create:
bigtable.logicalViews.create - Update:
bigtable.logicalViews.update - Delete:
bigtable.logicalViews.delete
- Create:
To view and query logical views:
- To list or describe logical views, you need the BigtableReader (
roles/bigtable.reader) role on the instance. Alternatively, you can ask your administrator to grant you the followingpermissions at the instance level:
- List:
bigtable.logicalViews.list - Describe:
bigtable.logicalViews.get
- List:
To query a logical view, you need the
Note: You don't need permission to read the source table.bigtable.logicalViews.readRowspermission on the logical view.
To create a logical view:
- You must have at least
bigtable.tables.readRowspermission on the sourcetable.
To grant read access to a specific view:
You can grant a user permission to read a specific logical view, even if theydon't have any other Bigtable permissions. To do this, use anIAM condition to grant thebigtable.logicalViews.readRowspermission only on that view:
- Grant the user the
bigtable.readerrole on the project. Create an IAM condition that limits the
bigtable.logicalViews.readRowspermission to the specific logical view.For example:resource.name == projects/PROJECT_ID/instances/INSTANCE_ID/logicalViews/VIEWReplace the following:
PROJECT_ID: the Google Cloud project thatyour Bigtable instance is in.VIEW: an ID up to 128 characters long for the newlogical view. The ID must be unique among table IDs and view IDs in the instance.INSTANCE_ID: the ID of instance to create the logical view in.
For more information, seeManage access to resources using IAM conditions.
For more information about all available roles and permissions, seeBigtable access control with IAM.
Create a logical view
Console
Open the list of Bigtable instances in the Google Cloud console.
Select an instance.
In the navigation pane, clickBigtable Studio.
Open a new tab by clicking andthen choosingEditor.
In the query editor, write your query. If the query isvalid SQL, aValid message is displayed.
Optional: To format your statement in SQL style, clickFormat.
ClickRun. The results of your query appear in theResults table.
When you're satisfied with the query, click theSave as expander arrow and chooseSave as logical view.
In theSave your logical view dialog, enter a name for the view, andthen clickSave.
For more information about using the query editor, seeManage yourdata using BigtableStudio.
gcloud
To create a logical view, use thegcloud bigtable logical-views createcommand.
gcloudbigtablelogical-viewscreateVIEW\--instance=INSTANCE--query=QUERYReplace the following:
VIEW: an ID up to 128 characters long for the newlogical view. The ID must be unique among table IDs and view IDs in the instance.QUERY: a valid GoogleSQL forBigtable queryINSTANCE: the ID of instance to create the logical view in
Optional:
- To protect the logical view from deletion, append the command with the
--deletion-protectionflag. If you don't apply this setting, the logical view canbe deleted. You can also explicitly allow logical view deletion by appending--no-deletion-protection. For more information, see theUpdate a logical view section of this document.
Update a logical view
Console
You can't update deletion protection for a logical view in theGoogle Cloud console. To enable or disable deletion protection, use theGoogle Cloud CLI.
Open the list of Bigtable instances in the Google Cloud console.
Select an instance from the list.
In the navigation pane, clickBigtable Studio. A list of viewsis displayed in the explorer.
Optional: The first 10 views in the instance are listed. To see 10 more,clickShow more.
Next to the view that you want to update, click themore_vert action menu,and then clickView definition.
Modify the query.
ClickRun.
After you've verified that the results pane shows data that should beincluded in the view, clickSave as.
In the dialog, enter the ID of the view that youmodified.
The dialog displays a message warning you that you are overwriting theexisting view.
ClickSave.
gcloud
To update a logical view to run a different query or to modify deletionprotection, use thegcloud bigtable logical-views updatecommand. You must specify the query, deletion protection, or both.
To update a logical view's query:
gcloudbigtablelogical-viewsupdateVIEW\--instance=INSTANCE--query=QUERYTo enable deletion protection for a logical view:
gcloudbigtablelogical-viewsupdateVIEW\--instance=INSTANCE\--deletion-protection=trueTo disable deletion protection for a logical view:
gcloudbigtablelogical-viewsupdateVIEW\--instance=INSTANCE\--deletion-protection=falseReplace the following:
VIEW: the ID of the logical view to updateINSTANCE: the ID of instance that contains thelogical viewQUERY: a valid GoogleSQL query
Delete a logical view
This action is permanent.
If a logical view has deletion protection enabled, you can't delete it. Todelete a logical view that has deletion protection enabled, you must update thelogical view to disable deletion protection. For more information, see theUpdate a logical view section of this document.
Console
Open the list of Bigtable instances in the Google Cloud console.
Select an instance from the list.
In the navigation pane, clickBigtable Studio. A list of viewsis displayed in the explorer.
Optional: The first 10 views in the instance are listed. To see 10 more,clickShow more.
ExpandViews.
Next to the view that you want to delete, click themore_vert action menu,and then clickDelete.
gcloud
To delete a logical view, use thegcloud bigtable logical-views deletecommand.
gcloudbigtablelogical-viewsdeleteVIEW\--instance=INSTANCEReplace the following:
VIEW: the ID of the logical view to updateINSTANCE: the ID of instance that contains thelogical view
Get a list of logical views for an instance
You can see a list of logical views for an instance.
Console
Open the list of Bigtable instances in the Google Cloud console.
Select an instance from the list.
In the navigation pane, clickBigtable Studio. A list of viewsis displayed in the explorer.
Optional: The first 10 views in the instance are listed. To see 10 more,clickShow more.
gcloud
To see a list of logical views for an instance, use thegcloud bigtable logical-views listcommand.
gcloudbigtablelogical-viewslist--instance=INSTANCEReplaceINSTANCE with the instance ID.
Describe a logical view
To get details about a logical view, use thegcloud bigtable logical-viewsdescribe command.
gcloudbigtablelogical-viewsdescribeVIEW\--instance=INSTANCEThe terminal displays details similar to the following:
createTime:'2025-03-07T19:49:56.316578Z'etag:W/"/v1/17919275593532352351"name:projects/my-project/instances/my-instance/logicalViews/my-viewquery:SELECTstreetFROMaddressesupdateTime:'2025-03-07T19:49:56.316578Z'deletion_protection:trueQuery a logical view
After you create a logical view, you can query it using SQL, much like you querya regular table. You can use logical views in theFROM clause ofSELECTstatements.
In the query editor, enter a GoogleSQL query that references the viewname. For example, if your view is namedMyLogicalView:
SELECT*FROMMyLogicalViewLIMIT100;For more information about executing SQL queries in Bigtable, seeQuery your data with SQL in the query editor.
What's next
Except as otherwise noted, the content of this page is licensed under theCreative Commons Attribution 4.0 License, and code samples are licensed under theApache 2.0 License. For details, see theGoogle Developers Site Policies. Java is a registered trademark of Oracle and/or its affiliates.
Last updated 2025-12-15 UTC.