Skip to content

Commit df1873a

Browse files
committed
chore: separate into respective files
1 parent d0bc36a commit df1873a

File tree

9 files changed

+168
-69
lines changed

9 files changed

+168
-69
lines changed

google/cloud/bigtable/CMakeLists.txt

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,8 @@ add_library(
109109
app_profile_config.cc
110110
app_profile_config.h
111111
async_row_reader.h
112+
bound_query.cc
113+
bound_query.h
112114
bytes.cc
113115
bytes.h
114116
cell.h
@@ -236,8 +238,9 @@ add_library(
236238
options.h
237239
polling_policy.cc
238240
polling_policy.h
241+
prepared_query.cc
242+
prepared_query.h
239243
query.cc
240-
query.h
241244
query_row.cc
242245
query_row.h
243246
read_modify_write_rule.h

google/cloud/bigtable/bigtable_client_unit_tests.bzl

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ bigtable_client_unit_tests = [
2121
"app_profile_config_test.cc",
2222
"async_read_stream_test.cc",
2323
"bigtable_version_test.cc",
24+
"bound_query_test.cc",
2425
"bytes_test.cc",
2526
"cell_test.cc",
2627
"client_options_test.cc",
@@ -78,8 +79,8 @@ bigtable_client_unit_tests = [
7879
"mutation_batcher_test.cc",
7980
"mutations_test.cc",
8081
"polling_policy_test.cc",
82+
"prepared_query_test.cc",
8183
"query_row_test.cc",
82-
"query_test.cc",
8384
"read_modify_write_rule_test.cc",
8485
"row_range_test.cc",
8586
"row_reader_test.cc",
Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,7 @@
1212
// See the License for the specific language governing permissions and
1313
// limitations under the License.
1414

15-
#include "google/cloud/bigtable/query.h"
16-
#include "google/cloud/bigtable/sql_statement.h"
15+
#include "google/cloud/bigtable/bound_query.h"
1716

1817
namespace google {
1918
namespace cloud {
@@ -49,16 +48,6 @@ google::bigtable::v2::ExecuteQueryRequest BoundQuery::ToRequestProto() {
4948
return result;
5049
}
5150

52-
BoundQuery PreparedQuery::BindParameters(
53-
std::unordered_map<std::string, Value> params) const {
54-
return BoundQuery(instance_, query_plan_, std::move(params));
55-
}
56-
57-
InstanceResource const& PreparedQuery::instance() const { return instance_; }
58-
SqlStatement const& PreparedQuery::sql_statement() const {
59-
return sql_statement_;
60-
}
61-
6251
GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_END
6352
} // namespace bigtable
6453
} // namespace cloud
Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
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_GOOGLE_CLOUD_BIGTABLE_BOUND_QUERY_H
16+
#define GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_BIGTABLE_BOUND_QUERY_H
17+
18+
#include "google/cloud/bigtable/instance_resource.h"
19+
#include "google/cloud/bigtable/internal/query_plan.h"
20+
#include "google/cloud/bigtable/value.h"
21+
#include "google/cloud/bigtable/version.h"
22+
#include "google/cloud/completion_queue.h"
23+
#include <google/bigtable/v2/bigtable.pb.h>
24+
#include <string>
25+
#include <unordered_map>
26+
27+
namespace google {
28+
namespace cloud {
29+
namespace bigtable {
30+
GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN
31+
32+
/**
33+
* Move only type representing a PreparedQuery with parameter values.
34+
* Created by calling PreparedQuery::BindParameters.
35+
*/
36+
class BoundQuery {
37+
public:
38+
// Copy and move.
39+
BoundQuery(BoundQuery const&) = delete;
40+
BoundQuery(BoundQuery&&) = default;
41+
BoundQuery& operator=(BoundQuery const&) = delete;
42+
BoundQuery& operator=(BoundQuery&&) = default;
43+
44+
// Accessors
45+
std::string const& prepared_query() const;
46+
google::bigtable::v2::ResultSetMetadata const& metadata() const;
47+
std::unordered_map<std::string, Value> const& parameters() const;
48+
InstanceResource const& instance() const;
49+
50+
google::bigtable::v2::ExecuteQueryRequest ToRequestProto();
51+
52+
private:
53+
friend class PreparedQuery;
54+
BoundQuery(InstanceResource instance,
55+
std::shared_ptr<bigtable_internal::QueryPlan> query_plan,
56+
std::unordered_map<std::string, Value> parameters)
57+
: instance_(std::move(instance)),
58+
query_plan_(std::move(query_plan)),
59+
parameters_(std::move(parameters)) {}
60+
61+
InstanceResource instance_;
62+
// Copy of the query_plan_ contained by the PreparedQuery that created
63+
// this BoundQuery.
64+
std::shared_ptr<bigtable_internal::QueryPlan> query_plan_;
65+
std::unordered_map<std::string, Value> parameters_;
66+
};
67+
68+
GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_END
69+
} // namespace bigtable
70+
} // namespace cloud
71+
} // namespace google
72+
#endif // GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_BIGTABLE_BOUND_QUERY_H
Lines changed: 1 addition & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
// See the License for the specific language governing permissions and
1313
// limitations under the License.
1414

15-
#include "google/cloud/bigtable/query.h"
15+
#include "google/cloud/bigtable/bound_query.h"
1616
#include "google/cloud/bigtable/value.h"
1717
#include "google/cloud/testing_util/status_matchers.h"
1818
#include <algorithm>
@@ -24,19 +24,6 @@ GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN
2424
namespace {
2525
using ::google::bigtable::v2::PrepareQueryResponse;
2626

27-
TEST(PreparedQuery, DefaultConstructor) {
28-
CompletionQueue cq;
29-
Project p("dummy-project");
30-
InstanceResource instance(p, "dummy-instance");
31-
std::string statement_contents(
32-
"SELECT * FROM my_table WHERE col1 = @val1 and col2 = @val2;");
33-
SqlStatement sql_statement(statement_contents);
34-
PrepareQueryResponse response;
35-
PreparedQuery q(cq, instance, sql_statement, response);
36-
EXPECT_EQ(instance.FullName(), q.instance().FullName());
37-
EXPECT_EQ(statement_contents, q.sql_statement().sql());
38-
}
39-
4027
TEST(BoundQuery, FromPreparedQuery) {
4128
CompletionQueue cq;
4229
Project p("dummy-project");

google/cloud/bigtable/google_cloud_cpp_bigtable.bzl

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ google_cloud_cpp_bigtable_hdrs = [
4848
"admin_client.h",
4949
"app_profile_config.h",
5050
"async_row_reader.h",
51+
"bound_query.h",
5152
"bytes.h",
5253
"cell.h",
5354
"client_options.h",
@@ -121,7 +122,7 @@ google_cloud_cpp_bigtable_hdrs = [
121122
"mutations.h",
122123
"options.h",
123124
"polling_policy.h",
124-
"query.h",
125+
"prepared_query.h",
125126
"query_row.h",
126127
"read_modify_write_rule.h",
127128
"resource_names.h",
@@ -174,6 +175,7 @@ google_cloud_cpp_bigtable_srcs = [
174175
"admin/internal/bigtable_table_admin_tracing_stub.cc",
175176
"admin_client.cc",
176177
"app_profile_config.cc",
178+
"bound_query.cc",
177179
"bytes.cc",
178180
"client_options.cc",
179181
"cluster_config.cc",
@@ -228,6 +230,7 @@ google_cloud_cpp_bigtable_srcs = [
228230
"mutation_batcher.cc",
229231
"mutations.cc",
230232
"polling_policy.cc",
233+
"prepared_query.cc",
231234
"query.cc",
232235
"query_row.cc",
233236
"resource_names.cc",
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
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/bigtable/prepared_query.h"
16+
#include "google/cloud/bigtable/sql_statement.h"
17+
18+
namespace google {
19+
namespace cloud {
20+
namespace bigtable {
21+
GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN
22+
23+
BoundQuery PreparedQuery::BindParameters(
24+
std::unordered_map<std::string, Value> params) const {
25+
return BoundQuery(instance_, query_plan_, std::move(params));
26+
}
27+
28+
InstanceResource const& PreparedQuery::instance() const { return instance_; }
29+
SqlStatement const& PreparedQuery::sql_statement() const {
30+
return sql_statement_;
31+
}
32+
33+
GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_END
34+
} // namespace bigtable
35+
} // namespace cloud
36+
} // namespace google
Lines changed: 4 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,12 @@
1212
// See the License for the specific language governing permissions and
1313
// limitations under the License.
1414

15-
#ifndef GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_BIGTABLE_QUERY_H
16-
#define GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_BIGTABLE_QUERY_H
15+
#ifndef GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_BIGTABLE_PREPARED_QUERY_H
16+
#define GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_BIGTABLE_PREPARED_QUERY_H
1717

18+
#include "google/cloud/bigtable/bound_query.h"
1819
#include "google/cloud/bigtable/instance_resource.h"
1920
#include "google/cloud/bigtable/internal/query_plan.h"
20-
#include "google/cloud/bigtable/sql_statement.h"
2121
#include "google/cloud/bigtable/value.h"
2222
#include "google/cloud/bigtable/version.h"
2323
#include "google/cloud/completion_queue.h"
@@ -30,42 +30,6 @@ namespace cloud {
3030
namespace bigtable {
3131
GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN
3232

33-
/**
34-
* Move only type representing a PreparedQuery with parameter values.
35-
* Created by calling PreparedQuery::BindParameters.
36-
*/
37-
class BoundQuery {
38-
public:
39-
// Copy and move.
40-
BoundQuery(BoundQuery const&) = delete;
41-
BoundQuery(BoundQuery&&) = default;
42-
BoundQuery& operator=(BoundQuery const&) = delete;
43-
BoundQuery& operator=(BoundQuery&&) = default;
44-
45-
// Accessors
46-
std::string const& prepared_query() const;
47-
google::bigtable::v2::ResultSetMetadata const& metadata() const;
48-
std::unordered_map<std::string, Value> const& parameters() const;
49-
InstanceResource const& instance() const;
50-
51-
google::bigtable::v2::ExecuteQueryRequest ToRequestProto();
52-
53-
private:
54-
friend class PreparedQuery;
55-
BoundQuery(InstanceResource instance,
56-
std::shared_ptr<bigtable_internal::QueryPlan> query_plan,
57-
std::unordered_map<std::string, Value> parameters)
58-
: instance_(std::move(instance)),
59-
query_plan_(std::move(query_plan)),
60-
parameters_(std::move(parameters)) {}
61-
62-
InstanceResource instance_;
63-
// Copy of the query_plan_ contained by the PreparedQuery that created
64-
// this BoundQuery.
65-
std::shared_ptr<bigtable_internal::QueryPlan> query_plan_;
66-
std::unordered_map<std::string, Value> parameters_;
67-
};
68-
6933
// Represents a long-lived query execution plan.
7034
// Query plans can expire and are refreshed as a background task.
7135
class PreparedQuery {
@@ -107,4 +71,4 @@ GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_END
10771
} // namespace bigtable
10872
} // namespace cloud
10973
} // namespace google
110-
#endif // GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_BIGTABLE_QUERY_H
74+
#endif // GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_BIGTABLE_PREPARED_QUERY_H
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
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/bigtable/query.h"
16+
#include "google/cloud/bigtable/value.h"
17+
#include "google/cloud/testing_util/status_matchers.h"
18+
#include <algorithm>
19+
20+
namespace google {
21+
namespace cloud {
22+
namespace bigtable {
23+
GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN
24+
namespace {
25+
using ::google::bigtable::v2::PrepareQueryResponse;
26+
27+
TEST(PreparedQuery, DefaultConstructor) {
28+
CompletionQueue cq;
29+
Project p("dummy-project");
30+
InstanceResource instance(p, "dummy-instance");
31+
std::string statement_contents(
32+
"SELECT * FROM my_table WHERE col1 = @val1 and col2 = @val2;");
33+
SqlStatement sql_statement(statement_contents);
34+
PrepareQueryResponse response;
35+
PreparedQuery q(cq, instance, sql_statement, response);
36+
EXPECT_EQ(instance.FullName(), q.instance().FullName());
37+
EXPECT_EQ(statement_contents, q.sql_statement().sql());
38+
}
39+
40+
} // namespace
41+
GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_END
42+
} // namespace bigtable
43+
} // namespace cloud
44+
} // namespace google

0 commit comments

Comments
 (0)