| 4418 | |
| 4419 | template <typename BatchFactory> |
| 4420 | void TestWithBatchFactory(BatchFactory&& factory) { |
| 4421 | std::shared_ptr<Device> device = std::make_shared<MyDevice>(1); |
| 4422 | auto mm = device->default_memory_manager(); |
| 4423 | |
| 4424 | std::shared_ptr<RecordBatch> batch; |
| 4425 | struct ArrowDeviceArray c_array {}; |
| 4426 | struct ArrowSchema c_schema {}; |
| 4427 | ArrayExportGuard array_guard(&c_array.array); |
| 4428 | SchemaExportGuard schema_guard(&c_schema); |
| 4429 | |
| 4430 | auto orig_bytes = pool_->bytes_allocated(); |
| 4431 | ASSERT_OK_AND_ASSIGN(batch, ToResult(factory())); |
| 4432 | ASSERT_OK(ExportSchema(*batch->schema(), &c_schema)); |
| 4433 | ASSERT_OK_AND_ASSIGN(auto sync, mm->MakeDeviceSyncEvent()); |
| 4434 | ASSERT_OK(ExportDeviceRecordBatch(*batch, sync, &c_array)); |
| 4435 | |
| 4436 | auto new_bytes = pool_->bytes_allocated(); |
| 4437 | batch.reset(); |
| 4438 | ASSERT_EQ(pool_->bytes_allocated(), new_bytes); |
| 4439 | ASSERT_OK_AND_ASSIGN(batch, |
| 4440 | ImportDeviceRecordBatch(&c_array, &c_schema, DeviceMapper)); |
| 4441 | ASSERT_OK(batch->ValidateFull()); |
| 4442 | ASSERT_TRUE(ArrowSchemaIsReleased(&c_schema)); |
| 4443 | ASSERT_TRUE(ArrowArrayIsReleased(&c_array.array)); |
| 4444 | |
| 4445 | // Re-export and re-import, now both at once |
| 4446 | ASSERT_OK(ExportDeviceRecordBatch(*batch, sync, &c_array, &c_schema)); |
| 4447 | batch.reset(); |
| 4448 | ASSERT_OK_AND_ASSIGN(batch, |
| 4449 | ImportDeviceRecordBatch(&c_array, &c_schema, DeviceMapper)); |
| 4450 | ASSERT_OK(batch->ValidateFull()); |
| 4451 | ASSERT_TRUE(ArrowSchemaIsReleased(&c_schema)); |
| 4452 | ASSERT_TRUE(ArrowArrayIsReleased(&c_array.array)); |
| 4453 | |
| 4454 | // Check value of imported record batch |
| 4455 | { |
| 4456 | std::shared_ptr<RecordBatch> expected; |
| 4457 | ASSERT_OK_AND_ASSIGN(expected, ToResult(factory())); |
| 4458 | AssertSchemaEqual(*expected->schema(), *batch->schema(), /*check_metadata=*/true); |
| 4459 | AssertBatchesEqual(*expected, *batch); |
| 4460 | } |
| 4461 | batch.reset(); |
| 4462 | ASSERT_EQ(pool_->bytes_allocated(), orig_bytes); |
| 4463 | } |
| 4464 | |
| 4465 | void TestWithJSON(const std::shared_ptr<MemoryManager>& mm, |
| 4466 | std::shared_ptr<DataType> type, const char* json) { |
nothing calls this directly
no test coverage detected