Google Cloud Bigtable C++ Client  1.42.0
A C++ Client Library for Google Cloud Bigtable
row_reader.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_READER_H
16 #define GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_BIGTABLE_ROW_READER_H
17 
18 #include "google/cloud/bigtable/data_client.h"
19 #include "google/cloud/bigtable/filters.h"
20 #include "google/cloud/bigtable/internal/readrowsparser.h"
21 #include "google/cloud/bigtable/internal/row_reader_impl.h"
22 #include "google/cloud/bigtable/metadata_update_policy.h"
23 #include "google/cloud/bigtable/row_set.h"
24 #include "google/cloud/bigtable/rpc_backoff_policy.h"
25 #include "google/cloud/bigtable/rpc_retry_policy.h"
26 #include "google/cloud/bigtable/version.h"
27 #include "google/cloud/stream_range.h"
28 
29 namespace google {
30 namespace cloud {
31 namespace bigtable {
33 class RowReader;
35 } // namespace bigtable
36 namespace bigtable_internal {
38 bigtable::RowReader MakeRowReader(std::shared_ptr<RowReaderImpl> impl);
40 } // namespace bigtable_internal
41 namespace bigtable {
43 
44 /**
45  * Object returned by Table::ReadRows(), enumerates rows in the response.
46  *
47  * @par Thread-safety
48  * Two threads operating concurrently on the same instance of this class or the
49  * iterators obtained from it are **not** guaranteed to work.
50  *
51  * Iterate over the results of ReadRows() using the STL idioms.
52  */
53 class RowReader {
54  public:
55  /**
56  * A constant for the magic value that means "no limit, get all rows".
57  *
58  * Zero is used as a magic value that means "get all rows" in the
59  * Cloud Bigtable RPC protocol.
60  */
61  // NOLINTNEXTLINE(readability-identifier-naming)
62  static std::int64_t constexpr NO_ROWS_LIMIT = 0;
63 
64  /// Default constructs an empty RowReader.
66 
68  RowReader(std::shared_ptr<DataClient> client, std::string table_name,
69  RowSet row_set, std::int64_t rows_limit, Filter filter,
70  std::unique_ptr<RPCRetryPolicy> retry_policy,
71  std::unique_ptr<RPCBackoffPolicy> backoff_policy,
72  MetadataUpdatePolicy metadata_update_policy,
73  std::unique_ptr<internal::ReadRowsParserFactory> parser_factory);
74 
76  RowReader(std::shared_ptr<DataClient> client, std::string app_profile_id,
77  std::string table_name, RowSet row_set, std::int64_t rows_limit,
78  Filter filter, std::unique_ptr<RPCRetryPolicy> retry_policy,
79  std::unique_ptr<RPCBackoffPolicy> backoff_policy,
80  MetadataUpdatePolicy metadata_update_policy,
81  std::unique_ptr<internal::ReadRowsParserFactory> parser_factory);
82 
83  RowReader(RowReader&&) = default;
84 
85  ~RowReader() = default;
86 
87  using iterator = StreamRange<Row>::iterator;
88 
89  /**
90  * Input iterator over rows in the response.
91  *
92  * The returned iterator is a single-pass input iterator that reads
93  * rows from the RowReader when incremented. The first row may be
94  * read when the iterator is constructed.
95  *
96  * Creating, and particularly incrementing, multiple iterators on
97  * the same RowReader is unsupported and can produce incorrect
98  * results.
99  *
100  * Retry and backoff policies are honored.
101  */
102  iterator begin();
103 
104  /// End iterator over the rows in the response.
105  iterator end();
106 
107  /**
108  * Gracefully terminate a streaming read.
109  *
110  * Invalidates iterators.
111  */
112  void Cancel();
113 
114  private:
115  friend RowReader bigtable_internal::MakeRowReader(
116  std::shared_ptr<bigtable_internal::RowReaderImpl>);
117  explicit RowReader(std::shared_ptr<bigtable_internal::RowReaderImpl> impl)
118  : impl_(std::move(impl)) {}
119 
120  Options options_ = google::cloud::internal::CurrentOptions();
121  StreamRange<Row> stream_;
122  std::shared_ptr<bigtable_internal::RowReaderImpl> impl_;
123 };
124 
126 } // namespace bigtable
127 namespace bigtable_internal {
129 
130 inline bigtable::RowReader MakeRowReader(std::shared_ptr<RowReaderImpl> impl) {
131  return bigtable::RowReader(std::move(impl));
132 }
133 
135 } // namespace bigtable_internal
136 } // namespace cloud
137 } // namespace google
138 
139 #endif // GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_BIGTABLE_ROW_READER_H