| 3977 | |
| 3978 | template <typename BatchFactory> |
| 3979 | void TestWithBatchFactory(BatchFactory&& factory) { |
| 3980 | std::shared_ptr<RecordBatch> batch; |
| 3981 | struct ArrowArray c_array {}; |
| 3982 | struct ArrowSchema c_schema {}; |
| 3983 | ArrayExportGuard array_guard(&c_array); |
| 3984 | SchemaExportGuard schema_guard(&c_schema); |
| 3985 | |
| 3986 | auto orig_bytes = pool_->bytes_allocated(); |
| 3987 | ASSERT_OK_AND_ASSIGN(batch, ToResult(factory())); |
| 3988 | ASSERT_OK(ExportSchema(*batch->schema(), &c_schema)); |
| 3989 | ASSERT_OK(ExportRecordBatch(*batch, &c_array)); |
| 3990 | |
| 3991 | auto new_bytes = pool_->bytes_allocated(); |
| 3992 | batch.reset(); |
| 3993 | ASSERT_EQ(pool_->bytes_allocated(), new_bytes); |
| 3994 | ASSERT_OK_AND_ASSIGN(batch, ImportRecordBatch(&c_array, &c_schema)); |
| 3995 | ASSERT_OK(batch->ValidateFull()); |
| 3996 | ASSERT_TRUE(ArrowSchemaIsReleased(&c_schema)); |
| 3997 | ASSERT_TRUE(ArrowArrayIsReleased(&c_array)); |
| 3998 | |
| 3999 | // Re-export and re-import, now both at once |
| 4000 | ASSERT_OK(ExportRecordBatch(*batch, &c_array, &c_schema)); |
| 4001 | batch.reset(); |
| 4002 | ASSERT_OK_AND_ASSIGN(batch, ImportRecordBatch(&c_array, &c_schema)); |
| 4003 | ASSERT_OK(batch->ValidateFull()); |
| 4004 | ASSERT_TRUE(ArrowSchemaIsReleased(&c_schema)); |
| 4005 | ASSERT_TRUE(ArrowArrayIsReleased(&c_array)); |
| 4006 | |
| 4007 | // Check value of imported record batch |
| 4008 | { |
| 4009 | std::shared_ptr<RecordBatch> expected; |
| 4010 | ASSERT_OK_AND_ASSIGN(expected, ToResult(factory())); |
| 4011 | AssertSchemaEqual(*expected->schema(), *batch->schema(), /*check_metadata=*/true); |
| 4012 | AssertBatchesEqual(*expected, *batch); |
| 4013 | } |
| 4014 | batch.reset(); |
| 4015 | ASSERT_EQ(pool_->bytes_allocated(), orig_bytes); |
| 4016 | } |
| 4017 | |
| 4018 | void TestWithJSON(std::shared_ptr<DataType> type, const char* json) { |
| 4019 | TestWithArrayFactory(JSONArrayFactory(type, json)); |
nothing calls this directly
no test coverage detected