Stay organized with collections
Save and categorize content based on your preferences.
Format output from the
cbt CLI
This document describes how to format specific types of data stored in
Bigtable rows when displayed by the
cbt CLI
.
Examples of formatting
Starting with version 0.12.0, the
cbt CLI
can format
certain complex types of data stored in table rows.
When you use the cbt read or cbt lookup command, the
cbt CLI
can
"pretty print" values stored in the rows.
The following example shows data output from the
cbt CLI
without
formatting.
To format a column or column family, you must provide a YAML file that
specifies the formatting for that column. When you call cbt lookup or
cbt read, you pass in the path to the YAML file with the format-file
argument. The following snippet shows an example of calling cbt lookup with
the format-file argument supplied.
The formatting YAML file must connect the column names or column family names
with the data types stored within them. The following snippet shows an example
of a YAML formatting file.
The protocol_buffer_definitions field provides a list
of .proto files that can contain protocol buffer message types to use for
decoding protobuf data.
The protocol_buffer_paths field provides a list of local paths that
can contain .proto files for decoding protocol buffer types.
You do not need to specify the locations of standard protocol buffer
imports, such as messages in the google/protobuf package.
The columns field contains a list of column names with the corresponding
data types for each column:
The protobuf column has its encoding set to "ProtocolBuffer" and its
type is set to 'Cat'. The
cbt CLI
interprets and formats all values stored
in this column as a Cat proto message type. The type must correspond to
a message type defined in one of the .proto files provided for the
protocol_buffer_definition field.
The json column has its encoding field set to "json". The cbt
interprets and formats all values stored in this column as a JSON
structure.
Other fields that you can provide:
default_encoding: This field defines a default formatting for all
all columns in a table or all columns in a column family.
default_type: This field defines a default data type for protocol buffer,
big-endian, and little-endian encoded columns.
families: This field defines encodings and types for all columns within
a column family. You can provide a default_encoding and default_type
for a column family. You can also override these encodings at the column
level by providing a columns field that lists columns by name with the
appropriate encoding and data types, as shown in the following snippet:
The
cbt CLI
supports formatting for several complex data types. The following
table lists the supported data types and strings to provide in the YAML file
for each of the list types. String values are not case-sensitive.
Data type
Formatting value for YAML
Hexadecimal
Hex, H
Big-endian
BigEndian, B
Little-endian
LittleEndian, L
Protocol buffer
ProtocolBuffer, P, PROTO
JSON
JSON, J
Table 1. Data types supported for formatting in cbt output.
The hexadecimal encoding is type agnostic. Data are displayed as a raw
hexadecimal representation of the stored data.
The available types for the big-endian and little-endian encodings are
int8, int16, int32, int64, uint8, uint16, uint32, uint64,
float32, and float64. Stored data length must be a multiple of the
type sized, in bytes. Data are displayed as scalars if the stored
length matches the type size, or as arrays otherwise. Types names are not
case-sensitive.
The types given for the protocol-buffer encoding
must match message types defined in provided
protocol-buffer definition files. The types are not case-sensitive.
If no type is specified, it
defaults to the column name for the column data being displayed.
The formatting values for YAML are not case-sensitive.
[[["Easy to understand","easyToUnderstand","thumb-up"],["Solved my problem","solvedMyProblem","thumb-up"],["Other","otherUp","thumb-up"]],[["Hard to understand","hardToUnderstand","thumb-down"],["Incorrect information or sample code","incorrectInformationOrSampleCode","thumb-down"],["Missing the information/samples I need","missingTheInformationSamplesINeed","thumb-down"],["Other","otherDown","thumb-down"]],["Last updated 2025-09-04 UTC."],[[["\u003cp\u003eThe \u003ccode\u003ecbt\u003c/code\u003e CLI can format complex data types stored in Bigtable rows for improved readability when using \u003ccode\u003ecbt read\u003c/code\u003e or \u003ccode\u003ecbt lookup\u003c/code\u003e.\u003c/p\u003e\n"],["\u003cp\u003eFormatting is defined in a YAML file, specifying data types and encodings for columns or column families, which is then passed to the \u003ccode\u003ecbt\u003c/code\u003e CLI using the \u003ccode\u003eformat-file\u003c/code\u003e argument.\u003c/p\u003e\n"],["\u003cp\u003eYAML formatting can include protocol buffer definitions and paths, allowing for the decoding and display of protobuf messages stored in Bigtable.\u003c/p\u003e\n"],["\u003cp\u003eSupported data types for formatting include hexadecimal, big-endian, little-endian, protocol buffer, and JSON, each with specific formatting values for the YAML file.\u003c/p\u003e\n"],["\u003cp\u003eA default formatting can be applied to an entire table, or specific column family in the YAML file, including default type, and encoding, with the possibility to override these at the column level.\u003c/p\u003e\n"]]],[],null,["# Format output from the cbt CLI\n\nFormat output from the\ncbt CLI\n==============================\n\nThis document describes how to format specific types of data stored in\nBigtable rows when displayed by the\n`cbt` CLI\n.\n\nExamples of formatting\n----------------------\n\nStarting with version 0.12.0, the\n`cbt` CLI\ncan format\n[certain complex types](#data-types) of data stored in table rows.\nWhen you use the `cbt read` or `cbt lookup` command, the\n`cbt` CLI\ncan\n\"pretty print\" values stored in the rows.\n\nThe following example shows data output from the\n`cbt` CLI\nwithout\nformatting. \n\n ----------------------------------------\n r1\n fam1:col1 @ 2022/03/09-11:19:45.966000\n \"\\n\\x05Brave\\x10\\x02\"\n fam1:col2 @ 2022/03/14-11:17:20.014000\n \"{\\\"name\\\": \\\"Brave\\\", \\\"age\\\": 2}\"\n\nThe following example shows data output from the\n`cbt` CLI\nwith\nformatting. \n\n r1\n fam1:col1 @ 2022/03/09-11:19:45.966000\n name: \"Brave\"\n age: 2\n fam1:col2 @ 2022/03/14-11:17:20.014000\n age: 2.00\n name: \"Brave\"\n\nPrint rows with formatting\n--------------------------\n\nTo format a column or column family, you must provide a YAML file that\nspecifies the formatting for that column. When you call `cbt lookup` or\n`cbt read`, you pass in the path to the YAML file with the `format-file`\nargument. The following snippet shows an example of calling `cbt lookup` with\nthe `format-file` argument supplied. \n\n cbt lookup my-table r1 format-file=/path/to/formatting.yml\n\n### Define column data formats in YAML\n\nThe formatting YAML file must connect the column names or column family names\nwith the data types stored within them. The following snippet shows an example\nof a YAML formatting file. \n\n protocol_buffer_definitions:\n - cat.proto\n protocol_buffer_paths:\n - testdata/\n\n\n columns:\n col1:\n encoding: ProtocolBuffer\n type: Cat\n\n col2:\n encoding: json\n\nThe following snippet shows the contents of 'cat.proto'. \n\n syntax = \"proto3\";\n package cats;\n\n option go_package = \"github.com/protocolbuffers/protobuf/examples/go/tutorialpb\";\n\n message Cat {\n string name = 1;\n int32 age = 2;\n }\n\nLooking at the example:\n\n- The `protocol_buffer_definitions` field provides a list of .proto files that can contain protocol buffer message types to use for decoding protobuf data.\n- The `protocol_buffer_paths` field provides a list of local paths that can contain .proto files for decoding protocol buffer types. You do not need to specify the locations of standard protocol buffer imports, such as messages in the `google/protobuf` package.\n- The `columns` field contains a list of column names with the corresponding\n data types for each column:\n\n - The `protobuf` column has its `encoding` set to \"ProtocolBuffer\" and its `type` is set to 'Cat'. The `cbt` CLI interprets and formats all values stored in this column as a `Cat` proto message type. The type must correspond to a message type defined in one of the .proto files provided for the `protocol_buffer_definition` field.\n - The `json` column has its `encoding` field set to \"json\". The `cbt` interprets and formats all values stored in this column as a JSON structure.\n\nOther fields that you can provide:\n\n- `default_encoding`: This field defines a default formatting for all all columns in a table or all columns in a column family.\n- `default_type`: This field defines a default data type for protocol buffer, big-endian, and little-endian encoded columns.\n- `families`: This field defines encodings and types for all columns within\n a column family. You can provide a `default_encoding` and `default_type`\n for a column family. You can also override these encodings at the column\n level by providing a `columns` field that lists columns by name with the\n appropriate encoding and data types, as shown in the following snippet:\n\n families:\n family1:\n default_encoding: BigEndian\n default_type: INT64\n columns:\n address:\n encoding: PROTO\n type: tutorial.Person\n\nSupported data types\n--------------------\n\nThe\n`cbt` CLI\nsupports formatting for several complex data types. The following\ntable lists the supported data types and strings to provide in the YAML file\nfor each of the list types. String values are not case-sensitive.\n\n**Table 1.** Data types supported for formatting in `cbt` output.\n\n- The hexadecimal encoding is type agnostic. Data are displayed as a raw hexadecimal representation of the stored data.\n- The available types for the big-endian and little-endian encodings are `int8`, `int16`, `int32`, `int64`, `uint8`, `uint16`, `uint32`, `uint64`, `float32`, and `float64`. Stored data length must be a multiple of the type sized, in bytes. Data are displayed as scalars if the stored length matches the type size, or as arrays otherwise. Types names are not case-sensitive.\n- The types given for the *protocol-buffer* encoding must match message types defined in provided protocol-buffer definition files. The types are not case-sensitive. If no type is specified, it defaults to the column name for the column data being displayed.\n- The formatting values for YAML are not case-sensitive."]]