Skip to content

Commit edaaca3

Browse files
authored
Merge pull request #24 from scotthart/add_async_insert_job
impl: add async InsertJob
2 parents 62fadfd + f423547 commit edaaca3

File tree

12 files changed

+481
-34
lines changed

12 files changed

+481
-34
lines changed

ci/cloudbuild/dockerfiles/fedora-latest-cmake.Dockerfile

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -67,15 +67,20 @@ RUN curl -fsSL https://distfiles.ariadne.space/pkgconf/pkgconf-2.2.0.tar.gz | \
6767
# set the search path.
6868
ENV PKG_CONFIG_PATH=/usr/local/lib64/pkgconfig:/usr/local/lib/pkgconfig:/usr/lib64/pkgconfig
6969

70+
# In order to work around https://github.com/llvm/llvm-project/issues/102443 we set
71+
# these compiler env vars so that all our dependencies are built the same way.
72+
ENV CC="clang"
73+
ENV CXX="clang++"
74+
ENV CXXFLAGS="-fclang-abi-compat=17"
75+
7076
# We disable the inline namespace because otherwise Abseil LTS updates break our
7177
# `check-api` build.
7278
WORKDIR /var/tmp/build
7379
RUN curl -fsSL https://github.com/abseil/abseil-cpp/archive/20240722.0.tar.gz | \
7480
tar -xzf - --strip-components=1 && \
75-
sed -i 's/^#define ABSL_OPTION_USE_\(.*\) 2/#define ABSL_OPTION_USE_\1 0/' "absl/base/options.h" && \
76-
sed -i 's/^#define ABSL_OPTION_USE_INLINE_NAMESPACE 1$/#define ABSL_OPTION_USE_INLINE_NAMESPACE 0/' "absl/base/options.h" && \
7781
cmake \
7882
-DCMAKE_BUILD_TYPE="Release" \
83+
-DCMAKE_CXX_STANDARD=17 \
7984
-DABSL_BUILD_TESTING=OFF \
8085
-DBUILD_SHARED_LIBS=yes \
8186
-GNinja -S . -B cmake-out && \
@@ -129,10 +134,11 @@ RUN curl -fsSL https://github.com/nlohmann/json/archive/v3.11.3.tar.gz | \
129134
ldconfig && cd /var/tmp && rm -fr build
130135

131136
WORKDIR /var/tmp/build/protobuf
132-
RUN curl -fsSL https://github.com/protocolbuffers/protobuf/archive/v29.0.tar.gz | \
137+
RUN curl -fsSL https://github.com/protocolbuffers/protobuf/archive/v29.3.tar.gz | \
133138
tar -xzf - --strip-components=1 && \
134139
cmake \
135140
-DCMAKE_BUILD_TYPE=Release \
141+
-DCMAKE_CXX_STANDARD=17 \
136142
-DBUILD_SHARED_LIBS=yes \
137143
-Dprotobuf_BUILD_TESTS=OFF \
138144
-Dprotobuf_ABSL_PROVIDER=package \
@@ -144,7 +150,7 @@ WORKDIR /var/tmp/build/
144150
RUN curl -fsSL https://github.com/open-telemetry/opentelemetry-cpp/archive/v1.18.0.tar.gz | \
145151
tar -xzf - --strip-components=1 && \
146152
cmake \
147-
-DCMAKE_CXX_STANDARD=14 \
153+
-DCMAKE_CXX_STANDARD=17 \
148154
-DCMAKE_BUILD_TYPE=Release \
149155
-DCMAKE_POSITION_INDEPENDENT_CODE=TRUE \
150156
-DBUILD_SHARED_LIBS=ON \
@@ -159,10 +165,11 @@ RUN curl -fsSL https://github.com/open-telemetry/opentelemetry-cpp/archive/v1.18
159165

