Google Cloud Spanner C++ Client
A C++ Client Library for Google Cloud Spanner
read_partition.h
Go to the documentation of this file.
1 // Copyright 2019 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 // http://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_SPANNER_READ_PARTITION_H
16 #define GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_SPANNER_READ_PARTITION_H
17 
21 #include "google/cloud/status_or.h"
22 #include <google/spanner/v1/spanner.pb.h>
23 #include <string>
24 #include <vector>
25 
26 namespace google {
27 namespace cloud {
28 namespace spanner {
29 inline namespace SPANNER_CLIENT_NS {
30 
31 class ReadPartition;
32 
51 StatusOr<std::string> SerializeReadPartition(
52  ReadPartition const& read_partition);
53 
72 StatusOr<ReadPartition> DeserializeReadPartition(
73  std::string const& serialized_read_partition);
74 
75 // Internal implementation details that callers should not use.
76 namespace internal {
77 ReadPartition MakeReadPartition(std::string transaction_id,
78  std::string session_id,
79  std::string partition_token,
80  std::string table_name, KeySet key_set,
81  std::vector<std::string> column_names,
82  ReadOptions read_options = {});
83 Connection::ReadParams MakeReadParams(ReadPartition const& read_partition);
84 } // namespace internal
85 
95  public:
100  ReadPartition() = default;
101 
104  ReadPartition(ReadPartition const&) = default;
105  ReadPartition(ReadPartition&&) = default;
106  ReadPartition& operator=(ReadPartition const&) = default;
107  ReadPartition& operator=(ReadPartition&&) = default;
109 
110  std::string TableName() const { return proto_.table(); }
111  std::vector<std::string> ColumnNames() const {
112  auto const& columns = proto_.columns();
113  return std::vector<std::string>(columns.begin(), columns.end());
114  }
115  google::cloud::spanner::ReadOptions ReadOptions() const {
116  google::cloud::spanner::ReadOptions options;
117  options.index_name = proto_.index();
118  options.limit = proto_.limit();
119  return options;
120  }
121 
124  friend bool operator==(ReadPartition const& lhs, ReadPartition const& rhs);
125  friend bool operator!=(ReadPartition const& lhs, ReadPartition const& rhs);
127 
128  private:
129  friend class ReadPartitionTester;
130  friend ReadPartition internal::MakeReadPartition(
131  std::string transaction_id, std::string session_id,
132  std::string partition_token, std::string table_name, KeySet key_set,
133  std::vector<std::string> column_names,
134  google::cloud::spanner::ReadOptions read_options);
135  friend Connection::ReadParams internal::MakeReadParams(
136  ReadPartition const& read_partition);
137  friend StatusOr<std::string> SerializeReadPartition(
138  ReadPartition const& read_partition);
139  friend StatusOr<ReadPartition> DeserializeReadPartition(
140  std::string const& serialized_read_partition);
141 
142  explicit ReadPartition(google::spanner::v1::ReadRequest proto)
143  : proto_(std::move(proto)) {}
144  ReadPartition(std::string transaction_id, std::string session_id,
145  std::string partition_token, std::string table_name,
146  google::cloud::spanner::KeySet key_set,
147  std::vector<std::string> column_names,
148  google::cloud::spanner::ReadOptions read_options = {});
149 
150  // Accessor methods for use by friends.
151  std::string PartitionToken() const { return proto_.partition_token(); }
152  std::string SessionId() const { return proto_.session(); }
153  std::string TransactionId() const { return proto_.transaction().id(); }
154  google::spanner::v1::KeySet KeySet() const { return proto_.key_set(); }
155 
156  google::spanner::v1::ReadRequest proto_;
157 };
158 
159 } // namespace SPANNER_CLIENT_NS
160 } // namespace spanner
161 } // namespace cloud
162 } // namespace google
163 
164 #endif // GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_SPANNER_READ_PARTITION_H
StatusOr< std::string > SerializeReadPartition(ReadPartition const &read_partition)
Serializes an instance of ReadPartition to a string of bytes.
bool operator!=(Backup const &a, Backup const &b)
Definition: backup.cc:33
StatusOr< ReadPartition > DeserializeReadPartition(std::string const &serialized_read_partition)
Deserializes the provided string into a ReadPartition.
bool operator==(Backup const &a, Backup const &b)
Definition: backup.cc:29
The KeySet class is a regular type that represents a collection of Keys.
Definition: keys.h:158
Contains all the Cloud Spanner C++ client types and functions.
google::cloud::spanner::ReadOptions ReadOptions() const
The ReadPartition class is a regular type that represents a single slice of a parallel Read operation...
std::vector< std::string > ColumnNames() const
#define SPANNER_CLIENT_NS
Definition: version.h:22