Google Cloud Spanner C++ Client  2.1.0
A C++ Client Library for Google Cloud Spanner
query_options.h
Go to the documentation of this file.
1 // Copyright 2020 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_SPANNER_QUERY_OPTIONS_H
16 #define GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_SPANNER_QUERY_OPTIONS_H
17 
18 #include "google/cloud/spanner/request_priority.h"
19 #include "google/cloud/spanner/version.h"
20 #include "google/cloud/optional.h"
21 #include "google/cloud/options.h"
22 #include "absl/types/optional.h"
23 #include <string>
24 
25 namespace google {
26 namespace cloud {
27 namespace spanner {
29 
30 /**
31  * These QueryOptions allow users to configure features about how their SQL
32  * queries executes on the server.
33  *
34  * @see https://cloud.google.com/spanner/docs/reference/rest/v1/QueryOptions
35  * @see http://cloud/spanner/docs/query-optimizer/manage-query-optimizer
36  */
37 class QueryOptions {
38  public:
39  QueryOptions() = default;
40  QueryOptions(QueryOptions const&) = default;
41  QueryOptions& operator=(QueryOptions const&) = default;
42  QueryOptions(QueryOptions&&) = default;
44 
45  /**
46  * Constructs from the the new, recommended way to represent options
47  * of all varieties, `google::cloud::Options`.
48  */
49  explicit QueryOptions(Options const& opts);
50 
51  /**
52  * Converts to the new, recommended way to represent options of all
53  * varieties, `google::cloud::Options`.
54  */
55  explicit operator Options() const;
56 
57  /// Returns the optimizer version
58  absl::optional<std::string> const& optimizer_version() const {
59  return optimizer_version_;
60  }
61 
62  /**
63  * Sets the optimizer version to the specified integer string. Setting to
64  * the empty string will use the database default. Use the string "latest" to
65  * use the latest available optimizer version.
66  */
67  QueryOptions& set_optimizer_version(absl::optional<std::string> version) {
68  optimizer_version_ = std::move(version);
69  return *this;
70  }
71 
72  /// Returns the optimizer statistics package
73  absl::optional<std::string> const& optimizer_statistics_package() const {
74  return optimizer_statistics_package_;
75  }
76 
77  /**
78  * Sets the optimizer statistics package to the specified string. Setting to
79  * the empty string will use the database default.
80  */
82  absl::optional<std::string> stats_package) {
83  optimizer_statistics_package_ = std::move(stats_package);
84  return *this;
85  }
86 
87  /// Returns the request priority.
88  absl::optional<RequestPriority> const& request_priority() const {
89  return request_priority_;
90  }
91 
92  /// Sets the request priority.
93  QueryOptions& set_request_priority(absl::optional<RequestPriority> priority) {
94  request_priority_ = std::move(priority);
95  return *this;
96  }
97 
98  /// Returns the request tag.
99  absl::optional<std::string> const& request_tag() const {
100  return request_tag_;
101  }
102 
103  /// Sets the request tag.
104  QueryOptions& set_request_tag(absl::optional<std::string> tag) {
105  request_tag_ = std::move(tag);
106  return *this;
107  }
108 
109  friend bool operator==(QueryOptions const& a, QueryOptions const& b) {
110  return a.request_priority_ == b.request_priority_ &&
111  a.request_tag_ == b.request_tag_ &&
112  a.optimizer_version_ == b.optimizer_version_ &&
113  a.optimizer_statistics_package_ == b.optimizer_statistics_package_;
114  }
115 
116  friend bool operator!=(QueryOptions const& a, QueryOptions const& b) {
117  return !(a == b);
118  }
119 
120  private:
121  absl::optional<std::string> optimizer_version_;
122  absl::optional<std::string> optimizer_statistics_package_;
123  absl::optional<RequestPriority> request_priority_;
124  absl::optional<std::string> request_tag_;
125 };
126 
128 } // namespace spanner
129 } // namespace cloud
130 } // namespace google
131 
132 #endif // GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_SPANNER_QUERY_OPTIONS_H