Skip to content

Commit 69547bb

Browse files
authored
impl(bigquery): Project custom classes, request and response (#11591)
1 parent 77e3080 commit 69547bb

15 files changed

+918
-0
lines changed

google/cloud/bigquery/bigquery_rest.cmake

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,12 @@ add_library(
7373
v2/minimal/internal/job_rest_stub_factory.h
7474
v2/minimal/internal/job_retry_policy.h
7575
v2/minimal/internal/log_wrapper.h
76+
v2/minimal/internal/project.cc
77+
v2/minimal/internal/project.h
78+
v2/minimal/internal/project_request.cc
79+
v2/minimal/internal/project_request.h
80+
v2/minimal/internal/project_response.cc
81+
v2/minimal/internal/project_response.h
7682
v2/minimal/internal/rest_stub_utils.cc
7783
v2/minimal/internal/rest_stub_utils.h
7884
v2/minimal/internal/table.cc
@@ -176,6 +182,8 @@ function (bigquery_rest_define_tests)
176182
${CMAKE_CURRENT_SOURCE_DIR}/v2/minimal/testing/mock_dataset_rest_stub.h
177183
${CMAKE_CURRENT_SOURCE_DIR}/v2/minimal/testing/mock_job_rest_stub.h
178184
${CMAKE_CURRENT_SOURCE_DIR}/v2/minimal/testing/mock_table_rest_stub.h
185+
${CMAKE_CURRENT_SOURCE_DIR}/v2/minimal/testing/project_test_utils.cc
186+
${CMAKE_CURRENT_SOURCE_DIR}/v2/minimal/testing/project_test_utils.h
179187
${CMAKE_CURRENT_SOURCE_DIR}/v2/minimal/testing/table_test_utils.cc
180188
${CMAKE_CURRENT_SOURCE_DIR}/v2/minimal/testing/table_test_utils.h)
181189
target_link_libraries(
@@ -219,6 +227,9 @@ function (bigquery_rest_define_tests)
219227
v2/minimal/internal/job_response_test.cc
220228
v2/minimal/internal/job_rest_stub_test.cc
221229
v2/minimal/internal/job_test.cc
230+
v2/minimal/internal/project_request_test.cc
231+
v2/minimal/internal/project_response_test.cc
232+
v2/minimal/internal/project_test.cc
222233
v2/minimal/internal/rest_stub_utils_test.cc
223234
v2/minimal/internal/table_client_test.cc
224235
v2/minimal/internal/table_connection_test.cc

google/cloud/bigquery/bigquery_rest_testing.bzl

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,11 @@ bigquery_rest_testing_hdrs = [
2121
"v2/minimal/testing/mock_dataset_rest_stub.h",
2222
"v2/minimal/testing/mock_job_rest_stub.h",
2323
"v2/minimal/testing/mock_table_rest_stub.h",
24+
"v2/minimal/testing/project_test_utils.h",
2425
"v2/minimal/testing/table_test_utils.h",
2526
]
2627

2728
bigquery_rest_testing_srcs = [
29+
"v2/minimal/testing/project_test_utils.cc",
2830
"v2/minimal/testing/table_test_utils.cc",
2931
]

google/cloud/bigquery/bigquery_rest_unit_tests.bzl

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,9 @@ bigquery_rest_unit_tests = [
3939
"v2/minimal/internal/job_response_test.cc",
4040
"v2/minimal/internal/job_rest_stub_test.cc",
4141
"v2/minimal/internal/job_test.cc",
42+
"v2/minimal/internal/project_request_test.cc",
43+
"v2/minimal/internal/project_response_test.cc",
44+
"v2/minimal/internal/project_test.cc",
4245
"v2/minimal/internal/rest_stub_utils_test.cc",
4346
"v2/minimal/internal/table_client_test.cc",
4447
"v2/minimal/internal/table_connection_test.cc",

google/cloud/bigquery/google_cloud_cpp_bigquery_rest.bzl

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,9 @@ google_cloud_cpp_bigquery_rest_hdrs = [
4848
"v2/minimal/internal/job_rest_stub_factory.h",
4949
"v2/minimal/internal/job_retry_policy.h",
5050
"v2/minimal/internal/log_wrapper.h",
51+
"v2/minimal/internal/project.h",
52+
"v2/minimal/internal/project_request.h",
53+
"v2/minimal/internal/project_response.h",
5154
"v2/minimal/internal/rest_stub_utils.h",
5255
"v2/minimal/internal/table.h",
5356
"v2/minimal/internal/table_client.h",
@@ -95,6 +98,9 @@ google_cloud_cpp_bigquery_rest_srcs = [
9598
"v2/minimal/internal/job_rest_connection_impl.cc",
9699
"v2/minimal/internal/job_rest_stub.cc",
97100
"v2/minimal/internal/job_rest_stub_factory.cc",
101+
"v2/minimal/internal/project.cc",
102+
"v2/minimal/internal/project_request.cc",
103+
"v2/minimal/internal/project_response.cc",
98104
"v2/minimal/internal/rest_stub_utils.cc",
99105
"v2/minimal/internal/table.cc",
100106
"v2/minimal/internal/table_client.cc",
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
// Copyright 2023 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/v2/minimal/internal/project.h"
16+
#include "google/cloud/internal/debug_string.h"
17+
#include "google/cloud/internal/format_time_point.h"
18+
19+
namespace google {
20+
namespace cloud {
21+
namespace bigquery_v2_minimal_internal {
22+
GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN
23+
24+
std::string ProjectReference::DebugString(absl::string_view name,
25+
TracingOptions const& options,
26+
int indent) const {
27+
return internal::DebugFormatter(name, options, indent)
28+
.StringField("project_id", project_id)
29+
.Build();
30+
}
31+
32+
std::string Project::DebugString(absl::string_view name,
33+
TracingOptions const& options,
34+
int indent) const {
35+
return internal::DebugFormatter(name, options, indent)
36+
.StringField("kind", kind)
37+
.StringField("id", id)
38+
.StringField("friendly_name", friendly_name)
39+
.SubMessage("project_reference", project_reference)
40+
.Field("numeric_id", numeric_id)
41+
.Build();
42+
}
43+
44+
GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_END
45+
} // namespace bigquery_v2_minimal_internal
46+
} // namespace cloud
47+
} // namespace google
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
// Copyright 2023 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_GOOGLE_CLOUD_BIGQUERY_V2_MINIMAL_INTERNAL_PROJECT_H
16+
#define GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_BIGQUERY_V2_MINIMAL_INTERNAL_PROJECT_H
17+
18+
#include "google/cloud/tracing_options.h"
19+
#include "google/cloud/version.h"
20+
#include "absl/strings/string_view.h"
21+
#include "absl/types/optional.h"
22+
#include <nlohmann/json.hpp>
23+
#include <string>
24+
25+
namespace google {
26+
namespace cloud {
27+
namespace bigquery_v2_minimal_internal {
28+
GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN
29+
30+
// Disabling clang-tidy here as the namespace is needed for using the
31+
// NLOHMANN_DEFINE_TYPE_NON_INTRUSIVE_WITH_DEFAULT.
32+
using namespace nlohmann::literals; // NOLINT
33+
34+
struct ProjectReference {
35+
std::string project_id;
36+
37+
std::string DebugString(absl::string_view name,
38+
TracingOptions const& options = {},
39+
int indent = 0) const;
40+
};
41+
NLOHMANN_DEFINE_TYPE_NON_INTRUSIVE_WITH_DEFAULT(ProjectReference, project_id);
42+
43+
struct Project {
44+
std::string kind;
45+
std::string id;
46+
std::string friendly_name;
47+
48+
std::int64_t numeric_id;
49+
50+
ProjectReference project_reference;
51+
52+
std::string DebugString(absl::string_view name,
53+
TracingOptions const& options = {},
54+
int indent = 0) const;
55+
};
56+
NLOHMANN_DEFINE_TYPE_NON_INTRUSIVE_WITH_DEFAULT(Project, kind, id,
57+
friendly_name, numeric_id,
58+
project_reference);
59+
60+
GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_END
61+
} // namespace bigquery_v2_minimal_internal
62+
} // namespace cloud
63+
} // namespace google
64+
65+
#endif // GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_BIGQUERY_V2_MINIMAL_INTERNAL_PROJECT_H
Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
// Copyright 2023 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/v2/minimal/internal/project_request.h"
16+
#include "google/cloud/bigquery/v2/minimal/internal/rest_stub_utils.h"
17+
#include "google/cloud/common_options.h"
18+
#include "google/cloud/internal/absl_str_cat_quiet.h"
19+
#include "google/cloud/internal/debug_string.h"
20+
#include "google/cloud/internal/format_time_point.h"
21+
#include "google/cloud/internal/make_status.h"
22+
#include "google/cloud/status.h"
23+
#include "absl/strings/match.h"
24+
25+
namespace google {
26+
namespace cloud {
27+
namespace bigquery_v2_minimal_internal {
28+
GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN
29+
30+
std::string ListProjectsRequest::DebugString(absl::string_view name,
31+
TracingOptions const& options,
32+
int indent) const {
33+
return internal::DebugFormatter(name, options, indent)
34+
.Field("max_results", max_results_)
35+
.StringField("page_token", page_token_)
36+
.Build();
37+
}
38+
39+
StatusOr<rest_internal::RestRequest> BuildRestRequest(
40+
ListProjectsRequest const& r) {
41+
rest_internal::RestRequest request;
42+
auto const& opts = internal::CurrentOptions();
43+
44+
std::string endpoint = GetBaseEndpoint(opts);
45+
46+
std::string path = absl::StrCat(endpoint, "/projects");
47+
request.SetPath(std::move(path));
48+
49+
// Add query params.
50+
if (r.max_results() > 0) {
51+
request.AddQueryParameter("maxResults", std::to_string(r.max_results()));
52+
}
53+
54+
auto if_not_empty_add = [&](char const* key, auto const& v) {
55+
if (v.empty()) return;
56+
request.AddQueryParameter(key, v);
57+
};
58+
if_not_empty_add("pageToken", r.page_token());
59+
60+
return request;
61+
}
62+
63+
GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_END
64+
} // namespace bigquery_v2_minimal_internal
65+
} // namespace cloud
66+
} // namespace google
Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
// Copyright 2023 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_GOOGLE_CLOUD_BIGQUERY_V2_MINIMAL_INTERNAL_PROJECT_REQUEST_H
16+
#define GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_BIGQUERY_V2_MINIMAL_INTERNAL_PROJECT_REQUEST_H
17+
18+
#include "google/cloud/internal/rest_request.h"
19+
#include "google/cloud/options.h"
20+
#include "google/cloud/status_or.h"
21+
#include "google/cloud/tracing_options.h"
22+
#include "google/cloud/version.h"
23+
#include "absl/strings/string_view.h"
24+
#include "absl/types/optional.h"
25+
#include <string>
26+
27+
namespace google {
28+
namespace cloud {
29+
namespace bigquery_v2_minimal_internal {
30+
GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN
31+
32+
class ListProjectsRequest {
33+
public:
34+
ListProjectsRequest() = default;
35+
36+
std::int32_t const& max_results() const { return max_results_; }
37+
std::string const& page_token() const { return page_token_; }
38+
39+
ListProjectsRequest& set_max_results(std::int32_t max_results) & {
40+
max_results_ = max_results;
41+
return *this;
42+
}
43+
ListProjectsRequest&& set_max_results(std::int32_t max_results) && {
44+
return std::move(set_max_results(max_results));
45+
}
46+
47+
ListProjectsRequest& set_page_token(std::string page_token) & {
48+
page_token_ = std::move(page_token);
49+
return *this;
50+
}
51+
ListProjectsRequest&& set_page_token(std::string page_token) && {
52+
return std::move(set_page_token(std::move(page_token)));
53+
}
54+
55+
std::string DebugString(absl::string_view name,
56+
TracingOptions const& options = {},
57+
int indent = 0) const;
58+
59+
private:
60+
std::int32_t max_results_{0};
61+
std::string page_token_;
62+
};
63+
64+
// Builds RestRequest from ListProjectsRequest.
65+
StatusOr<rest_internal::RestRequest> BuildRestRequest(
66+
ListProjectsRequest const& r);
67+
68+
GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_END
69+
} // namespace bigquery_v2_minimal_internal
70+
} // namespace cloud
71+
} // namespace google
72+
73+
#endif // GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_BIGQUERY_V2_MINIMAL_INTERNAL_PROJECT_REQUEST_H

0 commit comments

Comments
 (0)