Google Cloud Spanner C++ Client  1.35.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  * Construct from the the new, recommended way to represent options of all
47  * varieties, `google::cloud::Options`.
48  */
49  explicit QueryOptions(Options const& opts);
50 
51  /// Returns the optimizer version
52  absl::optional<std::string> const& optimizer_version() const {
53  return optimizer_version_;
54  }
55 
56  /**
57  * Sets the optimizer version to the specified integer string. Setting to
58  * the empty string will use the database default. Use the string "latest" to
59  * use the latest available optimizer version.
60  */
61  QueryOptions& set_optimizer_version(absl::optional<std::string> version) {
62  optimizer_version_ = std::move(version);
63  return *this;
64  }
65 
66  /// Returns the optimizer statistics package
67  absl::optional<std::string> const& optimizer_statistics_package() const {
68  return optimizer_statistics_package_;
69  }
70 
71  /**
72  * Sets the optimizer statistics package to the specified string. Setting to
73  * the empty string will use the database default.
74  */
76  absl::optional<std::string> stats_package) {
77  optimizer_statistics_package_ = std::move(stats_package);
78  return *this;
79  }
80 
81  /// Returns the request priority.
82  absl::optional<RequestPriority> const& request_priority() const {
83  return request_priority_;
84  }
85 
86  /// Sets the request priority.
87  QueryOptions& set_request_priority(absl::optional<RequestPriority> priority) {
88  request_priority_ = std::move(priority);
89  return *this;
90  }
91 
92  /// Returns the request tag.
93  absl::optional<std::string> const& request_tag() const {
94  return request_tag_;
95  }
96 
97  /// Sets the request tag.
98  QueryOptions& set_request_tag(absl::optional<std::string> tag) {
99  request_tag_ = std::move(tag);
100  return *this;
101  }
102 
103  friend bool operator==(QueryOptions const& a, QueryOptions const& b) {
104  return a.request_priority_ == b.request_priority_ &&
105  a.request_tag_ == b.request_tag_ &&
106  a.optimizer_version_ == b.optimizer_version_ &&
107  a.optimizer_statistics_package_ == b.optimizer_statistics_package_;
108  }
109 
110  friend bool operator!=(QueryOptions const& a, QueryOptions const& b) {
111  return !(a == b);
112  }
113 
114  private:
115  // Note: If you add an attribute here, remember to update the implementation
116  // of Client::OverlayQueryOptions().
117  absl::optional<std::string> optimizer_version_;
118  absl::optional<std::string> optimizer_statistics_package_;
119  absl::optional<RequestPriority> request_priority_;
120  absl::optional<std::string> request_tag_;
121 };
122 
124 } // namespace spanner
125 } // namespace cloud
126 } // namespace google
127 
128 #endif // GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_SPANNER_QUERY_OPTIONS_H