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.

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

namespace cbt = ::google::cloud::bigtable;
namespace cbta = ::google::cloud::bigtable_admin;
using ::google::cloud::StatusOr;
[](cbta::BigtableTableAdminClient admin, std::string const& project_id,
   std::string const& instance_id, std::string const& table_id) {
  std::string table_name = cbt::TableName(project_id, instance_id, table_id);

  google::bigtable::admin::v2::GetTableRequest r;
  r.set_name(table_name);
  r.set_view(google::bigtable::admin::v2::Table::FULL);

  StatusOr<google::bigtable::admin::v2::Table> table =
      admin.GetTable(std::move(r));
  if (!table) throw std::move(table).status();
  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.

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

// 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.

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

// 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.

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

# 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.