diff --git a/cpp/src/arrow/record_batch.cc b/cpp/src/arrow/record_batch.cc index bb2e702727e25..e8fca4bb2b609 100644 --- a/cpp/src/arrow/record_batch.cc +++ b/cpp/src/arrow/record_batch.cc @@ -390,4 +390,13 @@ Result> RecordBatchReader::Make( return std::make_shared(std::move(batches), schema); } +Result> RecordBatchReader::Make( + Iterator> it, std::shared_ptr schema) { + if (schema == nullptr) { + return Status::Invalid("Cannot infer schema from nullptr"); + } + + return std::make_shared(std::move(it), schema); +} + } // namespace arrow diff --git a/cpp/src/arrow/record_batch.h b/cpp/src/arrow/record_batch.h index 60aa9ad9c9415..561a80d3d58c1 100644 --- a/cpp/src/arrow/record_batch.h +++ b/cpp/src/arrow/record_batch.h @@ -324,6 +324,13 @@ class ARROW_EXPORT RecordBatchReader { /// element if not provided. static Result> Make( RecordBatchVector batches, std::shared_ptr schema = NULLPTR); + + /// \brief Create a RecordBatchReader from an iterator of RecordBatch. + /// + /// \param[in] iterator of RecordBatch to read from + /// \param[in] schema schema to conform to. A valid schema should be provided. + static Result> Make( + Iterator> it, std::shared_ptr schema); }; } // namespace arrow