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