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