Google Cloud Spanner C++ Client
A C++ Client Library for Google Cloud Spanner
query_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_QUERY_PARTITION_H
16 #define GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_SPANNER_QUERY_PARTITION_H
17 
20 #include "google/cloud/status_or.h"
21 #include <memory>
22 #include <string>
23 
24 namespace google {
25 namespace cloud {
26 namespace spanner {
27 inline namespace SPANNER_CLIENT_NS {
28 
29 class QueryPartition;
30 
49 StatusOr<std::string> SerializeQueryPartition(
50  QueryPartition const& query_partition);
51 
70 StatusOr<QueryPartition> DeserializeQueryPartition(
71  std::string const& serialized_query_partition);
72 
73 // Internal implementation details that callers should not use.
74 namespace internal {
75 QueryPartition MakeQueryPartition(std::string const& transaction_id,
76  std::string const& session_id,
77  std::string const& partition_token,
78  SqlStatement const& sql_statement);
79 Connection::SqlParams MakeSqlParams(QueryPartition const& query_partition);
80 } // namespace internal
81 
91  public:
96  QueryPartition() = default;
97 
100  QueryPartition(QueryPartition const&) = default;
101  QueryPartition(QueryPartition&&) = default;
102  QueryPartition& operator=(QueryPartition const&) = default;
103  QueryPartition& operator=(QueryPartition&&) = default;
105 
109  SqlStatement const& sql_statement() const { return sql_statement_; }
110 
113  friend bool operator==(QueryPartition const& a, QueryPartition const& b);
114  friend bool operator!=(QueryPartition const& a, QueryPartition const& b) {
115  return !(a == b);
116  }
118 
119  private:
120  friend class QueryPartitionTester;
121  friend QueryPartition internal::MakeQueryPartition(
122  std::string const& transaction_id, std::string const& session_id,
123  std::string const& partition_token, SqlStatement const& sql_statement);
124  friend Connection::SqlParams internal::MakeSqlParams(
125  QueryPartition const& query_partition);
126  friend StatusOr<std::string> SerializeQueryPartition(
127  QueryPartition const& query_partition);
128  friend StatusOr<QueryPartition> DeserializeQueryPartition(
129  std::string const& serialized_query_partition);
130 
131  QueryPartition(std::string transaction_id, std::string session_id,
132  std::string partition_token, SqlStatement sql_statement);
133 
134  // Accessor methods for use by friends.
135  std::string const& partition_token() const { return partition_token_; }
136  std::string const& session_id() const { return session_id_; }
137  std::string const& transaction_id() const { return transaction_id_; }
138 
139  std::string transaction_id_;
140  std::string session_id_;
141  std::string partition_token_;
142  SqlStatement sql_statement_;
143 };
144 
145 } // namespace SPANNER_CLIENT_NS
146 } // namespace spanner
147 } // namespace cloud
148 } // namespace google
149 
150 #endif // GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_SPANNER_QUERY_PARTITION_H
StatusOr< std::string > SerializeQueryPartition(QueryPartition const &query_partition)
Serializes an instance of QueryPartition to a string of bytes.
Wrap the arguments to ExecuteQuery(), ExecuteDml(), ProfileQuery(), ProfileDml(), and AnalyzeSql().
Definition: connection.h:89
friend bool operator!=(QueryPartition const &a, QueryPartition const &b)
bool operator==(Backup const &a, Backup const &b)
Definition: backup.cc:29
The QueryPartition class is a regular type that represents a single slice of a parallel SQL read.
Contains all the Cloud Spanner C++ client types and functions.
#define SPANNER_CLIENT_NS
Definition: version.h:22
SqlStatement const & sql_statement() const
Accessor for the SqlStatement associated with this QueryPartition.
StatusOr< QueryPartition > DeserializeQueryPartition(std::string const &serialized_query_partition)
Deserializes the provided string into a QueryPartition.
Represents a potentially parameterized SQL statement.
Definition: sql_statement.h:55