Get table metadata and apply a view

Get table metadata and apply the name view to table fields.

Code sample

C++

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

namespace cbt = ::google::cloud::bigtable;
using ::google::cloud::StatusOr;
[](cbt::TableAdmin admin, std::string const& table_id) {
  StatusOr<google::bigtable::admin::v2::Table> table =
      admin.GetTable(table_id, cbt::TableAdmin::FULL);
  if (!table) throw std::runtime_error(table.status().message());
  std::cout << table->name() << " details=\n" << table->DebugString() << "\n";
}

Java

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

// Gets table metadata, and applies a view to the table fields.
try {
  Table table = adminClient.getTable(tableId);
  System.out.println("Table: " + table.getId());
  Collection<ColumnFamily> columnFamilies = table.getColumnFamilies();
  for (ColumnFamily columnFamily : columnFamilies) {
    System.out.printf(
        "Column family: %s%nGC Rule: %s%n",
        columnFamily.getId(), columnFamily.getGCRule().toString());
  }
} catch (NotFoundException e) {
  System.err.println(
      "Failed to retrieve table metadata for a non-existent table: " + e.getMessage());
}

Node.js

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

// Get table metadata, and apply a view to the table fields
// Supported views include ID, schema or full
// View defaults to schema if unspecified.
const options = {
  view: 'id',
};
const [tableMetadata] = await table.getMetadata(options);
console.log(`Metadata: ${JSON.stringify(tableMetadata)}`);

Ruby

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

# instance_id = "my-instance"
# table_id    = "my-table"
table = bigtable.table(
  instance_id,
  table_id,
  view:           :FULL,
  perform_lookup: true
)
puts "Cluster states:"
table.cluster_states.each do |stats|
  p stats
end

What's next

To search and filter code samples for other Google Cloud products, see the Google Cloud sample browser.