nealrichardson commented on a change in pull request #12533:
URL: https://github.com/apache/arrow/pull/12533#discussion_r818243975



##########
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:
       How so? The tests don't show that; is there an additional test you'd 
like to see?
   
   FWIW this is adapted from the Scanner::Head method 
[here](https://github.com/apache/arrow/blob/master/cpp/src/arrow/dataset/scanner.cc#L465-L479)




-- 
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]


Reply via email to