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