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