MCPcopy Create free account
hub / github.com/apache/arrow / TestWithBatchFactory

Method TestWithBatchFactory

cpp/src/arrow/c/bridge_test.cc:3971–4008  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

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));

Callers

nothing calls this directly

Calls 13

ToResultFunction · 0.85
factoryFunction · 0.85
ArrowSchemaIsReleasedFunction · 0.85
ArrowArrayIsReleasedFunction · 0.85
AssertBatchesEqualFunction · 0.85
ASSERT_OK_AND_ASSIGNFunction · 0.70
ExportSchemaFunction · 0.70
ExportRecordBatchFunction · 0.70
ImportRecordBatchFunction · 0.70
bytes_allocatedMethod · 0.45
schemaMethod · 0.45
resetMethod · 0.45

Tested by

no test coverage detected