Skip to content

Commit 1b04d10

Browse files
authored
Merge pull request #15 from scotthart/add_get_job
impl: add GetJob with integration test
2 parents a76ef8b + 302d7df commit 1b04d10

File tree

8 files changed

+226
-3
lines changed

8 files changed

+226
-3
lines changed

google/cloud/bigquery_unified/CMakeLists.txt

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,15 @@ bigquery_unified_library(
129129

130130
set(bigquery_unified_library_files
131131
# cmake-format: sort
132-
client.cc client.h connection.cc connection.h read_arrow_response.h)
132+
client.cc
133+
client.h
134+
connection.cc
135+
connection.h
136+
internal/connection_impl.cc
137+
internal/connection_impl.h
138+
internal/default_options.cc
139+
internal/default_options.h
140+
read_arrow_response.h)
133141

134142
set(bigquery_unified_deps
135143
# cmake-format: sort

google/cloud/bigquery_unified/connection.cc

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

1515
#include "google/cloud/bigquery_unified/connection.h"
16+
#include "google/cloud/bigquery_unified/internal/connection_impl.h"
17+
#include "google/cloud/bigquery_unified/internal/default_options.h"
1618
#include "google/cloud/internal/make_status.h"
1719
#include "google/cloud/internal/pagination_range.h"
1820

@@ -98,7 +100,10 @@ StatusOr<ReadArrowResponse> Connection::ReadArrow(
98100
return internal::UnimplementedError("not implemented");
99101
}
100102

101-
std::shared_ptr<Connection> MakeConnection(Options options) { return {}; }
103+
std::shared_ptr<Connection> MakeConnection(Options options) {
104+
return bigquery_unified_internal::MakeDefaultConnectionImpl(
105+
bigquery_unified_internal::DefaultOptions(std::move(options)));
106+
}
102107

103108
GOOGLE_CLOUD_CPP_BIGQUERY_INLINE_NAMESPACE_END
104109
} // namespace google::cloud::bigquery_unified

google/cloud/bigquery_unified/google_cloud_cpp_bigquery_bigquery_unified.bzl

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,14 @@
1919
google_cloud_cpp_bigquery_bigquery_unified_hdrs = [
2020
"client.h",
2121
"connection.h",
22+
"internal/connection_impl.h",
23+
"internal/default_options.h",
2224
"read_arrow_response.h",
2325
]
2426

2527
google_cloud_cpp_bigquery_bigquery_unified_srcs = [
2628
"client.cc",
2729
"connection.cc",
30+
"internal/connection_impl.cc",
31+
"internal/default_options.cc",
2832
]

google/cloud/bigquery_unified/integration_tests/job_integration_test.cc

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,40 @@
1515
#include "google/cloud/bigquery_unified/client.h"
1616
#include "google/cloud/bigquery_unified/testing_util/status_matchers.h"
1717
#include "google/cloud/bigquery_unified/version.h"
18+
#include "google/cloud/internal/getenv.h"
1819
#include <gmock/gmock.h>
1920