160166
WORKDIR /var/tmp/build/grpc
161167
RUN dnf makecache && dnf install -y c-ares-devel re2-devel
162-
RUN curl -fsSL https://github.com/grpc/grpc/archive/v1.67.0.tar.gz | \
168+
RUN curl -fsSL https://github.com/grpc/grpc/archive/v1.69.0.tar.gz | \
163169
tar -xzf - --strip-components=1 && \
164170
cmake \
165171
-DCMAKE_BUILD_TYPE=Release \
172+
-DCMAKE_CXX_STANDARD=17 \
166173
-DBUILD_SHARED_LIBS=ON \
167174
-DgRPC_INSTALL=ON \
168175
-DgRPC_BUILD_TESTS=OFF \
@@ -184,10 +191,12 @@ RUN curl -fsSL https://github.com/grpc/grpc/archive/v1.67.0.tar.gz | \
184191
# files.
185192
ENV LD_LIBRARY_PATH=/usr/local/lib:/usr/local/lib64:${LD_LIBRARY_PATH}
186193
WORKDIR /var/tmp/build/google-cloud-cpp
187-
RUN curl -fsSL https://github.com/googleapis/google-cloud-cpp/archive/v2.31.0.tar.gz | \
194+
RUN curl -fsSL https://github.com/googleapis/google-cloud-cpp/archive/v2.33.0.tar.gz | \
188195
tar -xzf - --strip-components=1 && \
189196
cmake \
190197
-DCMAKE_BUILD_TYPE=Release \
198+
-DCMAKE_CXX_STANDARD=17 \
199+
-DGOOGLE_CLOUD_CPP_ENABLE_CLANG_ABI_COMPAT_17=ON \
191200
-DBUILD_SHARED_LIBS=yes \
192201
-DGOOGLE_CLOUD_CPP_ENABLE="bigquerycontrol,bigquery" \
193202
-GNinja -S . -B cmake-out && \
@@ -198,6 +207,7 @@ WORKDIR /var/tmp/build/arrow
198207
RUN curl -fsSL https://github.com/apache/arrow/archive/apache-arrow-18.1.0.tar.gz | \
199208
tar -xzf - --strip-components=1 && \
200209
cmake \
210+
-DCMAKE_CXX_STANDARD=17 \
201211
-GNinja -S cpp -B cmake-out \
202212
--preset ninja-release-minimal \
203213
-DARROW_BUILD_STATIC=ON && \

google/cloud/bigquery_unified/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,7 @@ set(bigquery_unified_library_files
135135
connection.h
136136
idempotency_policy.cc
137137
idempotency_policy.h
138+
internal/async_rest_long_running_operation_custom.h
138139
internal/connection_impl.cc
139140
internal/connection_impl.h
140141
internal/default_options.cc

google/cloud/bigquery_unified/client.cc

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -68,15 +68,13 @@ StreamRange<google::cloud::bigquery::v2::ListFormatJob> Client::ListJobs(
6868
}
6969

7070
future<StatusOr<google::cloud::bigquery::v2::Job>> Client::InsertJob(
71-
google::cloud::bigquery::v2::InsertJobRequest const& request,
72-
Options opts) {
73-
return make_ready_future<StatusOr<google::cloud::bigquery::v2::Job>>(
74-
internal::UnimplementedError("not implemented"));
71+
google::cloud::bigquery::v2::Job const& job, Options opts) {
72+
return connection_->InsertJob(
73+
job, internal::MergeOptions(std::move(opts), options_));
7574
}
7675

7776
StatusOr<google::cloud::bigquery::v2::JobReference> Client::InsertJob(
78-
google::cloud::NoAwaitTag,
79-
google::cloud::bigquery::v2::InsertJobRequest const& request,
77+
google::cloud::NoAwaitTag, google::cloud::bigquery::v2::Job const& job,
8078
Options opts) {
8179
return internal::UnimplementedError("not implemented");
8280
}

google/cloud/bigquery_unified/client.h

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -92,27 +92,25 @@ class Client {
9292
google::cloud::bigquery::v2::JobReference const& job_reference,
9393
Options opts = {});
9494

95+
// DeleteJob
96+
Status DeleteJob(google::cloud::bigquery::v2::DeleteJobRequest const& request,
97+
Options opts = {});
98+
9599
// GetJob
96100
StatusOr<google::cloud::bigquery::v2::Job> GetJob(
97101
google::cloud::bigquery::v2::GetJobRequest const& request,
98102
Options opts = {});
99103

100-
// DeleteJob
101-
Status DeleteJob(google::cloud::bigquery::v2::DeleteJobRequest const& request,
102-
Options opts = {});
103-
104104
// ListJobs
105105
StreamRange<google::cloud::bigquery::v2::ListFormatJob> ListJobs(
106106
google::cloud::bigquery::v2::ListJobsRequest request, Options opts = {});
107107

108108
// InsertJob
109109
future<StatusOr<google::cloud::bigquery::v2::Job>> InsertJob(
110-
google::cloud::bigquery::v2::InsertJobRequest const& request,
111-
Options opts = {});
110+
google::cloud::bigquery::v2::Job const& job, Options opts = {});
112111

113112
StatusOr<google::cloud::bigquery::v2::JobReference> InsertJob(
114-
google::cloud::NoAwaitTag,
115-
google::cloud::bigquery::v2::InsertJobRequest const& request,
113+
google::cloud::NoAwaitTag, google::cloud::bigquery::v2::Job const& job,
116114
Options opts = {});
117115

