This is an automated email from the ASF dual-hosted git repository.
lidavidm pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/arrow.git
The following commit(s) were added to refs/heads/master by this push:
new c1af787219 ARROW-17310: [C++] Expose RBR:Make() from Iterator<RB>
(#13798)
c1af787219 is described below
commit c1af787219088f659224b2cfa594775cee3be561
Author: Will Jones <[email protected]>
AuthorDate: Fri Aug 5 10:41:13 2022 -0700
ARROW-17310: [C++] Expose RBR:Make() from Iterator<RB> (#13798)
Authored-by: Will Jones <[email protected]>
Signed-off-by: David Li <[email protected]>
---
cpp/src/arrow/record_batch.cc | 9 +++++++++
cpp/src/arrow/record_batch.h | 8 ++++++++
2 files changed, 17 insertions(+)
diff --git a/cpp/src/arrow/record_batch.cc b/cpp/src/arrow/record_batch.cc
index ba9a843690..9001a57798 100644
--- a/cpp/src/arrow/record_batch.cc
+++ b/cpp/src/arrow/record_batch.cc
@@ -390,6 +390,15 @@ Result<std::shared_ptr<RecordBatchReader>>
RecordBatchReader::Make(
return std::make_shared<SimpleRecordBatchReader>(std::move(batches), schema);
}
+Result<std::shared_ptr<RecordBatchReader>> RecordBatchReader::MakeFromIterator(
+ Iterator<std::shared_ptr<RecordBatch>> batches, std::shared_ptr<Schema>
schema) {
+ if (schema == nullptr) {
+ return Status::Invalid("Schema cannot be nullptr");
+ }
+
+ return std::make_shared<SimpleRecordBatchReader>(std::move(batches), schema);
+}
+
RecordBatchReader::~RecordBatchReader() {
ARROW_WARN_NOT_OK(this->Close(), "Implicitly called RecordBatchReader::Close
failed");
}
diff --git a/cpp/src/arrow/record_batch.h b/cpp/src/arrow/record_batch.h
index b80c36d78c..8bc7032256 100644
--- a/cpp/src/arrow/record_batch.h
+++ b/cpp/src/arrow/record_batch.h
@@ -25,6 +25,7 @@
#include "arrow/result.h"
#include "arrow/status.h"
#include "arrow/type_fwd.h"
+#include "arrow/util/iterator.h"
#include "arrow/util/macros.h"
#include "arrow/util/visibility.h"
@@ -327,6 +328,13 @@ class ARROW_EXPORT RecordBatchReader {
/// element if not provided.
static Result<std::shared_ptr<RecordBatchReader>> Make(
RecordBatchVector batches, std::shared_ptr<Schema> schema = NULLPTR);
+
+ /// \brief Create a RecordBatchReader from an Iterator of RecordBatch.
+ ///
+ /// \param[in] batches an iterator of RecordBatch to read from.
+ /// \param[in] schema schema that each record batch in iterator will conform
to.
+ static Result<std::shared_ptr<RecordBatchReader>> MakeFromIterator(
+ Iterator<std::shared_ptr<RecordBatch>> batches, std::shared_ptr<Schema>
schema);
};
} // namespace arrow