diff --git a/CHANGELOG.md b/CHANGELOG.md index 78c224c932c15..b686a5435ca0e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -32,6 +32,13 @@ added to your `.bazelrc` file. build --@io_opentelemetry_cpp//api:with_abseil ``` +### New Libraries + +The following experimental libraries are now available: + +- [Cloud BigQuery Control API](/google/cloud/bigquerycontrol/README.md) - +This library provides support for the Dataset, Job, Model, Project, Routine, RowAccessPolicy, and Table REST resources. + ## v2.26.0 - 2024-07 ### BREAKING TESTING CHANGES diff --git a/ci/cloudbuild/builds/cmake-install.sh b/ci/cloudbuild/builds/cmake-install.sh index 1d1490be39924..1cd005e3d4635 100755 --- a/ci/cloudbuild/builds/cmake-install.sh +++ b/ci/cloudbuild/builds/cmake-install.sh @@ -73,7 +73,6 @@ expected_dirs+=( # no RPC services in google/cloud/bigquery/logging ./include/google/cloud/bigquery/logging ./include/google/cloud/bigquery/logging/v1 - ./include/google/cloud/bigquery/v2 ./include/google/cloud/bigquery/v2/minimal ./include/google/cloud/bigquery/v2/minimal/internal ./include/google/cloud/bigquery/v2/minimal/mocks diff --git a/cmake/GoogleCloudCppFeatures.cmake b/cmake/GoogleCloudCppFeatures.cmake index d2c598c650db0..4b83702da2a4a 100644 --- a/cmake/GoogleCloudCppFeatures.cmake +++ b/cmake/GoogleCloudCppFeatures.cmake @@ -370,6 +370,7 @@ macro (google_cloud_cpp_enable_cleanup) set(compute_features ${GOOGLE_CLOUD_CPP_ENABLE}) list(FILTER compute_features INCLUDE REGEX "^compute_.*") if ((storage IN_LIST GOOGLE_CLOUD_CPP_ENABLE) + OR (bigquerycontrol IN_LIST GOOGLE_CLOUD_CPP_ENABLE) OR (compute IN_LIST GOOGLE_CLOUD_CPP_ENABLE) OR (compute_features) OR (experimental-bigquery_rest IN_LIST GOOGLE_CLOUD_CPP_ENABLE) diff --git a/google/cloud/bigquerycontrol/BUILD.bazel b/google/cloud/bigquerycontrol/BUILD.bazel index a9f590820a752..13400631b5ae4 100644 --- a/google/cloud/bigquerycontrol/BUILD.bazel +++ b/google/cloud/bigquerycontrol/BUILD.bazel @@ -12,20 +12,85 @@ # See the License for the specific language governing permissions and # limitations under the License. -load("//bazel:gapic.bzl", "cc_gapic_library") - package(default_visibility = ["//visibility:private"]) licenses(["notice"]) # Apache 2.0 -service_dirs = ["table/v2/"] - -googleapis_deps = [ - "@com_google_googleapis//google/cloud/bigquery/v2:bigquerycontrol_cc_grpc", +service_dirs = [ + "dataset/v2/", + "job/v2/", + "model/v2/", + "project/v2/", + "routine/v2/", + "row_access_policy/v2/", + "table/v2/", ] -cc_gapic_library( - name = "bigquerycontrol", - googleapis_deps = googleapis_deps, - service_dirs = service_dirs, +code_glob = [d + i + f for d in service_dirs for i in [ + "", + "internal/", +] for f in [ + "*.h", + "*.cc", +]] + +sources_glob = [d + "internal/*_sources.cc" for d in service_dirs] + +filegroup( + name = "srcs", + srcs = glob(sources_glob), +) + +filegroup( + name = "hdrs", + srcs = glob( + include = code_glob, + exclude = sources_glob, + ), +) + +filegroup( + name = "public_hdrs", + srcs = glob([d + "*.h" for d in service_dirs]), + visibility = ["//:__pkg__"], ) + +filegroup( + name = "mocks", + srcs = glob([d + "mocks/*.h" for d in service_dirs]), + visibility = ["//:__pkg__"], +) + +cc_library( + name = "google_cloud_cpp_bigquerycontrol", + srcs = [":srcs"], + hdrs = [":hdrs"], + visibility = ["//:__pkg__"], + deps = [ + "//:common", + "//:grpc_utils", + "//google/cloud:google_cloud_cpp_rest_internal", + "//google/cloud:google_cloud_cpp_rest_protobuf_internal", + "@com_google_googleapis//google/cloud/bigquery/v2:bigquery_cc_proto", + ], +) + +cc_library( + name = "google_cloud_cpp_bigquerycontrol_mocks", + hdrs = [":mocks"], + visibility = ["//:__pkg__"], + deps = [ + ":google_cloud_cpp_bigquerycontrol", + "@com_google_googletest//:gtest", + ], +) + +[cc_test( + name = sample.replace("/", "_").replace(".cc", ""), + srcs = [sample], + tags = ["integration-test"], + deps = [ + "//:experimental-bigquerycontrol", + "//google/cloud/testing_util:google_cloud_cpp_testing_private", + ], +) for sample in glob([d + "samples/*.cc" for d in service_dirs])] diff --git a/google/cloud/bigquerycontrol/CMakeLists.txt b/google/cloud/bigquerycontrol/CMakeLists.txt index 8b219cdd449c1..85f6e5bf642bd 100644 --- a/google/cloud/bigquerycontrol/CMakeLists.txt +++ b/google/cloud/bigquerycontrol/CMakeLists.txt @@ -16,8 +16,180 @@ include(GoogleCloudCppLibrary) -google_cloud_cpp_add_gapic_library(bigquerycontrol "BigQuery API" EXPERIMENTAL - SERVICE_DIRS "table/v2/") +include(GoogleapisConfig) +set(DOXYGEN_PROJECT_NAME "Cloud BigQuery Control API C++ Client") +set(DOXYGEN_PROJECT_BRIEF + "A C++ Client Library for the Cloud BigQuery Control API") +set(DOXYGEN_PROJECT_NUMBER "${PROJECT_VERSION}") +set(DOXYGEN_EXCLUDE_SYMBOLS "internal") +set(DOXYGEN_EXAMPLE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/quickstart) + +unset(mocks_globs) +unset(source_globs) +set(service_dirs + # cmake-format: sort + "dataset/v2/" + "job/v2/" + "model/v2/" + "project/v2/" + "routine/v2/" + "row_access_policy/v2/" + "table/v2/") +foreach (dir IN LISTS service_dirs) + string(REPLACE "/" "_" ns "${dir}") + list(APPEND source_globs "${dir}*.h" "${dir}internal/*.h" + "${dir}internal/*_sources.cc") + list(APPEND mocks_globs "${dir}mocks/*.h") + list(APPEND DOXYGEN_EXAMPLE_PATH + "${CMAKE_CURRENT_SOURCE_DIR}/${dir}samples") + list(APPEND DOXYGEN_EXCLUDE_SYMBOLS "bigquerycontrol_${ns}internal") +endforeach () + +include(GoogleCloudCppDoxygen) +google_cloud_cpp_doxygen_targets("bigquerycontrol" DEPENDS cloud-docs + google-cloud-cpp::bigquery_v2_protos) + +include(GoogleCloudCppCommon) + +include(CompileProtos) +google_cloud_cpp_find_proto_include_dir(PROTO_INCLUDE_DIR) +google_cloud_cpp_load_protolist( + proto_list + "${PROJECT_SOURCE_DIR}/external/googleapis/protolists/bigquerycontrol.list") +google_cloud_cpp_load_protodeps( + proto_deps + "${PROJECT_SOURCE_DIR}/external/googleapis/protodeps/bigquerycontrol.deps") +google_cloud_cpp_proto_library( + google_cloud_cpp_bigquery_v2_protos # cmake-format: sort + ${proto_list} PROTO_PATH_DIRECTORIES "${EXTERNAL_GOOGLEAPIS_SOURCE}" + "${PROTO_INCLUDE_DIR}") +external_googleapis_set_version_and_alias(bigquery_v2_protos) +target_link_libraries(google_cloud_cpp_bigquery_v2_protos PUBLIC ${proto_deps}) + +file( + GLOB source_files + RELATIVE "${CMAKE_CURRENT_SOURCE_DIR}" + ${source_globs}) +list(SORT source_files) +add_library(google_cloud_cpp_bigquerycontrol ${source_files}) +target_include_directories( + google_cloud_cpp_bigquerycontrol + PUBLIC $ + $ + $) +target_link_libraries( + google_cloud_cpp_bigquerycontrol + PUBLIC google-cloud-cpp::grpc_utils + google-cloud-cpp::common + google-cloud-cpp::rest_internal + google-cloud-cpp::rest_protobuf_internal + google-cloud-cpp::bigquery_v2_protos) +google_cloud_cpp_add_common_options(google_cloud_cpp_bigquerycontrol) +set_target_properties( + google_cloud_cpp_bigquerycontrol + PROPERTIES EXPORT_NAME google-cloud-cpp::experimental-bigquerycontrol + VERSION "${PROJECT_VERSION}" + SOVERSION "${PROJECT_VERSION_MAJOR}") +target_compile_options(google_cloud_cpp_bigquerycontrol + PUBLIC ${GOOGLE_CLOUD_CPP_EXCEPTIONS_FLAG}) + +add_library(google-cloud-cpp::experimental-bigquerycontrol ALIAS + google_cloud_cpp_bigquerycontrol) + +# Get the destination directories based on the GNU recommendations. +include(GNUInstallDirs) + +# Export the CMake targets to make it easy to create configuration files. +install( + EXPORT google_cloud_cpp_bigquerycontrol-targets + DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/google_cloud_cpp_bigquerycontrol" + COMPONENT google_cloud_cpp_development) + +# Install the libraries and headers in the locations determined by +# GNUInstallDirs +install( + TARGETS google_cloud_cpp_bigquerycontrol google_cloud_cpp_bigquery_v2_protos + EXPORT google_cloud_cpp_bigquerycontrol-targets + RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} + COMPONENT google_cloud_cpp_runtime + LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} + COMPONENT google_cloud_cpp_runtime + NAMELINK_COMPONENT google_cloud_cpp_development + ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR} + COMPONENT google_cloud_cpp_development) + +google_cloud_cpp_install_proto_library_protos( + "google_cloud_cpp_bigquery_v2_protos" "${EXTERNAL_GOOGLEAPIS_SOURCE}") +google_cloud_cpp_install_proto_library_headers( + "google_cloud_cpp_bigquery_v2_protos") +google_cloud_cpp_install_headers("google_cloud_cpp_bigquerycontrol" + "include/google/cloud/bigquerycontrol") + +google_cloud_cpp_add_pkgconfig( + bigquerycontrol + "The Cloud BigQuery Control API C++ Client Library" + "Provides C++ APIs to use the Cloud BigQuery Control API." + "google_cloud_cpp_rest_internal" + "google_cloud_cpp_rest_protobuf_internal" + "google_cloud_cpp_grpc_utils" + "google_cloud_cpp_common" + "google_cloud_cpp_bigquery_v2_protos") + +# Create and install the CMake configuration files. +include(CMakePackageConfigHelpers) +configure_file("config.cmake.in" + "google_cloud_cpp_bigquerycontrol-config.cmake" @ONLY) +write_basic_package_version_file( + "google_cloud_cpp_bigquerycontrol-config-version.cmake" + VERSION ${PROJECT_VERSION} + COMPATIBILITY ExactVersion) + +install( + FILES + "${CMAKE_CURRENT_BINARY_DIR}/google_cloud_cpp_bigquerycontrol-config.cmake" + "${CMAKE_CURRENT_BINARY_DIR}/google_cloud_cpp_bigquerycontrol-config-version.cmake" + DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/google_cloud_cpp_bigquerycontrol" + COMPONENT google_cloud_cpp_development) + +external_googleapis_install_pc("google_cloud_cpp_bigquery_v2_protos") + +if (GOOGLE_CLOUD_CPP_WITH_MOCKS) + # Create a header-only library for the mocks. We use a CMake `INTERFACE` + # library for these, a regular library would not work on macOS (where the + # library needs at least one .o file). Unfortunately INTERFACE libraries are + # a bit weird in that they need absolute paths for their sources. + file( + GLOB relative_mock_files + RELATIVE "${CMAKE_CURRENT_SOURCE_DIR}" + ${mocks_globs}) + list(SORT relative_mock_files) + set(mock_files) + foreach (file IN LISTS relative_mock_files) + # We use a generator expression per the recommendation in: + # https://stackoverflow.com/a/62465051 + list(APPEND mock_files + "$") + endforeach () + add_library(google_cloud_cpp_bigquerycontrol_mocks INTERFACE) + target_sources(google_cloud_cpp_bigquerycontrol_mocks + INTERFACE ${mock_files}) + target_link_libraries( + google_cloud_cpp_bigquerycontrol_mocks + INTERFACE google-cloud-cpp::experimental-bigquerycontrol + GTest::gmock_main GTest::gmock GTest::gtest) + set_target_properties( + google_cloud_cpp_bigquerycontrol_mocks + PROPERTIES EXPORT_NAME google-cloud-cpp::bigquerycontrol_mocks) + target_include_directories( + google_cloud_cpp_bigquerycontrol_mocks + INTERFACE $ + $ + $) + target_compile_options(google_cloud_cpp_bigquerycontrol_mocks + INTERFACE ${GOOGLE_CLOUD_CPP_EXCEPTIONS_FLAG}) + + google_cloud_cpp_install_mocks(bigquerycontrol "Cloud BigQuery V2 API") +endif () if (BUILD_TESTING AND GOOGLE_CLOUD_CPP_ENABLE_CXX_EXCEPTIONS) add_executable(bigquerycontrol_quickstart "quickstart/quickstart.cc") @@ -27,11 +199,17 @@ if (BUILD_TESTING AND GOOGLE_CLOUD_CPP_ENABLE_CXX_EXCEPTIONS) google_cloud_cpp_add_common_options(bigquerycontrol_quickstart) add_test( NAME bigquerycontrol_quickstart - COMMAND - cmake -P "${PROJECT_SOURCE_DIR}/cmake/quickstart-runner.cmake" - $ GOOGLE_CLOUD_PROJECT - GOOGLE_CLOUD_CPP_TEST_REGION # EDIT HERE - ) + COMMAND cmake -P "${PROJECT_SOURCE_DIR}/cmake/quickstart-runner.cmake" + $ GOOGLE_CLOUD_PROJECT) set_tests_properties(bigquerycontrol_quickstart PROPERTIES LABELS "integration-test;quickstart") endif () + +# google-cloud-cpp::experimental-bigquerycontrol must be defined before we can +# add the samples. +foreach (dir IN LISTS service_dirs) + if (BUILD_TESTING AND GOOGLE_CLOUD_CPP_ENABLE_CXX_EXCEPTIONS) + google_cloud_cpp_add_samples_relative("experimental-bigquerycontrol" + "${dir}samples/") + endif () +endforeach () diff --git a/google/cloud/bigquerycontrol/README.md b/google/cloud/bigquerycontrol/README.md index d9ad1a510cb3d..cc7cf452aac5d 100644 --- a/google/cloud/bigquerycontrol/README.md +++ b/google/cloud/bigquerycontrol/README.md @@ -2,8 +2,8 @@ :construction: -This directory contains an idiomatic C++ client library for the \[BigQuery -API\]\[cloud-service-docs\]. +This directory contains an idiomatic C++ client library for the +[BigQuery API][cloud-service-docs]. A data platform for customers to create, manage, share and query data. @@ -22,23 +22,27 @@ this library. ```cc -#include "google/cloud/bigquerycontrol/table/v2/ EDIT HERE _client.h" +#include "google/cloud/bigquerycontrol/job/v2/job_client.h" #include "google/cloud/location.h" #include int main(int argc, char* argv[]) try { - if (argc != 3) { - std::cerr << "Usage: " << argv[0] << " project-id location-id\n"; + if (argc != 2) { + std::cerr << "Usage: " << argv[0] << " project-id\n"; return 1; } - auto const location = google::cloud::Location(argv[1], argv[2]); + auto const project_id = argv[1]; - namespace bigquerycontrol = ::google::cloud::bigquerycontrol_table_v2; - auto client = bigquerycontrol::ServiceClient( - bigquerycontrol::MakeServiceConnection()); // EDIT HERE + namespace bigquerycontrol = ::google::cloud::bigquerycontrol_job_v2; + namespace bigquery_v2_proto = ::google::cloud::bigquery::v2; + auto client = bigquerycontrol::JobServiceClient( + bigquerycontrol::MakeJobServiceConnectionRest()); - for (auto r : client.List /*EDIT HERE*/ (location.FullName())) { + bigquery_v2_proto::ListJobsRequest list_request; + list_request.set_project_id(project_id); + + for (auto r : client.ListJobs(list_request)) { if (!r) throw std::move(r).status(); std::cout << r->DebugString() << "\n"; } @@ -54,14 +58,11 @@ int main(int argc, char* argv[]) try { ## More Information -- Official documentation about the \[BigQuery API\]\[cloud-service-docs\] - service -- \[Reference doxygen documentation\]\[doxygen-link\] for each release of this +- Official documentation about the [BigQuery API][cloud-service-docs] service +- [Reference doxygen documentation][doxygen-link] for each release of this client library -- Detailed header comments in our \[public `.h`\]\[source-link\] files +- Detailed header comments in our [public `.h`][source-link] files -\[cloud-service-docs\]: https://cloud.google.com/bigquerycontrol \[EDIT HERE\] -\[doxygen-link\]: -https://cloud.google.com/cpp/docs/reference/bigquerycontrol/latest/ -\[source-link\]: -https://github.com/googleapis/google-cloud-cpp/tree/main/google/cloud/bigquerycontrol +[cloud-service-docs]: https://cloud.google.com/bigquery/docs +[doxygen-link]: https://cloud.google.com/cpp/docs/reference/bigquerycontrol/latest/ +[source-link]: https://github.com/googleapis/google-cloud-cpp/tree/main/google/cloud/bigquerycontrol diff --git a/google/cloud/bigquerycontrol/config.cmake.in b/google/cloud/bigquerycontrol/config.cmake.in new file mode 100644 index 0000000000000..83265732d005d --- /dev/null +++ b/google/cloud/bigquerycontrol/config.cmake.in @@ -0,0 +1,24 @@ +# 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. + +include(CMakeFindDependencyMacro) +# google_cloud_cpp_googleapis finds both gRPC and Protobuf, no need to load them here. +find_dependency(google_cloud_cpp_googleapis) +find_dependency(google_cloud_cpp_common) +find_dependency(google_cloud_cpp_grpc_utils) +find_dependency(google_cloud_cpp_rest_internal) +find_dependency(google_cloud_cpp_rest_protobuf_internal) +find_dependency(absl) + +include("${CMAKE_CURRENT_LIST_DIR}/google_cloud_cpp_bigquerycontrol-targets.cmake") diff --git a/google/cloud/bigquerycontrol/doc/main.dox b/google/cloud/bigquerycontrol/doc/main.dox index 98085e62f3c74..899832b0f897b 100644 --- a/google/cloud/bigquerycontrol/doc/main.dox +++ b/google/cloud/bigquerycontrol/doc/main.dox @@ -55,6 +55,6 @@ application. - @ref bigquerycontrol-env - describes environment variables that can configure the behavior of the library. -[cloud-service-docs]: https://cloud.google.com/bigquerycontrol [EDIT HERE] +[cloud-service-docs]: https://cloud.google.com/bigquery/docs */ diff --git a/google/cloud/bigquerycontrol/quickstart/README.md b/google/cloud/bigquerycontrol/quickstart/README.md index c8255d277b343..672c6e967df5a 100644 --- a/google/cloud/bigquerycontrol/quickstart/README.md +++ b/google/cloud/bigquerycontrol/quickstart/README.md @@ -151,4 +151,4 @@ set GRPC_DEFAULT_SSL_ROOTS_FILE_PATH=%cd%\roots.pem [grpc-roots-pem-bug]: https://github.com/grpc/grpc/issues/16571 [homebrew-cmake-link]: https://formulae.brew.sh/formula/cmake [howto-setup-dev-workstation]: /doc/contributor/howto-guide-setup-development-workstation.md -[quickstart-link]: https://cloud.google.com/bigquerycontrol/docs/quickstart +[quickstart-link]: https://cloud.google.com/bigquery/docs/quickstarts/quickstart-web-ui diff --git a/google/cloud/bigquerycontrol/quickstart/quickstart.cc b/google/cloud/bigquerycontrol/quickstart/quickstart.cc index 9f180474db7a5..112ff2872e31f 100644 --- a/google/cloud/bigquerycontrol/quickstart/quickstart.cc +++ b/google/cloud/bigquerycontrol/quickstart/quickstart.cc @@ -13,23 +13,27 @@ // limitations under the License. //! [all] -#include "google/cloud/bigquerycontrol/table/v2/ EDIT HERE _client.h" +#include "google/cloud/bigquerycontrol/job/v2/job_client.h" #include "google/cloud/location.h" #include int main(int argc, char* argv[]) try { - if (argc != 3) { - std::cerr << "Usage: " << argv[0] << " project-id location-id\n"; + if (argc != 2) { + std::cerr << "Usage: " << argv[0] << " project-id\n"; return 1; } - auto const location = google::cloud::Location(argv[1], argv[2]); + auto const project_id = argv[1]; - namespace bigquerycontrol = ::google::cloud::bigquerycontrol_table_v2; - auto client = bigquerycontrol::ServiceClient( - bigquerycontrol::MakeServiceConnection()); // EDIT HERE + namespace bigquerycontrol = ::google::cloud::bigquerycontrol_job_v2; + namespace bigquery_v2_proto = ::google::cloud::bigquery::v2; + auto client = bigquerycontrol::JobServiceClient( + bigquerycontrol::MakeJobServiceConnectionRest()); - for (auto r : client.List /*EDIT HERE*/ (location.FullName())) { + bigquery_v2_proto::ListJobsRequest list_request; + list_request.set_project_id(project_id); + + for (auto r : client.ListJobs(list_request)) { if (!r) throw std::move(r).status(); std::cout << r->DebugString() << "\n"; }