Mantenha tudo organizado com as coleções
Salve e categorize o conteúdo com base nas suas preferências.
Formatar a saída da
CLI cbt
Neste documento, descrevemos como formatar tipos específicos de dados armazenados em
linhas do Bigtable quando exibidos pela
CLI cbt.
Exemplos de formatação
A partir da versão 0.12.0, a
CLI cbt
pode formatar
determinados tipos complexos de dados armazenados em linhas da tabela.
Quando você usa o comando cbt read ou cbt lookup, a
CLI cbt
pode
"estilizar a formatação" dos valores armazenados nas linhas.
O exemplo a seguir mostra a saída de dados da
CLI cbt
sem
formatação.
Para formatar uma coluna ou um grupo de colunas, forneça um arquivo YAML que especifique a formatação dela. Ao chamar cbt lookup ou cbt read, você passa o caminho para o arquivo YAML com o argumento format-file. O snippet a seguir mostra um exemplo de como chamar cbt lookup com o argumento format-file fornecido.
O arquivo YAML de formatação precisa conectar os nomes das colunas ou dos nomes das colunas aos tipos de dados armazenados nelas. O snippet a seguir mostra um exemplo
de um arquivo de formatação YAML.
O campo protocol_buffer_definitions fornece uma lista
de arquivos .proto que podem conter tipos de mensagem de buffer de protocolo a serem usados para
decodificar dados protobuf.
O campo protocol_buffer_paths fornece uma lista de caminhos locais que podem conter arquivos .proto para decodificar tipos de buffer de protocolo.
Não é necessário especificar os locais das importações de buffer de protocolo padrão, como mensagens no pacote google/protobuf.
O campo columns contém uma lista de nomes de colunas com os tipos de dados
correspondentes para cada coluna:
A coluna protobuf tem o encoding definido como "ProtocolBuffer" e o
type está definido como "Cat". A
CLI cbt
interpreta e formata todos os valores armazenados
nessa coluna como um tipo de mensagem proto Cat. O tipo precisa corresponder a um tipo de mensagem definido em um dos arquivos .proto fornecidos para o campo protocol_buffer_definition.
A coluna json tem o campo encoding definido como "json". O cbt
interpreta e formata todos os valores armazenados nessa coluna como uma estrutura
JSON.
Outros campos que você pode fornecer:
default_encoding: este campo define uma formatação padrão para todas as colunas de uma tabela ou todas as colunas de um grupo.
default_type: este campo define um tipo de dados padrão para o buffer de protocolo,
as colunas codificadas big-endian e little-endian.
families: este campo define codificações e tipos para todas as colunas em um grupo. Você pode fornecer um default_encoding e um default_type
para um grupo de colunas. Também é possível modificar essas codificações no nível da coluna
fornecendo um campo columns que liste as colunas por nome com os
tipos de codificação e dados apropriados, conforme mostrado no snippet a seguir:
A
CLI cbt
oferece suporte à formatação para vários tipos de dados complexos. A tabela a seguir lista os tipos de dados e strings compatíveis para fornecer no arquivo YAML para cada um dos tipos de lista. Os valores de string não diferenciam maiúsculas de minúsculas.
Tipo de dado
Como formatar o valor para YAML
Codificação
Hex, H
Big-endian
BigEndian, B
Little-endian
LittleEndian, L
Buffer de protocolo
ProtocolBuffer, P, PROTO
JSON
JSON, J
Tabela 1. Tipos de dados compatíveis com formatação na saída cbt.
A codificação hexadecimal é do tipo agnóstico. Os dados são exibidos como uma representação hexadecimal bruta dos dados armazenados.
Os tipos disponíveis para as codificações big-endian e little-endian são
int8 ,int16 ,int32 ,int64 ,uint8 ,uint16 ,uint32 ,uint64 ,float32 e float64. O comprimento de dados armazenados precisa ser um múltiplo do tipo dimensionado em bytes. Os dados serão exibidos como escalares se o comprimento
armazenado corresponder ao tamanho do tipo. Caso contrário, os dados serão matrizes. Os nomes dos tipos não diferenciam maiúsculas de minúsculas.
Os tipos fornecidos para a codificação buffer de protocolo precisam corresponder aos tipos de mensagens definidos nos arquivos de definição do buffer de protocolo fornecidos. Os tipos não diferenciam maiúsculas de minúsculas.
Se nenhum tipo for especificado, o padrão será o nome da coluna para os dados da coluna que estão sendo exibidos.
Os valores de formatação para YAML não diferenciam maiúsculas de minúsculas.
[[["Fácil de entender","easyToUnderstand","thumb-up"],["Meu problema foi resolvido","solvedMyProblem","thumb-up"],["Outro","otherUp","thumb-up"]],[["Difícil de entender","hardToUnderstand","thumb-down"],["Informações incorretas ou exemplo de código","incorrectInformationOrSampleCode","thumb-down"],["Não contém as informações/amostras de que eu preciso","missingTheInformationSamplesINeed","thumb-down"],["Problema na tradução","translationIssue","thumb-down"],["Outro","otherDown","thumb-down"]],["Última atualização 2025-09-03 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."]]