Skip to content

Commit a5d8a1d

Browse files
chore(bigtable): add minimum QueryPlan class with dummy behavior (#15644)
* chore(bigtable): add minimum QueryPlan class with dummy behavior * chore: remove redundant std::move * chore: remove unused imports * chore: remove public constructor, args by value
1 parent 45b56d7 commit a5d8a1d

File tree

6 files changed

+164
-0
lines changed

6 files changed

+164
-0
lines changed

google/cloud/bigtable/CMakeLists.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -212,6 +212,8 @@ add_library(
212212
internal/partial_result_set_source.h
213213
internal/prefix_range_end.cc
214214
internal/prefix_range_end.h
215+
internal/query_plan.cc
216+
internal/query_plan.h
215217
internal/rate_limiter.cc
216218
internal/rate_limiter.h
217219
internal/readrowsparser.cc
@@ -481,6 +483,7 @@ if (BUILD_TESTING)
481483
internal/partial_result_set_resume_test.cc
482484
internal/partial_result_set_source_test.cc
483485
internal/prefix_range_end_test.cc
486+
internal/query_plan_test.cc
484487
internal/rate_limiter_test.cc
485488
internal/retry_traits_test.cc
486489
internal/traced_row_reader_test.cc

google/cloud/bigtable/bigtable_client_unit_tests.bzl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@ bigtable_client_unit_tests = [
6767
"internal/partial_result_set_resume_test.cc",
6868
"internal/partial_result_set_source_test.cc",
6969
"internal/prefix_range_end_test.cc",
70+
"internal/query_plan_test.cc",
7071
"internal/rate_limiter_test.cc",
7172
"internal/retry_traits_test.cc",
7273
"internal/traced_row_reader_test.cc",

google/cloud/bigtable/google_cloud_cpp_bigtable.bzl

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,7 @@ google_cloud_cpp_bigtable_hdrs = [
105105
"internal/partial_result_set_resume.h",
106106
"internal/partial_result_set_source.h",
107107
"internal/prefix_range_end.h",
108+
"internal/query_plan.h",
108109
"internal/rate_limiter.h",
109110
"internal/readrowsparser.h",
110111
"internal/retry_traits.h",
@@ -218,6 +219,7 @@ google_cloud_cpp_bigtable_srcs = [
218219
"internal/partial_result_set_resume.cc",
219220
"internal/partial_result_set_source.cc",
220221
"internal/prefix_range_end.cc",
222+
"internal/query_plan.cc",
221223
"internal/rate_limiter.cc",
222224
"internal/readrowsparser.cc",
223225
"internal/traced_row_reader.cc",
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
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/internal/query_plan.h"
16+
#include "google/cloud/completion_queue.h"
17+
#include <google/bigtable/v2/data.pb.h>
18+
19+
namespace google {
20+
namespace cloud {
21+
namespace bigtable_internal {
22+
GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN
23+
24+
std::string const& QueryPlan::prepared_query() const {
25+
return response_.prepared_query();
26+
}
27+
28+
google::bigtable::v2::ResultSetMetadata const& QueryPlan::metadata() const {
29+
return response_.metadata();
30+
}
31+
32+
GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_END
33+
} // namespace bigtable_internal
34+
} // namespace cloud
35+
} // namespace google
Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
2+
// Copyright 2025 Google LLC
3+
//
4+
// Licensed under the Apache License, Version 2.0 (the "License");
5+
// you may not use this file except in compliance with the License.
6+
// You may obtain a copy of the License at
7+
//
8+
// https://www.apache.org/licenses/LICENSE-2.0
9+
//
10+
// Unless required by applicable law or agreed to in writing, software
11+
// distributed under the License is distributed on an "AS IS" BASIS,
12+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
// See the License for the specific language governing permissions and
14+
// limitations under the License.
15+
16+
#ifndef GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_BIGTABLE_INTERNAL_QUERY_PLAN_H
17+
#define GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_BIGTABLE_INTERNAL_QUERY_PLAN_H
18+
19+
#include "google/cloud/bigtable/version.h"
20+
#include "google/cloud/completion_queue.h"
21+
#include <google/bigtable/v2/bigtable.pb.h>
22+
#include <string>
23+
#include <utility>
24+
25+
namespace google {
26+
namespace cloud {
27+
namespace bigtable_internal {
28+
GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN
29+
30+
class QueryPlan : public std::enable_shared_from_this<QueryPlan> {
31+
public:
32+
// Typically, a lambda capturing the original PrepareQueryRequest and
33+
// DataConnection pointer necessary to call the PrepareQuery RPC.
34+
using RefreshFn = std::function<google::bigtable::v2::PrepareQueryResponse()>;
35+
36+
// Calls the constructor and then Initialize.
37+
static std::shared_ptr<QueryPlan> Create(
38+
CompletionQueue cq, google::bigtable::v2::PrepareQueryResponse response,
39+
RefreshFn fn) {
40+
return std::shared_ptr<QueryPlan>(
41+
new QueryPlan(std::move(cq), std::move(response), std::move(fn)));
42+
}
43+
44+
// Accessor for the prepared_query field in response_.
45+
std::string const& prepared_query() const;
46+
47+
// Accessor for the metadata field in response_.
48+
google::bigtable::v2::ResultSetMetadata const& metadata() const;
49+
50+
private:
51+
QueryPlan(CompletionQueue cq,
52+
google::bigtable::v2::PrepareQueryResponse response, RefreshFn fn)
53+
: cq_(std::move(cq)),
54+
response_(std::move(response)),
55+
fn_(std::move(fn)) {}
56+
57+
// Performs the first call to ScheduleRefresh and any other initialization not
58+
// possible in the constructor.
59+
void Initialize() {}
60+
61+
// Calls MakeDeadlineTimer on the CompletionQueue with a continuation lambda
62+
// capturing a std::weak_ptr to this that calls RefreshQueryPlan.
63+
void ScheduleRefresh() {}
64+
65+
// Performs the synchronization around calling RefreshFn and updating
66+
// response_.
67+
void RefreshQueryPlan() {}
68+
69+
CompletionQueue cq_;
70+
future<void> refresh_timer_;
71+
mutable std::mutex mu_;
72+
std::condition_variable cond_;
73+
google::bigtable::v2::PrepareQueryResponse response_; // GUARDED_BY(mu_)
74+
RefreshFn fn_;
75+
};
76+
77+
GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_END
78+
} // namespace bigtable_internal
79+
} // namespace cloud
80+
} // namespace google
81+
82+
#endif // GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_BIGTABLE_INTERNAL_QUERY_PLAN_H
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
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/internal/query_plan.h"
16+
#include "google/cloud/completion_queue.h"
17+
#include <google/bigtable/v2/data.pb.h>
18+
#include <gmock/gmock.h>
19+
20+
namespace google {
21+
namespace cloud {
22+
namespace bigtable_internal {
23+
GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN
24+
namespace {
25+
26+
/// @test Basic test to confirm compilation and dummy behavior.
27+
/// Remove this after implementing QueryPlan.
28+
TEST(QueryPlanTest, TestDummyMethods) {
29+
auto cq = CompletionQueue();
30+
auto response = google::bigtable::v2::PrepareQueryResponse();
31+
auto fn = QueryPlan::RefreshFn();
32+
auto created = QueryPlan::Create(cq, response, fn);
33+
ASSERT_EQ("", (*created).prepared_query());
34+
ASSERT_EQ(0, created->metadata().ByteSizeLong());
35+
}
36+
37+
} // namespace
38+
GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_END
39+
} // namespace bigtable_internal
40+
} // namespace cloud
41+
} // namespace google

0 commit comments

Comments
 (0)