bkietz commented on code in PR #44495:
URL: https://github.com/apache/arrow/pull/44495#discussion_r1837058002
##########
cpp/src/arrow/c/bridge.cc:
##########
@@ -2511,4 +2516,347 @@ Result<std::shared_ptr<ChunkedArray>>
ImportDeviceChunkedArray(
return ImportChunked</*IsDevice=*/true>(stream, mapper);
}
+namespace {
+
+class AsyncRecordBatchIterator {
+ public:
+ struct TaskWithMetadata {
+ ArrowAsyncTask task_;
+ std::shared_ptr<KeyValueMetadata> metadata_;
+ };
+
+ struct State {
+ State(uint64_t queue_size, DeviceMemoryMapper mapper)
+ : queue_size_{queue_size}, mapper_{std::move(mapper)} {}
+
+ Result<RecordBatchWithMetadata> next() {
+ TaskWithMetadata task;
+ {
+ std::unique_lock<std::mutex> lock(mutex_);
+ cv_.wait(lock,
+ [&] { return !error_.ok() || !batches_.empty() ||
end_of_stream_; });
+ if (!error_.ok()) {
+ return error_;
+ }
+
+ if (batches_.empty() && end_of_stream_) {
+ return IterationEnd<RecordBatchWithMetadata>();
+ }
+
+ task = std::move(batches_.front());
+ batches_.pop();
+ }
+
+ producer_->request(producer_, 1);
+ ArrowDeviceArray out;
+ if (task.task_.extract_data(&task.task_, &out) != 0) {
+ std::unique_lock<std::mutex> lock(mutex_);
+ cv_.wait(lock, [&] { return !error_.ok(); });
+ return error_;
+ }
+
+ ARROW_ASSIGN_OR_RAISE(auto batch, ImportDeviceRecordBatch(&out, schema_,
mapper_));
+ return RecordBatchWithMetadata{std::move(batch),
std::move(task.metadata_)};
+ }
+
+ const uint64_t queue_size_;
+ const DeviceMemoryMapper mapper_;
+ ArrowAsyncProducer* producer_;
+ DeviceAllocationType device_type_;
+
+ std::mutex mutex_;
+ std::shared_ptr<Schema> schema_;
+ std::condition_variable cv_;
+ std::queue<TaskWithMetadata> batches_;
+ bool end_of_stream_ = false;
+ Status error_{Status::OK()};
+ };
+
+ AsyncRecordBatchIterator(uint64_t queue_size, const DeviceMemoryMapper
mapper)
Review Comment:
This one must've missed the batch
```suggestion
AsyncRecordBatchIterator(uint64_t queue_size, DeviceMemoryMapper mapper)
```
--
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]