2021
namespace google::cloud::bigquery_unified {
2122
GOOGLE_CLOUD_CPP_BIGQUERY_INLINE_NAMESPACE_BEGIN
2223
namespace {
2324

24-
TEST(JobIntegrationTest, Success) { EXPECT_TRUE(true); }
25+
using ::testing::Eq;
26+
27+
class JobIntegrationTest : public ::testing::Test {
28+
protected:
29+
void SetUp() override {
30+
project_id_ =
31+
google::cloud::internal::GetEnv("GOOGLE_CLOUD_PROJECT").value_or("");
32+
ASSERT_FALSE(project_id_.empty());
33+
}
34+
std::string project_id_;
35+
};
36+
37+
TEST_F(JobIntegrationTest, GetJob) {
38+
namespace bigquery_proto = google::cloud::bigquery::v2;
39+
std::shared_ptr<Connection> connection =
40+
google::cloud::bigquery_unified::MakeConnection();
41+
auto client = google::cloud::bigquery_unified::Client(connection);
42+
43+
// TODO: hard coding this id is brittle but currently necessary.
44+
std::string const job_id = "job_TyRhPS6z-5_e9JSwtT8ieuwDOdLD";
45+
bigquery_proto::GetJobRequest get_request;
46+
get_request.set_project_id(project_id_);
47+
get_request.set_job_id(job_id);
48+
auto job = client.GetJob(get_request);
49+
ASSERT_STATUS_OK(job);
50+
EXPECT_THAT(job->status().state(), Eq("DONE"));
51+
}
2552

2653
} // namespace
2754
GOOGLE_CLOUD_CPP_BIGQUERY_INLINE_NAMESPACE_END
Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
// Copyright 2025 Google LLC
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// https://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
#include "google/cloud/bigquery_unified/internal/connection_impl.h"
16+
#include "google/cloud/bigquerycontrol/v2/internal/job_option_defaults.h"
17+
#include "google/cloud/bigquerycontrol/v2/internal/job_rest_connection_impl.h"
18+
#include "google/cloud/bigquerycontrol/v2/internal/job_rest_stub_factory.h"
19+
#include "google/cloud/bigquerycontrol/v2/internal/job_tracing_connection.h"
20+
#include "google/cloud/background_threads.h"
21+
#include "google/cloud/internal/rest_background_threads_impl.h"
22+
23+
namespace google::cloud::bigquery_unified_internal {
24+
GOOGLE_CLOUD_CPP_BIGQUERY_INLINE_NAMESPACE_BEGIN
25+
26+
ConnectionImpl::ConnectionImpl(
27+
std::shared_ptr<google::cloud::bigquerycontrol_v2::JobServiceConnection>
28+
job_connection,
29+
google::cloud::Options job_options,
30+
std::shared_ptr<bigquerycontrol_v2_internal::JobServiceRestStub> job_stub,
31+
google::cloud::Options options)
32+
: job_connection_(std::move(job_connection)),
33+
job_stub_(std::move(job_stub)),
34+
job_options_(std::move(job_options)),
35+
options_(std::move(options)) {}
36+
37+
StatusOr<google::cloud::bigquery::v2::Job> ConnectionImpl::GetJob(
38+
google::cloud::bigquery::v2::GetJobRequest const& request, Options opts) {
39+
// TODO: Instead of creating an OptionsSpan, pass opts when job_connection_
40+
// supports it.
41+
internal::OptionsSpan span(internal::MergeOptions(
42+
std::move(opts), internal::MergeOptions(options_, job_options_)));
43+
return job_connection_->GetJob(request);
44+
}
45+
46+
std::shared_ptr<bigquery_unified::Connection> MakeDefaultConnectionImpl(
47+
Options options) {
48+
auto job_options =
49+
bigquerycontrol_v2_internal::JobServiceDefaultOptions(options);
50+
auto job_background = std::make_unique<
51+
rest_internal::AutomaticallyCreatedRestBackgroundThreads>();
52+
auto job_stub =
53+
bigquerycontrol_v2_internal::CreateDefaultJobServiceRestStub(job_options);
54+
std::shared_ptr<bigquerycontrol_v2::JobServiceConnection> job_connection =
55+
bigquerycontrol_v2_internal::MakeJobServiceTracingConnection(
56+
std::make_shared<
57+
bigquerycontrol_v2_internal::JobServiceRestConnectionImpl>(
58+
std::move(job_background), job_stub, job_options));
59+
60+
// TODO: We should probably add a TracingConnection decorator in order to
61+
// associate all the various rpcs that are called as part of these
62+
// operations.
63+
return std::make_shared<bigquery_unified_internal::ConnectionImpl>(
64+
std::move(job_connection), std::move(job_options), std::move(job_stub),
65+
std::move(options));
66+
}
67+
68+
GOOGLE_CLOUD_CPP_BIGQUERY_INLINE_NAMESPACE_END
69+
} // namespace google::cloud::bigquery_unified_internal
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
// Copyright 2025 Google LLC
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// https://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
#ifndef GOOGLE_CLOUD_CPP_BIGQUERY_GOOGLE_CLOUD_BIGQUERY_UNIFIED_INTERNAL_CONNECTION_IMPL_H
16+
#define GOOGLE_CLOUD_CPP_BIGQUERY_GOOGLE_CLOUD_BIGQUERY_UNIFIED_INTERNAL_CONNECTION_IMPL_H
17+
18+
#include "google/cloud/bigquery_unified/connection.h"
19+
#include "google/cloud/bigquery_unified/version.h"
20+
#include "google/cloud/bigquerycontrol/v2/internal/job_rest_stub.h"
21+
#include "google/cloud/bigquerycontrol/v2/job_connection.h"
22+
23+
namespace google::cloud::bigquery_unified_internal {
24+
GOOGLE_CLOUD_CPP_BIGQUERY_INLINE_NAMESPACE_BEGIN
25+
26+
class ConnectionImpl : public bigquery_unified::Connection {
27+
public:
28+
ConnectionImpl(
29+
std::shared_ptr<google::cloud::bigquerycontrol_v2::JobServiceConnection>
30+
job_connection,
31+
google::cloud::Options job_options,
32+
std::shared_ptr<bigquerycontrol_v2_internal::JobServiceRestStub> job_stub,
33+
google::cloud::Options options);
34+
35+
~ConnectionImpl() override = default;
36+
37+
Options options() override { return options_; }
38+
39+
StatusOr<google::cloud::bigquery::v2::Job> GetJob(
40+
google::cloud::bigquery::v2::GetJobRequest const& request,
41+
Options opts) override;
42+
43+
private:
44+
std::shared_ptr<bigquerycontrol_v2::JobServiceConnection> job_connection_;
45+
std::shared_ptr<bigquerycontrol_v2_internal::JobServiceRestStub> job_stub_;
46+
Options job_options_;
47+
Options options_;
48+
};
49+
50+
std::shared_ptr<bigquery_unified::Connection> MakeDefaultConnectionImpl(
51+
Options options);
52+
53+
GOOGLE_CLOUD_CPP_BIGQUERY_INLINE_NAMESPACE_END
54+
} // namespace google::cloud::bigquery_unified_internal
55+
56+
#endif // GOOGLE_CLOUD_CPP_BIGQUERY_GOOGLE_CLOUD_BIGQUERY_UNIFIED_INTERNAL_CONNECTION_IMPL_H
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
// Copyright 2025 Google LLC
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// https://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
#include "google/cloud/bigquery_unified/internal/default_options.h"
16+
17+
namespace google::cloud::bigquery_unified_internal {
18+
GOOGLE_CLOUD_CPP_BIGQUERY_INLINE_NAMESPACE_BEGIN
19+
20+
google::cloud::Options DefaultOptions(google::cloud::Options options) {
21+
return options;
22+
}
23+
24+
GOOGLE_CLOUD_CPP_BIGQUERY_INLINE_NAMESPACE_END
25+
} // namespace google::cloud::bigquery_unified_internal
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
// Copyright 2025 Google LLC
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// https://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
#ifndef GOOGLE_CLOUD_CPP_BIGQUERY_GOOGLE_CLOUD_BIGQUERY_UNIFIED_INTERNAL_DEFAULT_OPTIONS_H
16+
#define GOOGLE_CLOUD_CPP_BIGQUERY_GOOGLE_CLOUD_BIGQUERY_UNIFIED_INTERNAL_DEFAULT_OPTIONS_H
17+
18+
#include "google/cloud/bigquery_unified/version.h"
19+
#include "google/cloud/options.h"
20+
21+
namespace google::cloud::bigquery_unified_internal {
22+
GOOGLE_CLOUD_CPP_BIGQUERY_INLINE_NAMESPACE_BEGIN
23+
24+
google::cloud::Options DefaultOptions(google::cloud::Options options);
25+
26+
GOOGLE_CLOUD_CPP_BIGQUERY_INLINE_NAMESPACE_END
27+
} // namespace google::cloud::bigquery_unified_internal
28+
29+
#endif // GOOGLE_CLOUD_CPP_BIGQUERY_GOOGLE_CLOUD_BIGQUERY_UNIFIED_INTERNAL_DEFAULT_OPTIONS_H

0 commit comments

Comments
 (0)