The Cloud BigQuery C++ Client library offers types and functions to use Cloud BigQuery from C++ applications.
While this library isGA, please note Google Cloud C++ client libraries donotfollowSemantic Versioning.
Quickstart
The following shows the code that you'll run in thegoogle/cloud/bigquery/quickstart/directory, which should give you a taste of the Cloud BigQuery C++ client library API.
#include "google/cloud/bigquery/storage/v1/bigquery_read_client.h"
#include <iostream>
namespace {
void ProcessRowsInAvroFormat(
::google::cloud::bigquery::storage::v1::AvroSchema const&,
::google::cloud::bigquery::storage::v1::AvroRows const&) {
// Code to deserialize avro rows should be added here.
}
} // namespace
int main(int argc, char* argv[]) try {
if (argc != 3) {
std::cerr << "Usage: " << argv[0] << " <project-id> <table-name>\n";
return 1;
}
// project_name should be in the format "projects/<your-gcp-project>"
std::string const project_name = "projects/" + std::string(argv[1]);
// table_name should be in the format:
// "projects/<project-table-resides-in>/datasets/<dataset-table_resides-in>/tables/<table
// name>" The project values in project_name and table_name do not have to be
// identical.
std::string const table_name = argv[2];
// Create a namespace alias to make the code easier to read.
namespace bigquery_storage = ::google::cloud::bigquery_storage_v1;
constexpr int kMaxReadStreams = 1;
// Create the ReadSession.
auto client = bigquery_storage::BigQueryReadClient(
bigquery_storage::MakeBigQueryReadConnection());
::google::cloud::bigquery::storage::v1::ReadSession read_session;
read_session.set_data_format(
google::cloud::bigquery::storage::v1::DataFormat::AVRO);
read_session.set_table(table_name);
auto session =
client.CreateReadSession(project_name, read_session, kMaxReadStreams);
if (!session) throw std::move(session).status();
// Read rows from the ReadSession.
constexpr int kRowOffset = 0;
auto read_rows = client.ReadRows(session->streams(0).name(), kRowOffset);
std::int64_t num_rows = 0;
for (auto const& row : read_rows) {
if (row.ok()) {
num_rows += row->row_count();
ProcessRowsInAvroFormat(session->avro_schema(), row->avro_rows());
}
}
std::cout << num_rows << " rows read from table: " << table_name << "\n";
return 0;
} catch (google::cloud::Status const& status) {
std::cerr << "google::cloud::Status thrown: " << status << "\n";
return 1;
}
Main classes
This library offers multiple*Clientclasses, which are listed below. Each one of these classes exposes all the RPCs for a service as member functions of the class. This library groups multiple services because they are part of the same product or are often used together. A typical example may be the administrative and data plane operations for a single product.
The library also has other classes that provide helpers, configuration parameters, and infrastructure to mock the*Clientclasses when testing your application.
[[["Easy to understand","easyToUnderstand","thumb-up"],["Solved my problem","solvedMyProblem","thumb-up"],["Other","otherUp","thumb-up"]],[["Hard to understand","hardToUnderstand","thumb-down"],["Incorrect information or sample code","incorrectInformationOrSampleCode","thumb-down"],["Missing the information/samples I need","missingTheInformationSamplesINeed","thumb-down"],["Other","otherDown","thumb-down"]],["Last updated 2025-09-04 UTC."],[[["\u003cp\u003eThe Cloud BigQuery C++ Client Library provides tools for C++ applications to interact with Cloud BigQuery, and it is currently in General Availability (GA).\u003c/p\u003e\n"],["\u003cp\u003eThe latest version of the library is 2.37.0-rc, and the library does not follow Semantic Versioning.\u003c/p\u003e\n"],["\u003cp\u003eThe library features several client classes, including \u003ccode\u003eAnalyticsHubServiceClient\u003c/code\u003e, \u003ccode\u003eMetastoreServiceClient\u003c/code\u003e, \u003ccode\u003eConnectionServiceClient\u003c/code\u003e, \u003ccode\u003eDataPolicyServiceClient\u003c/code\u003e, \u003ccode\u003eDataTransferServiceClient\u003c/code\u003e, \u003ccode\u003eMigrationServiceClient\u003c/code\u003e, \u003ccode\u003eReservationServiceClient\u003c/code\u003e, \u003ccode\u003eBigQueryReadClient\u003c/code\u003e, and \u003ccode\u003eBigQueryWriteClient\u003c/code\u003e, each exposing RPCs for their respective services.\u003c/p\u003e\n"],["\u003cp\u003eThe library offers a quickstart guide with example code demonstrating how to read data from a BigQuery table in AVRO format.\u003c/p\u003e\n"],["\u003cp\u003eFurther documentation is provided for next steps, such as error handling, overriding endpoints and authentication credentials, retry policies, environment variables, and testing.\u003c/p\u003e\n"]]],[],null,["Version latestkeyboard_arrow_down\n\n- [2.42.0-rc (latest)](/cpp/docs/reference/bigquery/latest)\n- [2.41.0](/cpp/docs/reference/bigquery/2.41.0)\n- [2.40.0](/cpp/docs/reference/bigquery/2.40.0)\n- [2.39.0](/cpp/docs/reference/bigquery/2.39.0)\n- [2.38.0](/cpp/docs/reference/bigquery/2.38.0)\n- [2.37.0](/cpp/docs/reference/bigquery/2.37.0)\n- [2.36.0](/cpp/docs/reference/bigquery/2.36.0)\n- [2.35.0](/cpp/docs/reference/bigquery/2.35.0)\n- [2.34.0](/cpp/docs/reference/bigquery/2.34.0)\n- [2.33.0](/cpp/docs/reference/bigquery/2.33.0)\n- [2.32.0](/cpp/docs/reference/bigquery/2.32.0)\n- [2.31.0](/cpp/docs/reference/bigquery/2.31.0)\n- [2.30.0](/cpp/docs/reference/bigquery/2.30.0)\n- [2.29.0](/cpp/docs/reference/bigquery/2.29.0)\n- [2.28.0](/cpp/docs/reference/bigquery/2.28.0)\n- [2.27.0](/cpp/docs/reference/bigquery/2.27.0)\n- [2.26.0](/cpp/docs/reference/bigquery/2.26.0)\n- [2.25.1](/cpp/docs/reference/bigquery/2.25.1)\n- [2.24.0](/cpp/docs/reference/bigquery/2.24.0)\n- [2.23.0](/cpp/docs/reference/bigquery/2.23.0)\n- [2.22.1](/cpp/docs/reference/bigquery/2.22.1)\n- [2.21.0](/cpp/docs/reference/bigquery/2.21.0)\n- [2.20.0](/cpp/docs/reference/bigquery/2.20.0)\n- [2.19.0](/cpp/docs/reference/bigquery/2.19.0)\n- [2.18.0](/cpp/docs/reference/bigquery/2.18.0)\n- [2.17.0](/cpp/docs/reference/bigquery/2.17.0)\n- [2.16.0](/cpp/docs/reference/bigquery/2.16.0)\n- [2.15.1](/cpp/docs/reference/bigquery/2.15.1)\n- [2.14.0](/cpp/docs/reference/bigquery/2.14.0)\n- [2.13.0](/cpp/docs/reference/bigquery/2.13.0)\n- [2.12.0](/cpp/docs/reference/bigquery/2.12.0)\n- [2.11.0](/cpp/docs/reference/bigquery/2.11.0) \n\nCloud BigQuery C++ Client Library\n=================================\n\nThe Cloud BigQuery C++ Client library offers types and functions to use Cloud BigQuery from C++ applications.\n\nWhile this library is **GA** , please note Google Cloud C++ client libraries do **not** follow [Semantic Versioning](https://semver.org/).\n\n### Quickstart\n\nThe following shows the code that you'll run in the `google/cloud/bigquery/quickstart/` directory, which should give you a taste of the Cloud BigQuery C++ client library API. \n\n #include \"google/cloud/bigquery/storage/v1/bigquery_read_client.h\"\n #include \u003ciostream\u003e\n\n namespace {\n void ProcessRowsInAvroFormat(\n ::google::cloud::bigquery::storage::v1::AvroSchema const&,\n ::google::cloud::bigquery::storage::v1::AvroRows const&) {\n // Code to deserialize avro rows should be added here.\n }\n } // namespace\n\n int main(int argc, char* argv[]) try {\n if (argc != 3) {\n std::cerr \u003c\u003c \"Usage: \" \u003c\u003c argv[0] \u003c\u003c \" \u003cproject-id\u003e \u003ctable-name\u003e\\n\";\n return 1;\n }\n\n // project_name should be in the format \"projects/\u003cyour-gcp-project\u003e\"\n std::string const project_name = \"projects/\" + std::string(argv[1]);\n // table_name should be in the format:\n // \"projects/\u003cproject-table-resides-in\u003e/datasets/\u003cdataset-table_resides-in\u003e/tables/\u003ctable\n // name\u003e\" The project values in project_name and table_name do not have to be\n // identical.\n std::string const table_name = argv[2];\n\n // Create a namespace alias to make the code easier to read.\n namespace bigquery_storage = ::google::cloud::bigquery_storage_v1;\n constexpr int kMaxReadStreams = 1;\n // Create the ReadSession.\n auto client = bigquery_storage::BigQueryReadClient(\n bigquery_storage::MakeBigQueryReadConnection());\n ::google::cloud::bigquery::storage::v1::ReadSession read_session;\n read_session.set_data_format(\n google::cloud::bigquery::storage::v1::DataFormat::AVRO);\n read_session.set_table(table_name);\n auto session =\n client.CreateReadSession(project_name, read_session, kMaxReadStreams);\n if (!session) throw std::move(session).status();\n\n // Read rows from the ReadSession.\n constexpr int kRowOffset = 0;\n auto read_rows = client.ReadRows(session-\u003estreams(0).name(), kRowOffset);\n\n std::int64_t num_rows = 0;\n for (auto const& row : read_rows) {\n if (row.ok()) {\n num_rows += row-\u003erow_count();\n ProcessRowsInAvroFormat(session-\u003eavro_schema(), row-\u003eavro_rows());\n }\n }\n\n std::cout \u003c\u003c num_rows \u003c\u003c \" rows read from table: \" \u003c\u003c table_name \u003c\u003c \"\\n\";\n return 0;\n } catch (google::cloud::Status const& status) {\n std::cerr \u003c\u003c \"google::cloud::Status thrown: \" \u003c\u003c status \u003c\u003c \"\\n\";\n return 1;\n }\n\n### Main classes\n\nThis library offers multiple `*Client` classes, which are listed below. Each one of these classes exposes all the RPCs for a service as member functions of the class. This library groups multiple services because they are part of the same product or are often used together. A typical example may be the administrative and data plane operations for a single product.\n\nThe library also has other classes that provide helpers, configuration parameters, and infrastructure to mock the `*Client` classes when testing your application.\n\n- [`bigquery_analyticshub_v1::AnalyticsHubServiceClient`](/cpp/docs/reference/bigquery/latest/classgoogle_1_1cloud_1_1bigquery__analyticshub__v1_1_1AnalyticsHubServiceClient)\n- [`bigquery_biglake_v1::MetastoreServiceClient`](/cpp/docs/reference/bigquery/latest/classgoogle_1_1cloud_1_1bigquery__biglake__v1_1_1MetastoreServiceClient)\n- [`bigquery_connection_v1::ConnectionServiceClient`](/cpp/docs/reference/bigquery/latest/classgoogle_1_1cloud_1_1bigquery__connection__v1_1_1ConnectionServiceClient)\n- [`bigquery_datapolicies_v1::DataPolicyServiceClient`](/cpp/docs/reference/bigquery/latest/classgoogle_1_1cloud_1_1bigquery__datapolicies__v1_1_1DataPolicyServiceClient)\n- [`bigquery_datapolicies_v2::DataPolicyServiceClient`](/cpp/docs/reference/bigquery/latest/classgoogle_1_1cloud_1_1bigquery__datapolicies__v2_1_1DataPolicyServiceClient)\n- [`bigquery_datatransfer_v1::DataTransferServiceClient`](/cpp/docs/reference/bigquery/latest/classgoogle_1_1cloud_1_1bigquery__datatransfer__v1_1_1DataTransferServiceClient)\n- [`bigquery_migration_v2::MigrationServiceClient`](/cpp/docs/reference/bigquery/latest/classgoogle_1_1cloud_1_1bigquery__migration__v2_1_1MigrationServiceClient)\n- [`bigquery_reservation_v1::ReservationServiceClient`](/cpp/docs/reference/bigquery/latest/classgoogle_1_1cloud_1_1bigquery__reservation__v1_1_1ReservationServiceClient)\n- [`bigquery_storage_v1::BigQueryReadClient`](/cpp/docs/reference/bigquery/latest/classgoogle_1_1cloud_1_1bigquery__storage__v1_1_1BigQueryReadClient)\n- [`bigquery_storage_v1::BigQueryWriteClient`](/cpp/docs/reference/bigquery/latest/classgoogle_1_1cloud_1_1bigquery__storage__v1_1_1BigQueryWriteClient)\n\n### Next Steps\n\n- [Error Handling](https://cloud.google.com/cpp/docs/reference/common/latest/common-error-handling.html) - describes how the library reports errors.\n- [How to Override the Default Endpoint](/cpp/docs/reference/bigquery/latest/bigquery-override-endpoint) - describes how to override the default endpoint.\n- [How to Override the Authentication Credentials](/cpp/docs/reference/bigquery/latest/bigquery-override-authentication) - describes how to change the authentication credentials used by the library.\n- [Override Retry, Backoff, and Idempotency Policies](/cpp/docs/reference/bigquery/latest/bigquery-override-retry) - describes how to change the default retry policies.\n- [Environment Variables](/cpp/docs/reference/bigquery/latest/bigquery-env) - describes environment variables that can configure the behavior of the library.\n- [Testing your Cloud BigQueryRead application with googlemock](/cpp/docs/reference/bigquery/latest/bigquery-read-mock)"]]