테이블 나열

컬렉션을 사용해 정리하기 내 환경설정을 기준으로 콘텐츠를 저장하고 분류하세요.

Cloud Bigtable 인스턴스의 모든 테이블을 나열합니다.

코드 샘플

C++

Bigtable용 클라이언트 라이브러리를 설치하고 사용하는 방법은 Bigtable 클라이언트 라이브러리를 참조하세요.

namespace cbt = ::google::cloud::bigtable;
namespace cbta = ::google::cloud::bigtable_admin;
using ::google::cloud::StreamRange;
[](cbta::BigtableTableAdminClient admin, std::string const& project_id,
   std::string const& instance_id) {
  std::string instance_name = cbt::InstanceName(project_id, instance_id);

  google::bigtable::admin::v2::ListTablesRequest r;
  r.set_parent(instance_name);
  r.set_view(google::bigtable::admin::v2::Table::NAME_ONLY);

  StreamRange<google::bigtable::admin::v2::Table> tables =
      admin.ListTables(std::move(r));
  for (auto& table : tables) {
    if (!table) throw std::move(table).status();
    std::cout << table->name() << "\n";
  }
}

C#

Bigtable용 클라이언트 라이브러리를 설치하고 사용하는 방법은 Bigtable 클라이언트 라이브러리를 참조하세요.

// Lists tables in intance.
// Initialize request argument(s).
ListTablesRequest request = new ListTablesRequest
{
    ParentAsInstanceName = s_instanceName
};
try
{
    // Make the request.
    PagedEnumerable<ListTablesResponse, Table> response = bigtableTableAdminClient.ListTables(request);

}
catch (Exception ex)
{
    Console.WriteLine($"Error listing tables {ex.Message}");
}

Java

Bigtable용 클라이언트 라이브러리를 설치하고 사용하는 방법은 Bigtable 클라이언트 라이브러리를 참조하세요.

// Lists tables in the current instance.
try {
  List<String> tableIds = adminClient.listTables();
  for (String tableId : tableIds) {
    System.out.println(tableId);
  }
} catch (NotFoundException e) {
  System.err.println("Failed to list tables from a non-existent instance: " + e.getMessage());
}

Node.js

Bigtable용 클라이언트 라이브러리를 설치하고 사용하는 방법은 Bigtable 클라이언트 라이브러리를 참조하세요.

// List tables in current project
const [tables] = await instance.getTables();
tables.forEach(table => {
  console.log(table.id);
});

PHP

Bigtable용 클라이언트 라이브러리를 설치하고 사용하는 방법은 Bigtable 클라이언트 라이브러리를 참조하세요.

use Google\Cloud\Bigtable\Admin\V2\BigtableInstanceAdminClient;
use Google\Cloud\Bigtable\Admin\V2\BigtableTableAdminClient;

/**
 * List tables in an instance
 *
 * @param string $projectId The Google Cloud project ID
 * @param string $instanceId The ID of the Bigtable instance
 */
function list_tables(
    string $projectId,
    string $instanceId
): void {
    $instanceAdminClient = new BigtableInstanceAdminClient();
    $tableAdminClient = new BigtableTableAdminClient();

    $instanceName = $instanceAdminClient->instanceName($projectId, $instanceId);

    printf('Listing Tables:' . PHP_EOL);
    $tables = $tableAdminClient->listTables($instanceName)->iterateAllElements();
    if (empty($tables)) {
        print('No table exists.' . PHP_EOL);
        return;
    }
    foreach ($tables as $table) {
        print($table->getName() . PHP_EOL);
    }
}

Python

Bigtable용 클라이언트 라이브러리를 설치하고 사용하는 방법은 Bigtable 클라이언트 라이브러리를 참조하세요.

tables = instance.list_tables()
print("Listing tables in current project...")
if tables != []:
    for tbl in tables:
        print(tbl.table_id)
else:
    print("No table exists in current project...")

Ruby

Bigtable용 클라이언트 라이브러리를 설치하고 사용하는 방법은 Bigtable 클라이언트 라이브러리를 참조하세요.

# instance_id = "my-instance"
bigtable.tables(instance_id).all.each do |t|
  puts "Table: #{t.name}"
end

다음 단계

다른 Google Cloud 제품의 코드 샘플을 검색하고 필터링하려면 Google Cloud 샘플 브라우저를 참조하세요.