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

Method TestWithBatchFactory

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

Source from the content-addressed store, hash-verified

3910
3911 template <typename BatchFactory>
3912 void TestWithBatchFactory(BatchFactory&& factory) {
3913 std::shared_ptr<RecordBatch> batch;
3914 struct ArrowArray c_array {};
3915 struct ArrowSchema c_schema {};
3916 ArrayExportGuard array_guard(&c_array);
3917 SchemaExportGuard schema_guard(&c_schema);
3918
3919 auto orig_bytes = pool_->bytes_allocated();
3920 ASSERT_OK_AND_ASSIGN(batch, ToResult(factory()));
3921 ASSERT_OK(ExportSchema(*batch->schema(), &c_schema));
3922 ASSERT_OK(ExportRecordBatch(*batch, &c_array));
3923
3924 auto new_bytes = pool_->bytes_allocated();
3925 batch.reset();
3926 ASSERT_EQ(pool_->bytes_allocated(), new_bytes);
3927 ASSERT_OK_AND_ASSIGN(batch, ImportRecordBatch(&c_array, &c_schema));
3928 ASSERT_OK(batch->ValidateFull());
3929 ASSERT_TRUE(ArrowSchemaIsReleased(&c_schema));
3930 ASSERT_TRUE(ArrowArrayIsReleased(&c_array));
3931
3932 // Re-export and re-import, now both at once
3933 ASSERT_OK(ExportRecordBatch(*batch, &c_array, &c_schema));
3934 batch.reset();
3935 ASSERT_OK_AND_ASSIGN(batch, ImportRecordBatch(&c_array, &c_schema));
3936 ASSERT_OK(batch->ValidateFull());
3937 ASSERT_TRUE(ArrowSchemaIsReleased(&c_schema));
3938 ASSERT_TRUE(ArrowArrayIsReleased(&c_array));
3939
3940 // Check value of imported record batch
3941 {
3942 std::shared_ptr<RecordBatch> expected;
3943 ASSERT_OK_AND_ASSIGN(expected, ToResult(factory()));
3944 AssertSchemaEqual(*expected->schema(), *batch->schema(), /*check_metadata=*/true);
3945 AssertBatchesEqual(*expected, *batch);
3946 }
3947 batch.reset();
3948 ASSERT_EQ(pool_->bytes_allocated(), orig_bytes);
3949 }
3950
3951 void TestWithJSON(std::shared_ptr<DataType> type, const char* json) {
3952 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