paleolimbot commented on a change in pull request #12533:
URL: https://github.com/apache/arrow/pull/12533#discussion_r818222944
##########
File path: r/src/recordbatchreader.cpp
##########
@@ -51,6 +51,20 @@ std::shared_ptr<arrow::Table> Table__from_RecordBatchReader(
return table;
}
+// [[arrow::export]]
+std::shared_ptr<arrow::Table> RecordBatchReader__Head(
+ const std::shared_ptr<arrow::RecordBatchReader>& reader, int64_t num_rows)
{
+ std::vector<std::shared_ptr<arrow::RecordBatch>> batches;
+ std::shared_ptr<arrow::RecordBatch> this_batch;
+ while (num_rows > 0) {
+ this_batch = ValueOrStop(reader->Next());
+ if (this_batch == nullptr) break;
+ batches.push_back(this_batch->Slice(0, num_rows));
+ num_rows -= this_batch->num_rows();
+ }
+ return ValueOrStop(arrow::Table::FromRecordBatches(reader->schema(),
batches));
+}
Review comment:
My reading of this is that it may give more rows than `num_rows`...is
that the intention? I get that it's awkward because the record batch reader is
mutable (as Jon noted below).
--
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]