Create and manage protobuf schemas

Preview

This product or feature is subject to the "Pre-GA Offerings Terms" in the General Service Terms section of theService Specific Terms. Pre-GA products and features are available "as is" and might have limited support. For more information, see thelaunch stage descriptions.

This document describes how to create and perform operations on schema bundles.

In Bigtable, you can useprotocol buffer (protobuf) schemas to query individual fieldswithin protobuf messages stored as bytes in your columns.You do this by uploading your schemas in aschema bundle, a table-levelresource that contains one or more of your protobuf schemas.

Using schema bundles offers the following benefits:

  • Saves time and effort: With protocol buffers, you define your datastructure once in a proto file, and then use the generated source code towrite and read your data.
  • Improves data consistency: By using a proto file as a single source oftruth, you can ensure that all applications and services are using the samedata model.
  • Eliminates data duplication: You can use protocol buffers acrossprojects by defining message types in proto files that reside outside of aspecific project's codebase.

The process of using schemas in Bigtable starts with your protofiles. Aproto file is a text file where you define the structure of yourdata. You use the protobuf compiler tool, also referred to asprotoc, togenerate aprotobuf file descriptor set, which is a machine-readable schema ofyour proto file. You then use this descriptor set to create a schema bundle.

For examples of proto files and their corresponding descriptor sets, seeExample data.

The following diagram shows the process of using schemas inBigtable:

The process of using protobuf schemas in Bigtable.
Figure 1. The process of using protobuf schemas in Bigtable (click to enlarge).

You can create schema bundles using the Google Cloud CLI. After you upload aschema bundle to Bigtable, you can query your data usingthe Bigtable Studio query builder, GoogleSQL forBigtable, or Bigtableexternal tables in BigQuery.

Before you begin

Take the following steps if you plan to use the gcloud CLI:

  1. Install theGoogle Cloud CLI.
  2. Initialize the gcloud CLI:

    gcloudinit

Required roles

To get the permissions that you need to create and manage schema bundles, askyour administrator to grant you theBigtable Admin (roles/bigtable.admin)Identity and Access Management (IAM) role on the table.

This predefined role contains the permissions that Bigtablerequires to work with schema bundles. To see the exact permissions that arerequired, expand theRequired permissions section:

Required permissions

  • bigtable.schemaBundles.create
  • bigtable.schemaBundles.update
  • bigtable.schemaBundles.delete
  • bigtable.schemaBundles.get
  • bigtable.schemaBundles.list

You might also be able to get these permissions withcustom roles or otherpredefined roles.

For more information about Bigtable roles and permissions, seeAccess control with IAM.

Generate a protobuf file descriptor set

Before you can create a schema bundle, you need to generate a descriptor setfrom your proto files with the protobuf compiler tool.

  1. To install the compiler,download the package and follow theinstructions in the README file.
  2. Run the compiler:

    protoc--proto_path=IMPORT_PATH--include_imports\--descriptor_set_out=DESCRIPTOR_OUTPUT_LOCATIONPATH_TO_PROTO

    Replace the following:

    • IMPORT_PATH: the directory where the protoc compilersearches for proto files.
    • DESCRIPTOR_OUTPUT_LOCATION: the directory where theprotoc compiler saves the generated descriptor set.
    • PATH_TO_PROTO: the path to your proto file.

For example, to create a descriptor set namedlibrary.pb for thelibrary.proto file in the current directory, you can use the following command:

protoc--include_imports--descriptor_set_out=library.pblibrary.proto

Create a schema bundle

gcloud

To create a schema bundle, use thegcloud bigtable schema-bundles create command:

gcloudbigtableschema-bundlescreateSCHEMA_BUNDLE_ID\--instance=INSTANCE_ID\--table=TABLE_ID\--proto-descriptors-file=PROTO_DESCRIPTORS_FILE

