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