pitrou commented on a change in pull request #11946:
URL: https://github.com/apache/arrow/pull/11946#discussion_r782143512
##########
File path: cpp/src/arrow/record_batch.h
##########
@@ -234,6 +234,68 @@ class ARROW_EXPORT RecordBatchReader {
return batch;
}
+ class RecordBatchReaderIterator {
+ public:
+ using iterator_category = std::input_iterator_tag;
+ using difference_type = std::ptrdiff_t;
+ using value_type = std::shared_ptr<RecordBatch>;
+ using pointer = value_type const*;
+ using reference = value_type const&;
+
+ RecordBatchReaderIterator() : batch_(RecordBatchEnd()), reader_(NULLPTR) {}
+
+ explicit RecordBatchReaderIterator(RecordBatchReader* reader)
+ : batch_(RecordBatchEnd()), reader_(reader) {
+ Next();
+ }
+
+ bool operator==(const RecordBatchReaderIterator& other) const {
+ return batch_ == other.batch_;
+ }
+
+ bool operator!=(const RecordBatchReaderIterator& other) const {
+ return !(*this == other);
+ }
+
+ Result<std::shared_ptr<RecordBatch>> operator*() {
+ ARROW_RETURN_NOT_OK(batch_.status());
+
+ return batch_;
+ }
+
+ RecordBatchReaderIterator& operator++() {
+ Next();
+ return *this;
+ }
+
+ RecordBatchReaderIterator operator++(int) {
+ RecordBatchReaderIterator tmp(*this);
+ Next();
+ return tmp;
+ }
+
+ private:
+ std::shared_ptr<RecordBatch> RecordBatchEnd() {
+ return std::shared_ptr<RecordBatch>(NULLPTR);
+ }
+
+ void Next() {
+ if (reader_ == NULLPTR) {
+ batch_ = RecordBatchEnd();
+ return;
+ }
+ batch_ = reader_->Next();
+ }
+
+ Result<std::shared_ptr<RecordBatch>> batch_;
+ RecordBatchReader* reader_;
+ };
+ /// \brief Returns an iterator to the first record batch in the stream
+ RecordBatchReaderIterator begin() { return RecordBatchReaderIterator(this); }
Review comment:
It's ok, however please use "Return" (infinitive) not "Returns" (present
tense).
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]