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

Method Make

cpp/src/arrow/field_ref_test.cc:117–203  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

115 }
116
117 static Result<FieldPathTestCase> Make() {
118 // Generate test input based on a single schema. First by creating a StructArray,
119 // then deriving the other input types (ChunkedArray, RecordBatch, Table, etc) from
120 // it. We also compute the expected outputs for each child individually (for each
121 // output type).
122 FieldPathTestCase out;
123 random::RandomArrayGenerator gen(kRandomSeed);
124
125 // Define child fields and input schema
126
127 // Intentionally duplicated names for the FieldRef tests
128 out.v1_1_1.field = field("a", boolean());
129 out.v1_1_0.field = field("a", float32());
130
131 out.v1_1.field = field("b", struct_({out.v1_1_0.field, out.v1_1_1.field}));
132 out.v1_0.field = field("a", int32());
133 out.v1.field = field("b", struct_({out.v1_0.field, out.v1_1.field}));
134 out.v0.field = field("a", utf8());
135 out.schema = arrow::schema({out.v0.field, out.v1.field});
136 out.type = struct_(out.schema->fields());
137
138 // Create null bitmaps for the struct fields independent of its children's
139 // bitmaps. For FieldPath::GetFlattened, parent/child bitmaps should be combined
140 // - for FieldPath::Get, higher-level nulls are ignored.
141 auto bitmap1_1 = gen.NullBitmap(kNumRows, 0.15);
142 auto bitmap1 = gen.NullBitmap(kNumRows, 0.30);
143
144 // Generate raw leaf arrays
145 out.v1_1_1.array = gen.ArrayOf(out.v1_1_1.field->type(), kNumRows);
146 out.v1_1_0.array = gen.ArrayOf(out.v1_1_0.field->type(), kNumRows);
147 out.v1_0.array = gen.ArrayOf(out.v1_0.field->type(), kNumRows);
148 out.v0.array = gen.ArrayOf(out.v0.field->type(), kNumRows);
149 // Make struct fields from leaf arrays (we use the custom bitmaps here)
150 ARROW_ASSIGN_OR_RAISE(
151 out.v1_1.array,
152 StructArray::Make({out.v1_1_0.array, out.v1_1_1.array},
153 {out.v1_1_0.field, out.v1_1_1.field}, bitmap1_1));
154 ARROW_ASSIGN_OR_RAISE(out.v1.array,
155 StructArray::Make({out.v1_0.array, out.v1_1.array},
156 {out.v1_0.field, out.v1_1.field}, bitmap1));
157
158 // Not used to create the test input, but pre-compute flattened versions of nested
159 // arrays for comparisons in the GetFlattened tests.
160 ARROW_ASSIGN_OR_RAISE(
161 out.v1_0_flat.array,
162 checked_pointer_cast<StructArray>(out.v1.array)->GetFlattenedField(0));
163 ARROW_ASSIGN_OR_RAISE(
164 out.v1_1_flat.array,
165 checked_pointer_cast<StructArray>(out.v1.array)->GetFlattenedField(1));
166 ARROW_ASSIGN_OR_RAISE(
167 out.v1_1_0_flat.array,
168 checked_pointer_cast<StructArray>(out.v1_1_flat.array)->GetFlattenedField(0));
169 ARROW_ASSIGN_OR_RAISE(
170 out.v1_1_1_flat.array,
171 checked_pointer_cast<StructArray>(out.v1_1_flat.array)->GetFlattenedField(1));
172 // Sanity check
173 ARROW_CHECK(!out.v1_0_flat.array->Equals(out.v1_0.array));
174 ARROW_CHECK(!out.v1_1_flat.array->Equals(out.v1_1.array));

Callers

nothing calls this directly

Calls 12

struct_Function · 0.85
NullBitmapMethod · 0.80
GetFlattenedFieldMethod · 0.80
fieldFunction · 0.70
schemaFunction · 0.70
MakeFunction · 0.70
ARROW_ASSIGN_OR_RAISEFunction · 0.50
fieldsMethod · 0.45
ArrayOfMethod · 0.45
typeMethod · 0.45
EqualsMethod · 0.45
ValidateFullMethod · 0.45

Tested by

no test coverage detected