Google Cloud Spanner C++ Client  1.32.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 // 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_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 "absl/types/optional.h"
22 #include <string>
23 
24 namespace google {
25 namespace cloud {
26 namespace spanner {
27 inline namespace SPANNER_CLIENT_NS {
28 
29 /**
30  * These QueryOptions allow users to configure features about how their SQL
31  * queries executes on the server.
32  *
33  * @see https://cloud.google.com/spanner/docs/reference/rest/v1/QueryOptions
34  * @see http://cloud/spanner/docs/query-optimizer/manage-query-optimizer
35  */
36 class QueryOptions {
37  public:
38  QueryOptions() = default;
39  QueryOptions(QueryOptions const&) = default;
40  QueryOptions& operator=(QueryOptions const&) = default;
41  QueryOptions(QueryOptions&&) = default;
43 
44  /// Returns the optimizer version
45  absl::optional<std::string> const& optimizer_version() const {
46  return optimizer_version_;
47  }
48 
49  /**
50  * Sets the optimizer version to the specified integer string. Setting to
51  * the empty string will use the database default. Use the string "latest" to
52  * use the latest available optimizer version.
53  */
54  QueryOptions& set_optimizer_version(absl::optional<std::string> version) {
55  optimizer_version_ = std::move(version);
56  return *this;
57  }
58 
59  /// Returns the optimizer statistics package
60  absl::optional<std::string> const& optimizer_statistics_package() const {
61  return optimizer_statistics_package_;
62  }
63 
64  /**
65  * Sets the optimizer statistics package to the specified string. Setting to
66  * the empty string will use the database default.
67  */
69  absl::optional<std::string> stats_package) {
70  optimizer_statistics_package_ = std::move(stats_package);
71  return *this;
72  }
73 
74  /// Returns the request priority.
75  absl::optional<RequestPriority> const& request_priority() const {
76  return request_priority_;
77  }
78 
79  /// Sets the request priority.
80  QueryOptions& set_request_priority(absl::optional<RequestPriority> priority) {
81  request_priority_ = std::move(priority);
82  return *this;
83  }
84 
85  /// Returns the request tag.
86  absl::optional<std::string> const& request_tag() const {
87  return request_tag_;
88  }
89 
90  /// Sets the request tag.
91  QueryOptions& set_request_tag(absl::optional<std::string> tag) {
92  request_tag_ = std::move(tag);
93  return *this;
94  }
95 
96  friend bool operator==(QueryOptions const& a, QueryOptions const& b) {
97  return a.request_priority_ == b.request_priority_ &&
98  a.request_tag_ == b.request_tag_ &&
99  a.optimizer_version_ == b.optimizer_version_ &&
100  a.optimizer_statistics_package_ == b.optimizer_statistics_package_;
101  }
102 
103  friend bool operator!=(QueryOptions const& a, QueryOptions const& b) {
104  return !(a == b);
105  }
106 
107  private:
108  // Note: If you add an attribute here, remember to update the implementation
109  // of Client::OverlayQueryOptions().
110  absl::optional<std::string> optimizer_version_;
111  absl::optional<std::string> optimizer_statistics_package_;
112  absl::optional<RequestPriority> request_priority_;
113  absl::optional<std::string> request_tag_;
114 };
115 
116 } // namespace SPANNER_CLIENT_NS
117 } // namespace spanner
118 } // namespace cloud
119 } // namespace google
120 
121 #endif // GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_SPANNER_QUERY_OPTIONS_H