Replace the following:

  • SCHEMA_BUNDLE_ID: a unique ID for the new schema bundle that can't contain any dot ('.') character.
  • INSTANCE_ID: the ID of the instance to create the schema bundle in.
  • TABLE_ID: the ID of the table to create the schema bundle in.
  • PROTO_DESCRIPTORS_FILE: the path to the descriptor set generated in the previous step.

Java

To create a schema bundle, use thecreateSchemaBundle method:

To learn how to install and use the client library for Bigtable, seeBigtable client libraries.

To authenticate to Bigtable, set up Application Default Credentials. For more information, seeSet up authentication for a local development environment.

try{InputStreamin=getClass().getClassLoader().getResourceAsStream(PROTO_FILE_PATH);CreateSchemaBundleRequestrequest=CreateSchemaBundleRequest.of(tableId,schemaBundleId).setProtoSchema(ByteString.readFrom(in));SchemaBundleschemaBundle=adminClient.createSchemaBundle(request);System.out.printf("Schema bundle: %s created successfully%n",schemaBundle.getId());}catch(NotFoundExceptione){System.err.println("Failed to create a schema bundle from a non-existent table: "+e.getMessage());}catch(IOExceptione){thrownewRuntimeException(e);}

View information about schema bundles

Before you can view information about schema bundles, you need to have aBigtable table with at least one schema bundle. You can getinformation about schema bundles in a table by retrieving a single schemabundle's definition or by listing all schema bundles in a table.

Get schema bundle definition

gcloud

To get details about a schema bundle, use thegcloud bigtable schema-bundles describe command:

gcloudbigtableschema-bundlesdescribeSCHEMA_BUNDLE_ID\--instance=INSTANCE_ID\--table=TABLE_ID

Replace the following:

  • SCHEMA_BUNDLE_ID: the ID of the schema bundle.
  • INSTANCE_ID: the ID of the instance.
  • TABLE_ID: the ID of the table.

Java

To get the definition of a schema bundle, use thegetSchemaBundle method.This method returns aSchemaBundle object that contains the schemadefinition.

The following example shows how to get a schema bundle and deserialize thedescriptor set to print the contents of the schema:

To learn how to install and use the client library for Bigtable, seeBigtable client libraries.

To authenticate to Bigtable, set up Application Default Credentials. For more information, seeSet up authentication for a local development environment.

