Skip to content

Commit

Permalink
add quickstart
Browse files Browse the repository at this point in the history
  • Loading branch information
scotthart committed Jun 28, 2024
1 parent f3e51fc commit 2171de7
Show file tree
Hide file tree
Showing 3 changed files with 62 additions and 0 deletions.
7 changes: 7 additions & 0 deletions google/cloud/bigquery/quickstart/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -30,3 +30,10 @@ endif ()
# Once the bigquery_client package is found, define new targets.
add_executable(quickstart quickstart.cc)
target_link_libraries(quickstart google-cloud-cpp::bigquery)

find_package(google_cloud_cpp_bigquery_job)
if (google_cloud_cpp_bigquery_job_FOUND)
add_executable(quickstart_job quickstart_job.cc)
target_link_libraries(quickstart_job
google-cloud-cpp::experimental-bigquery_job)
endif ()
8 changes: 8 additions & 0 deletions google/cloud/bigquery/quickstart/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -34,3 +34,11 @@ BIGQUERY_LIBS := $(shell pkg-config $(BIGQUERY_DEPS) --libs-only-l)
# A target using the Cloud BigQuery C++ client library.
$(BIN)/quickstart: quickstart.cc
$(CXXLD) $(CXXFLAGS) $(BIGQUERY_CXXFLAGS) $(BIGQUERY_CXXLDFLAGS) -o $@ $^ $(BIGQUERY_LIBS)

BIGQUERY_JOB_DEPS := google_cloud_cpp_bigquery_job
BIGQUERY_JOB_CXXFLAGS := $(shell pkg-config $(BIGQUERY_JOB_DEPS) --cflags)
BIGQUERY_JOB_CXXLDFLAGS := $(shell pkg-config $(BIGQUERY_JOB_DEPS) --libs-only-L)
BIGQUERY_JOB_LIBS := $(shell pkg-config $(BIGQUERY_JOB_DEPS) --libs-only-l)

$(BIN)/quickstart_job: quickstart_job.cc
$(CXXLD) $(CXXFLAGS) $(BIGQUERY_JOB_CXXFLAGS) $(BIGQUERY_JOB_CXXLDFLAGS) -o $@ $^ $(BIGQUERY_JOB_LIBS)
47 changes: 47 additions & 0 deletions google/cloud/bigquery/quickstart/quickstart_job.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
// Copyright 2024 Google LLC
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// https://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

//! [START bigqueryjob_quickstart] [all]
#include "google/cloud/bigquery/job/v2/job_client.h"
#include <iostream>

namespace {} // namespace

int main(int argc, char* argv[]) try {
if (argc != 2) {
std::cerr << "Usage: " << argv[0] << " <project-id>\n";
return 1;
}

std::string const project_id = std::string(argv[1]);

namespace bigquery_proto = google::cloud::bigquery::v2;
namespace bigquery_job = google::cloud::bigquery_job_v2;
auto client = bigquery_job::JobServiceClient(
bigquery_job::MakeJobServiceConnectionRest());

bigquery_proto::ListJobsRequest list_request;
list_request.set_project_id(project_id);
std::vector<std::string> job_ids;
for (auto job : client.ListJobs(list_request)) {
if (!job) throw std::move(job).status();
std::cout << job->DebugString() << "\n";
}

return 0;
} catch (google::cloud::Status const& status) {
std::cerr << "google::cloud::Status thrown: " << status << "\n";
return 1;
}
//! [END bigqueryjob_quickstart] [all]

0 comments on commit 2171de7

Please sign in to comment.