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