Google Cloud Bigtable C++ Client  2.0.0
A C++ Client Library for Google Cloud Bigtable
row_set.h
Go to the documentation of this file.
1 // Copyright 2017 Google Inc.
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_BIGTABLE_ROW_SET_H
16 #define GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_BIGTABLE_ROW_SET_H
17 
18 #include "google/cloud/bigtable/row_range.h"
19 #include "google/cloud/bigtable/version.h"
20 
21 namespace google {
22 namespace cloud {
23 namespace bigtable {
25 /**
26  * Represent a (possibly non-continuous) set of row keys.
27  *
28  * Cloud Bigtable can scan non-continuous sets of rows, these sets can include
29  * a mix of specific row keys and ranges as defined by `bigtable::RowRange`.
30  */
31 class RowSet {
32  public:
33  /// Create an empty set.
34  RowSet() = default;
35 
36  RowSet(RowSet&&) = default;
37  RowSet& operator=(RowSet&&) = default;
38  RowSet(RowSet const&) = default;
39  RowSet& operator=(RowSet const&) = default;
40 
41  template <typename... Arg>
42  RowSet(Arg&&... a) { // NOLINT(google-explicit-constructor)
43  AppendAll(std::forward<Arg&&>(a)...);
44  }
45 
46  /// Add @p range to the set.
47  void Append(RowRange range) {
48  *row_set_.add_row_ranges() = std::move(range).as_proto();
49  }
50 
51  /**
52  * Add @p row_key to the set, minimize copies when possible.
53  */
54  template <typename T>
55  void Append(T&& row_key) {
56  *row_set_.add_row_keys() = std::forward<T>(row_key);
57  }
58 
59  /**
60  * Modify this object to contain the ranges and keys inside @p range.
61  *
62  * This function removes any rowkeys outside @p range, it removes any row
63  * ranges that do not intersect with @p range, and keeps only the intersection
64  * for those ranges that do intersect @p range.
65  */
66  RowSet Intersect(bigtable::RowRange const& range) const;
67 
68  /**
69  * Returns true if the set is empty.
70  *
71  * A row set is empty iff passing it to a ReadRows call would never
72  * cause it to return rows. This is true if the set consists of only
73  * empty ranges.
74  *
75  * Note that a default constructed RowSet is not empty, since it
76  * matches all rows in the table.
77  */
78  bool IsEmpty() const;
79 
80  ::google::bigtable::v2::RowSet const& as_proto() const& { return row_set_; }
81  ::google::bigtable::v2::RowSet&& as_proto() && { return std::move(row_set_); }
82 
83  private:
84  /// Append the arguments to the rowset.
85  template <typename H, typename... Tail>
86  void AppendAll(H&& head, Tail&&... a) {
87  // We cannot use the initializer list expression here because the types
88  // may be all different.
89  Append(std::forward<H>(head));
90  AppendAll(std::forward<Tail>(a)...);
91  }
92 
93  /// Terminate the recursion.
94  void AppendAll() {}
95 
96  ::google::bigtable::v2::RowSet row_set_;
97 };
99 } // namespace bigtable
100 } // namespace cloud
101 } // namespace google
102 
103 #endif // GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_BIGTABLE_ROW_SET_H