118116
future<StatusOr<google::cloud::bigquery::v2::Job>> InsertJob(

google/cloud/bigquery_unified/connection.cc

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -71,16 +71,14 @@ StreamRange<google::cloud::bigquery::v2::ListFormatJob> Connection::ListJobs(
7171

7272
// InsertJob
7373
future<StatusOr<google::cloud::bigquery::v2::Job>> Connection::InsertJob(
74-
google::cloud::bigquery::v2::InsertJobRequest const& request,
75-
Options opts) {
74+
google::cloud::bigquery::v2::Job const& job, Options opts) {
7675
return google::cloud::make_ready_future<
7776
StatusOr<google::cloud::bigquery::v2::Job>>(
7877
Status(StatusCode::kUnimplemented, "not implemented"));
7978
}
8079

8180
StatusOr<google::cloud::bigquery::v2::JobReference> Connection::InsertJob(
82-
google::cloud::NoAwaitTag,
83-
google::cloud::bigquery::v2::InsertJobRequest const& request,
81+
google::cloud::NoAwaitTag, google::cloud::bigquery::v2::Job const& job,
8482
Options opts) {
8583
return internal::UnimplementedError("not implemented");
8684
}

google/cloud/bigquery_unified/connection.h

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -77,12 +77,10 @@ class Connection {
7777

7878
// InsertJob
7979
virtual future<StatusOr<google::cloud::bigquery::v2::Job>> InsertJob(
80-
google::cloud::bigquery::v2::InsertJobRequest const& request,
81-
Options opts);
80+
google::cloud::bigquery::v2::Job const& job, Options opts);
8281

8382
virtual StatusOr<google::cloud::bigquery::v2::JobReference> InsertJob(
84-
google::cloud::NoAwaitTag,
85-
google::cloud::bigquery::v2::InsertJobRequest const& request,
83+
google::cloud::NoAwaitTag, google::cloud::bigquery::v2::Job const& job,
8684
Options opts);
8785

8886
virtual future<StatusOr<google::cloud::bigquery::v2::Job>> InsertJob(

google/cloud/bigquery_unified/google_cloud_cpp_bigquery_bigquery_unified.bzl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ google_cloud_cpp_bigquery_bigquery_unified_hdrs = [
2020
"client.h",
2121
"connection.h",
2222
"idempotency_policy.h",
23+
"internal/async_rest_long_running_operation_custom.h",
2324
"internal/connection_impl.h",
2425
"internal/default_options.h",
2526
"job_options.h",

google/cloud/bigquery_unified/integration_tests/job_integration_test.cc

Lines changed: 32 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
// limitations under the License.
1414

1515
#include "google/cloud/bigquery_unified/client.h"
16+
#include "google/cloud/bigquery_unified/job_options.h"
1617
#include "google/cloud/bigquery_unified/testing_util/status_matchers.h"
1718
#include "google/cloud/bigquery_unified/version.h"
1819
#include "google/cloud/internal/getenv.h"
@@ -22,6 +23,7 @@ namespace google::cloud::bigquery_unified {
2223
GOOGLE_CLOUD_CPP_BIGQUERY_INLINE_NAMESPACE_BEGIN
2324
namespace {
2425

26+
using ::google::cloud::bigquery_unified::testing_util::IsOk;
2527
using ::testing::Eq;
2628

2729
class JobIntegrationTest : public ::testing::Test {
@@ -34,14 +36,43 @@ class JobIntegrationTest : public ::testing::Test {
3436
std::string project_id_;
3537
};
3638

39+
TEST_F(JobIntegrationTest, InsertJob) {
40+
namespace bigquery_proto = google::cloud::bigquery::v2;
41+
42+
bigquery_proto::JobConfigurationQuery query;
43+
query.mutable_use_legacy_sql()->set_value(false);
44+
query.set_query(
45+
"SELECT name, state, year, sum(number) as total "
46+
"FROM `bigquery-public-data.usa_names.usa_1910_2013` "
47+
"WHERE year >= 2000 "
48+
"GROUP BY name, state, year "
49+
"LIMIT 100");
50+
51+
bigquery_proto::JobConfiguration config;
52+
*config.mutable_query() = query;
53+
config.mutable_labels()->insert({"test_suite", "job_integration_test"});
54+
config.mutable_labels()->insert({"test_case", "insert_job"});
55+
56+
bigquery_proto::Job query_job_request;
57+
*query_job_request.mutable_configuration() = config;
58+
std::shared_ptr<Connection> connection =
59+
google::cloud::bigquery_unified::MakeConnection();
60+
auto client = google::cloud::bigquery_unified::Client(connection);
61+
62+
auto options =
63+
google::cloud::Options{}.set<BillingProjectOption>(project_id_);
64+
auto query_job = client.InsertJob(query_job_request, options).get();
65+
EXPECT_THAT(query_job, IsOk());
66+
}
67+
3768
TEST_F(JobIntegrationTest, GetJob) {
3869
namespace bigquery_proto = google::cloud::bigquery::v2;
3970
std::shared_ptr<Connection> connection =
4071
google::cloud::bigquery_unified::MakeConnection();
4172
auto client = google::cloud::bigquery_unified::Client(connection);
4273

4374
// TODO: hard coding this id is brittle but currently necessary.
44-
std::string const job_id = "job_TyRhPS6z-5_e9JSwtT8ieuwDOdLD";
75+
std::string const job_id = "job_XORZAqWx6R3xcDQCL9K_-2peocI7";
4576
bigquery_proto::GetJobRequest get_request;
4677
get_request.set_project_id(project_id_);
4778
get_request.set_job_id(job_id);

0 commit comments

Comments
 (0)