From fd9d4b22aa3d9ba13a726536925e3625893881a4 Mon Sep 17 00:00:00 2001 From: Zijie Li Date: Thu, 7 May 2026 17:02:59 -0400 Subject: [PATCH] feat(bigtable): accept optional app profile ID in quickstart Update the Bigtable C++ quickstart example to accept an optional `app_profile_id` parameter from the command line, defaulting to `"default"` if unset, to explicitly configure the Table with an application profile ID. This allows users to easily test routing and features associated with different application profiles. Also update the accompanying README instructions to document the new command-line argument. --- google/cloud/bigtable/README.md | 11 +++++++---- google/cloud/bigtable/quickstart/README.md | 10 ++++++---- google/cloud/bigtable/quickstart/quickstart.cc | 11 +++++++---- 3 files changed, 20 insertions(+), 12 deletions(-) diff --git a/google/cloud/bigtable/README.md b/google/cloud/bigtable/README.md index f241e00b88b2c..f419ff3f8434c 100644 --- a/google/cloud/bigtable/README.md +++ b/google/cloud/bigtable/README.md @@ -21,23 +21,26 @@ this library. #include "google/cloud/bigtable/table.h" int main(int argc, char* argv[]) try { - if (argc != 4) { + if (argc != 4 && argc != 5) { std::string const cmd = argv[0]; auto last_slash = std::string(cmd).find_last_of('/'); std::cerr << "Usage: " << cmd.substr(last_slash + 1) - << " \n"; + << " [app_profile_id]\n"; return 1; } std::string const project_id = argv[1]; std::string const instance_id = argv[2]; std::string const table_id = argv[3]; + std::string const app_profile_id = (argc == 5 ? argv[4] : "default"); // Create a namespace alias to make the code easier to read. namespace cbt = ::google::cloud::bigtable; - cbt::Table table(cbt::MakeDataConnection(), - cbt::TableResource(project_id, instance_id, table_id)); + cbt::Table table( + cbt::MakeDataConnection(), + cbt::TableResource(project_id, instance_id, table_id), + google::cloud::Options{}.set(app_profile_id)); std::string row_key = "r1"; std::string column_family = "cf1"; diff --git a/google/cloud/bigtable/quickstart/README.md b/google/cloud/bigtable/quickstart/README.md index 2cbf124c98b82..2c3ddf29927ff 100644 --- a/google/cloud/bigtable/quickstart/README.md +++ b/google/cloud/bigtable/quickstart/README.md @@ -55,10 +55,11 @@ review the [Authentication methods at Google][authentication-quickstart]. project. As it is often the case with C++ libraries, compiling these dependencies may take several minutes. -1. Run the example, changing the placeholder(s) to appropriate values: +1. Run the example, changing the placeholder(s) to appropriate values (the app + profile ID is optional): ```bash - bazel run :quickstart -- [GCP PROJECT] [CLOUD BIGTABLE INSTANCE] [CLOUD BIGTABLE TABLE] + bazel run :quickstart -- [GCP PROJECT] [CLOUD BIGTABLE INSTANCE] [CLOUD BIGTABLE TABLE] [[APP PROFILE ID]] ``` ## Using with CMake @@ -92,10 +93,11 @@ review the [Authentication methods at Google][authentication-quickstart]. cmake --build .build ``` -1. Run the example, changing the placeholder(s) to appropriate values: +1. Run the example, changing the placeholder(s) to appropriate values (the app + profile ID is optional): ```bash - .build/quickstart [GCP PROJECT] [CLOUD BIGTABLE INSTANCE] [CLOUD BIGTABLE TABLE] + .build/quickstart [GCP PROJECT] [CLOUD BIGTABLE INSTANCE] [CLOUD BIGTABLE TABLE] [[APP PROFILE ID]] ``` ## Platform Specific Notes diff --git a/google/cloud/bigtable/quickstart/quickstart.cc b/google/cloud/bigtable/quickstart/quickstart.cc index 95acbf1d710d6..17e9745c73d99 100644 --- a/google/cloud/bigtable/quickstart/quickstart.cc +++ b/google/cloud/bigtable/quickstart/quickstart.cc @@ -16,23 +16,26 @@ #include "google/cloud/bigtable/table.h" int main(int argc, char* argv[]) try { - if (argc != 4) { + if (argc != 4 && argc != 5) { std::string const cmd = argv[0]; auto last_slash = std::string(cmd).find_last_of('/'); std::cerr << "Usage: " << cmd.substr(last_slash + 1) - << " \n"; + << " [app_profile_id]\n"; return 1; } std::string const project_id = argv[1]; std::string const instance_id = argv[2]; std::string const table_id = argv[3]; + std::string const app_profile_id = (argc == 5 ? argv[4] : "default"); // Create a namespace alias to make the code easier to read. namespace cbt = ::google::cloud::bigtable; - cbt::Table table(cbt::MakeDataConnection(), - cbt::TableResource(project_id, instance_id, table_id)); + cbt::Table table( + cbt::MakeDataConnection(), + cbt::TableResource(project_id, instance_id, table_id), + google::cloud::Options{}.set(app_profile_id)); std::string row_key = "r1"; std::string column_family = "cf1";