Skip to content

Commit 6676f72

Browse files
authored
feat(bigtable): add support for RowStream (#15587)
* feat(bigtable): add support for RowStream
1 parent 27b7412 commit 6676f72

File tree

4 files changed

+100
-82
lines changed

4 files changed

+100
-82
lines changed

google/cloud/bigtable/query_row.cc

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -66,17 +66,17 @@ bool operator==(QueryRow const& a, QueryRow const& b) {
6666
}
6767

6868
//
69-
// QueryRowStreamIterator
69+
// RowStreamIterator
7070
//
7171

72-
QueryRowStreamIterator::QueryRowStreamIterator() = default;
72+
RowStreamIterator::RowStreamIterator() = default;
7373

74-
QueryRowStreamIterator::QueryRowStreamIterator(Source source)
74+
RowStreamIterator::RowStreamIterator(Source source)
7575
: source_(std::move(source)) {
7676
++*this;
7777
}
7878

79-
QueryRowStreamIterator& QueryRowStreamIterator::operator++() {
79+
RowStreamIterator& RowStreamIterator::operator++() {
8080
if (!row_ok_) {
8181
source_ = nullptr; // Last row was an error; become "end"
8282
return *this;
@@ -90,23 +90,21 @@ QueryRowStreamIterator& QueryRowStreamIterator::operator++() {
9090
return *this;
9191
}
9292

93-
QueryRowStreamIterator QueryRowStreamIterator::operator++(int) {
93+
RowStreamIterator RowStreamIterator::operator++(int) {
9494
auto old = *this;
9595
++*this;
9696
return old;
9797
}
9898

99-
bool operator==(QueryRowStreamIterator const& a,
100-
QueryRowStreamIterator const& b) {
99+
bool operator==(RowStreamIterator const& a, RowStreamIterator const& b) {
101100
// Input iterators may only be compared to (copies of) themselves and end.
102101
// See https://en.cppreference.com/w/cpp/named_req/InputIterator. Therefore,
103102
// by definition, all input iterators are equal unless one is end and the
104103
// other is not.
105104
return !a.source_ == !b.source_;
106105
}
107106

108-
bool operator!=(QueryRowStreamIterator const& a,
109-
QueryRowStreamIterator const& b) {
107+
bool operator!=(RowStreamIterator const& a, RowStreamIterator const& b) {
110108
return !(a == b);
111109
}
112110

google/cloud/bigtable/query_row.h

Lines changed: 19 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -205,11 +205,11 @@ class QueryRow {
205205
};
206206

207207
/**
208-
* A `QueryRowStreamIterator` is an _Input Iterator_ (see below) that returns a
208+
* A `RowStreamIterator` is an _Input Iterator_ (see below) that returns a
209209
* sequence of `StatusOr<QueryRow>` objects.
210210
*
211211
* As an [Input Iterator][input-iterator], the sequence may only be consumed
212-
* once. Default constructing a `QueryRowStreamIterator` creates an instance
212+
* once. Default constructing a `RowStreamIterator` creates an instance
213213
* that represents "end".
214214
*
215215
* @note The term "stream" in this name refers to the general nature
@@ -218,7 +218,7 @@ class QueryRow {
218218
*
219219
* [input-iterator]: https://en.cppreference.com/w/cpp/named_req/InputIterator
220220
*/
221-
class QueryRowStreamIterator {
221+
class RowStreamIterator {
222222
public:
223223
/**
224224
* A function that returns a sequence of `StatusOr<QueryRow>` objects.
@@ -239,27 +239,25 @@ class QueryRowStreamIterator {
239239
///@}
240240

241241
/// Default constructs an "end" iterator.
242-
QueryRowStreamIterator();
242+
RowStreamIterator();
243243

244244
/**
245-
* Constructs a `QueryRowStreamIterator` that will consume rows from the given
245+
* Constructs a `RowStreamIterator` that will consume rows from the given
246246
* @p source, which must not be `nullptr`.
247247
*/
248-
explicit QueryRowStreamIterator(Source source);
248+
explicit RowStreamIterator(Source source);
249249

250250
reference operator*() { return row_; }
251251
pointer operator->() { return &row_; }
252252

253253
const_reference operator*() const { return row_; }
254254
const_pointer operator->() const { return &row_; }
255255

256-
QueryRowStreamIterator& operator++();
257-
QueryRowStreamIterator operator++(int);
256+
RowStreamIterator& operator++();
257+
RowStreamIterator operator++(int);
258258

259-
friend bool operator==(QueryRowStreamIterator const&,
260-
QueryRowStreamIterator const&);
261-
friend bool operator!=(QueryRowStreamIterator const&,
262-
QueryRowStreamIterator const&);
259+
friend bool operator==(RowStreamIterator const&, RowStreamIterator const&);
260+
friend bool operator!=(RowStreamIterator const&, RowStreamIterator const&);
263261

264262
private:
265263
bool row_ok_{true};
@@ -269,7 +267,7 @@ class QueryRowStreamIterator {
269267

270268
/**
271269
* A `TupleStreamIterator<Tuple>` is an "Input Iterator" that wraps a
272-
* `QueryRowStreamIterator`,
270+
* `RowStreamIterator`,
273271
* parsing its elements into a sequence of
274272
* `StatusOr<Tuple>` objects.
275273
*
@@ -278,7 +276,7 @@ class QueryRowStreamIterator {
278276
*
279277
* Default constructing this object creates an instance that represents "end".
280278
*
281-
* Each `QueryRow` returned by the wrapped `QueryRowStreamIterator` must be
279+
* Each `QueryRow` returned by the wrapped `RowStreamIterator` must be
282280
* convertible to the specified `Tuple` template parameter.
283281
*
284282
* @note The term "stream" in this name refers to the general nature
@@ -304,8 +302,8 @@ class TupleStreamIterator {
304302
/// Default constructs an "end" iterator.
305303
TupleStreamIterator() = default;
306304

307-
/// Creates an iterator that wraps the given `QueryRowStreamIterator` range.
308-
TupleStreamIterator(QueryRowStreamIterator begin, QueryRowStreamIterator end)
305+
/// Creates an iterator that wraps the given `RowStreamIterator` range.
306+
TupleStreamIterator(RowStreamIterator begin, RowStreamIterator end)
309307
: it_(std::move(begin)), end_(std::move(end)) {
310308
ParseTuple();
311309
}
@@ -351,13 +349,13 @@ class TupleStreamIterator {
351349

352350
bool tup_ok_{false};
353351
value_type tup_;
354-
QueryRowStreamIterator it_;
355-
QueryRowStreamIterator end_;
352+
RowStreamIterator it_;
353+
RowStreamIterator end_;
356354
};
357355

358356
/**
359357
* A `TupleStream<Tuple>` defines a range that parses `Tuple` objects from the
360-
* given range of `QueryRowStreamIterator`s.
358+
* given range of `RowStreamIterator`s.
361359
*
362360
* Users create instances using the `StreamOf<T>(range)` non-member factory
363361
* function (defined below). The following is a typical usage of this class in
@@ -407,13 +405,13 @@ class TupleStream {
407405
/**
408406
* A factory that creates a `TupleStream<Tuple>` by wrapping the given @p
409407
* range. The `QueryRowRange` must be a range defined by
410-
* `QueryRowStreamIterator` objects.
408+
* `RowStreamIterator` objects.
411409
*
412410
*
413411
* @note Ownership of the @p range is not transferred, so it must outlive the
414412
* returned `TupleStream`.
415413
*
416-
* @tparam QueryRowRange must be a range defined by `QueryRowStreamIterator`s.
414+
* @tparam QueryRowRange must be a range defined by `RowStreamIterator`s.
417415
*/
418416
template <typename Tuple, typename QueryRowRange>
419417
TupleStream<Tuple> StreamOf(QueryRowRange&& range) {

0 commit comments

Comments
 (0)