SchemaBundleschemaBundle=null;try{schemaBundle=adminClient.getSchemaBundle(tableId,schemaBundleId);// Deserialize and print the FileDescriptorSetDescriptorProtos.FileDescriptorSetfileDescriptorSet=DescriptorProtos.FileDescriptorSet.parseFrom(schemaBundle.getProtoSchema());System.out.println("--------- Deserialized FileDescriptorSet ---------");for(DescriptorProtos.FileDescriptorProtofileDescriptorProto:fileDescriptorSet.getFileList()){System.out.println("File: "+fileDescriptorProto.getName());System.out.println("  Package: "+fileDescriptorProto.getPackage());for(DescriptorProtos.DescriptorProtomessageType:fileDescriptorProto.getMessageTypeList()){System.out.println("  Message: "+messageType.getName());}}System.out.println("--------------------------------------------------");}catch(InvalidProtocolBufferExceptione){System.err.println("Failed to parse FileDescriptorSet: "+e.getMessage());}catch(NotFoundExceptione){System.err.println("Failed to retrieve metadata from a non-existent schema bundle: "+e.getMessage());}

The output is similar to the following:

--------- Deserialized FileDescriptorSet ---------File: my_schema.protoPackage: my_packageMessage: MyMessage--------------------------------------------------

List schema bundles in a table

gcloud

To see a list of schema bundles for a table, use thegcloud bigtable schema-bundles list command:

gcloudbigtableschema-bundleslist\--instance=INSTANCE_ID\--table=TABLE_ID

Replace the following:

  • INSTANCE_ID: the ID of the instance.
  • TABLE_ID: the ID of the table.

Java

To see a list of all schema bundles in a table, use thelistSchemaBundlesmethod. This method returns a list of schema bundle IDs.

The following example shows how to list the schema bundles in a table:

To learn how to install and use the client library for Bigtable, seeBigtable client libraries.

To authenticate to Bigtable, set up Application Default Credentials. For more information, seeSet up authentication for a local development environment.

List<String>schemaBundleIds=newArrayList<>();try{schemaBundleIds=adminClient.listSchemaBundles(tableId);for(StringschemaBundleId:schemaBundleIds){System.out.println(schemaBundleId);}}catch(NotFoundExceptione){System.err.println("Failed to list schema bundles from a non-existent table: "+e.getMessage());}

The output is similar to the following:

my-schema-bundle-1my-schema-bundle-2

Update a schema bundle

When you update a schema bundle, Bigtable checks if the newdescriptor set is backward compatible with the existing one. If it is incompatible,the update fails with aFailedPrecondition error. We recommend that youreserve deleted field numbers to prevent their reuse. For more information, seeProto Best Practices in the protobuf documentation.

If you're sure that the incompatible changes are safe and want to force anupdate, you can use the--ignore-warnings flag with gcloud CLI.

gcloud

To update a schema bundle to use a different descriptor set, use thegcloud bigtable schema-bundles update command:

gcloudbigtableschema-bundlesupdateSCHEMA_BUNDLE_ID\--instance=INSTANCE_ID\--table=TABLE_ID\--proto-descriptors-file=PROTO_DESCRIPTORS_FILE

Replace the following:

  • SCHEMA_BUNDLE_ID: the ID of the schema bundle to update.
  • INSTANCE_ID: the ID of the instance that contains the schema bundle.
  • TABLE_ID: the ID of the table that contains the schema bundle.
  • PROTO_DESCRIPTORS_FILE: the path to the new descriptor set file.

Optional: To force the update even if there are incompatible changes, appendthe command with the--ignore-warnings flag.

Java

To learn how to install and use the client library for Bigtable, seeBigtable client libraries.

To authenticate to Bigtable, set up Application Default Credentials. For more information, seeSet up authentication for a local development environment.

try{InputStreamin=getClass().getClassLoader().getResourceAsStream(PROTO_FILE_PATH);UpdateSchemaBundleRequestrequest=UpdateSchemaBundleRequest.of(tableId,schemaBundleId).setProtoSchema(ByteString.readFrom(in));SchemaBundleschemaBundle=adminClient.updateSchemaBundle(request);System.out.printf("Schema bundle: %s updated successfully%n",schemaBundle.getId());}catch(NotFoundExceptione){System.err.println("Failed to modify a non-existent schema bundle: "+e.getMessage());}catch(IOExceptione){thrownewRuntimeException(e);}

Delete a schema bundle

Warning: This action is permanent.

gcloud

To delete a schema bundle, use thegcloud bigtable schema-bundles delete command:

gcloudbigtableschema-bundlesdeleteSCHEMA_BUNDLE_ID\--instance=INSTANCE_ID\--table=TABLE_ID

Replace the following:

  • SCHEMA_BUNDLE_ID: the ID of the schema bundle to delete.
  • INSTANCE_ID: the ID of the instance that contains the schema bundle.
  • TABLE_ID: the ID of the table that contains the schema bundle.

Java

To learn how to install and use the client library for Bigtable, seeBigtable client libraries.

To authenticate to Bigtable, set up Application Default Credentials. For more information, seeSet up authentication for a local development environment.

try{adminClient.deleteSchemaBundle(tableId,schemaBundleId);System.out.printf("SchemaBundle: %s deleted successfully%n",schemaBundleId);}catch(NotFoundExceptione){System.err.println("Failed to delete a non-existent schema bundle: "+e.getMessage());}

Limitations

Schema bundles have the following limitations:

  • You can create a maximum of 10 schema bundles per table.
  • The total size of the serialized protocol buffer descriptors within a schemabundle can't exceed 4 MB. There is no direct limit on the number ofindividual schemas you can include in a bundle, as long as the total size ofthe bundle doesn't exceed this limit.

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.