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

Function TEST_F

cpp/src/arrow/table_builder_test.cc:82–138  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

80}
81
82TEST_F(TestRecordBatchBuilder, Basics) {
83 auto schema = ExampleSchema1();
84
85 std::unique_ptr<RecordBatchBuilder> builder;
86 ASSERT_OK_AND_ASSIGN(builder, RecordBatchBuilder::Make(schema, pool_));
87
88 std::vector<bool> is_valid = {false, true, true, true};
89 std::vector<int32_t> f0_values = {0, 1, 2, 3};
90 std::vector<std::string> f1_values = {"a", "bb", "ccc", "dddd"};
91 std::vector<std::vector<int8_t>> f2_values = {{}, {0, 1}, {}, {2}};
92
93 std::shared_ptr<Array> a0, a1, a2;
94
95 // Make the expected record batch
96 auto AppendData = [&](Int32Builder* b0, StringBuilder* b1, ListBuilder* b2) {
97 AppendValues<Int32Builder, int32_t>(b0, f0_values, is_valid);
98 AppendValues<StringBuilder, std::string>(b1, f1_values, is_valid);
99 AppendList<Int8Builder, int8_t>(b2, f2_values, is_valid);
100 };
101
102 Int32Builder ex_b0;
103 StringBuilder ex_b1;
104 ListBuilder ex_b2(pool_, std::make_unique<Int8Builder>(pool_));
105
106 AppendData(&ex_b0, &ex_b1, &ex_b2);
107 ASSERT_OK(ex_b0.Finish(&a0));
108 ASSERT_OK(ex_b1.Finish(&a1));
109 ASSERT_OK(ex_b2.Finish(&a2));
110
111 auto expected = RecordBatch::Make(schema, 4, {a0, a1, a2});
112
113 // Builder attributes
114 ASSERT_EQ(3, builder->num_fields());
115 ASSERT_EQ(schema.get(), builder->schema().get());
116
117 const int kIter = 3;
118 for (int i = 0; i < kIter; ++i) {
119 AppendData(builder->GetFieldAs<Int32Builder>(0),
120 checked_cast<StringBuilder*>(builder->GetField(1)),
121 builder->GetFieldAs<ListBuilder>(2));
122
123 std::shared_ptr<RecordBatch> batch;
124
125 if (i == kIter - 1) {
126 // Do not flush in last iteration
127 ASSERT_OK_AND_ASSIGN(batch, builder->Flush(false));
128 } else {
129 ASSERT_OK_AND_ASSIGN(batch, builder->Flush());
130 }
131
132 ASSERT_BATCHES_EQUAL(*expected, *batch);
133 }
134
135 // Test setting initial capacity
136 builder->SetInitialCapacity(4096);
137 ASSERT_EQ(4096, builder->initial_capacity());
138}
139

Callers

nothing calls this directly

Calls 15

ExampleSchema1Function · 0.85
to_stringFunction · 0.85
SetInitialCapacityMethod · 0.80
push_backMethod · 0.80
ASSERT_OK_AND_ASSIGNFunction · 0.70
MakeFunction · 0.70
fieldFunction · 0.70
dictionaryFunction · 0.70
schemaFunction · 0.70
FinishMethod · 0.45
num_fieldsMethod · 0.45
getMethod · 0.45

Tested by

no test coverage detected