| 793 | } |
| 794 | |
| 795 | Status ExportDeviceRecordBatch(const RecordBatch& batch, |
| 796 | std::shared_ptr<Device::SyncEvent> sync, |
| 797 | struct ArrowDeviceArray* out, |
| 798 | struct ArrowSchema* out_schema) { |
| 799 | void* sync_event{nullptr}; |
| 800 | if (sync) { |
| 801 | sync_event = sync->get_raw(); |
| 802 | } |
| 803 | |
| 804 | // XXX perhaps bypass ToStructArray for speed? |
| 805 | ARROW_ASSIGN_OR_RAISE(auto array, batch.ToStructArray()); |
| 806 | |
| 807 | SchemaExportGuard guard(out_schema); |
| 808 | if (out_schema != nullptr) { |
| 809 | // Export the schema, not the struct type, so as not to lose top-level metadata |
| 810 | RETURN_NOT_OK(ExportSchema(*batch.schema(), out_schema)); |
| 811 | } |
| 812 | |
| 813 | ARROW_ASSIGN_OR_RAISE(auto device_info, ValidateDeviceInfo(*array->data())); |
| 814 | if (!device_info.first) { |
| 815 | out->device_type = ARROW_DEVICE_CPU; |
| 816 | } else { |
| 817 | out->device_type = static_cast<ArrowDeviceType>(*device_info.first); |
| 818 | } |
| 819 | out->device_id = device_info.second; |
| 820 | |
| 821 | ArrayExporter exporter(/*device_interface*/ true); |
| 822 | RETURN_NOT_OK(exporter.Export(array->data())); |
| 823 | exporter.Finish(&out->array); |
| 824 | |
| 825 | auto* pdata = reinterpret_cast<ExportedArrayPrivateData*>(out->array.private_data); |
| 826 | pdata->sync_ = std::move(sync); |
| 827 | out->sync_event = sync_event; |
| 828 | |
| 829 | guard.Detach(); |
| 830 | return Status::OK(); |
| 831 | } |
| 832 | |
| 833 | ////////////////////////////////////////////////////////////////////////// |
| 834 | // C schema import |