| 2827 | } |
| 2828 | |
| 2829 | Future<> ExportAsyncRecordBatchReader( |
| 2830 | std::shared_ptr<Schema> schema, |
| 2831 | AsyncGenerator<std::shared_ptr<RecordBatch>> generator, |
| 2832 | DeviceAllocationType device_type, struct ArrowAsyncDeviceStreamHandler* handler) { |
| 2833 | if (!schema) { |
| 2834 | handler->on_error(handler, EINVAL, "Schema is null", nullptr); |
| 2835 | handler->release(handler); |
| 2836 | return Future<>::MakeFinished(Status::Invalid("Schema is null")); |
| 2837 | } |
| 2838 | |
| 2839 | struct ArrowSchema c_schema; |
| 2840 | SchemaExportGuard guard(&c_schema); |
| 2841 | |
| 2842 | auto status = ExportSchema(*schema, &c_schema); |
| 2843 | if (!status.ok()) { |
| 2844 | handler->on_error(handler, EINVAL, status.message().c_str(), nullptr); |
| 2845 | handler->release(handler); |
| 2846 | return Future<>::MakeFinished(status); |
| 2847 | } |
| 2848 | |
| 2849 | return VisitAsyncGenerator(generator, AsyncProducer{device_type, &c_schema, handler}) |
| 2850 | .Then( |
| 2851 | [handler]() -> Status { |
| 2852 | int status = handler->on_next_task(handler, nullptr, nullptr); |
| 2853 | handler->release(handler); |
| 2854 | if (status != 0) { |
| 2855 | return Status::UnknownError("Received error from handler::on_next_task ", |
| 2856 | status); |
| 2857 | } |
| 2858 | return Status::OK(); |
| 2859 | }, |
| 2860 | [handler](const Status status) -> Status { |
| 2861 | handler->on_error(handler, EINVAL, status.message().c_str(), nullptr); |
| 2862 | handler->release(handler); |
| 2863 | return status; |
| 2864 | }); |
| 2865 | } |
| 2866 | |
| 2867 | } // namespace arrow |