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

Function TEST_F

cpp/src/arrow/array/array_union_test.cc:249–324  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

247};
248
249TEST_F(TestUnionArrayFactories, TestMakeDense) {
250 std::shared_ptr<Array> value_offsets;
251 // type_ids_: {0, 1, 2, 0, 1, 3, 2, 0, 2, 1}
252 ArrayFromVector<Int32Type, int32_t>({0, 0, 0, 1, 1, 0, 1, 2, 1, 2}, &value_offsets);
253
254 auto children = std::vector<std::shared_ptr<Array>>(4);
255 ArrayFromVector<StringType, std::string>({"abc", "def", "xyz"}, &children[0]);
256 ArrayFromVector<UInt8Type>({10, 20, 30}, &children[1]);
257 ArrayFromVector<DoubleType>({1.618, 2.718, 3.142}, &children[2]);
258 ArrayFromVector<Int8Type>({-12}, &children[3]);
259
260 std::vector<std::string> field_names = {"str", "int1", "real", "int2"};
261
262 std::shared_ptr<Array> result;
263 const UnionArray* union_array;
264
265 // without field names and type codes
266 ASSERT_OK_AND_ASSIGN(result,
267 DenseUnionArray::Make(*type_ids_, *value_offsets, children));
268 ASSERT_OK(result->ValidateFull());
269 union_array = checked_cast<const UnionArray*>(result.get());
270 CheckUnionArray(*union_array, UnionMode::DENSE, {"0", "1", "2", "3"}, {0, 1, 2, 3});
271
272 // with field name
273 ASSERT_RAISES(Invalid,
274 DenseUnionArray::Make(*type_ids_, *value_offsets, children, {"one"}));
275 ASSERT_OK_AND_ASSIGN(
276 result, DenseUnionArray::Make(*type_ids_, *value_offsets, children, field_names));
277 ASSERT_OK(result->ValidateFull());
278 union_array = checked_cast<const UnionArray*>(result.get());
279 CheckUnionArray(*union_array, UnionMode::DENSE, field_names, {0, 1, 2, 3});
280
281 // with type codes
282 ASSERT_RAISES(Invalid, DenseUnionArray::Make(*logical_type_ids_, *value_offsets,
283 children, std::vector<int8_t>{0}));
284 ASSERT_OK_AND_ASSIGN(result, DenseUnionArray::Make(*logical_type_ids_, *value_offsets,
285 children, type_codes_));
286 ASSERT_OK(result->ValidateFull());
287 union_array = checked_cast<const UnionArray*>(result.get());
288 CheckUnionArray(*union_array, UnionMode::DENSE, {"0", "1", "2", "3"}, type_codes_);
289
290 // with field names and type codes
291 ASSERT_RAISES(Invalid, DenseUnionArray::Make(*logical_type_ids_, *value_offsets,
292 children, {"one"}, type_codes_));
293 ASSERT_OK_AND_ASSIGN(result, DenseUnionArray::Make(*logical_type_ids_, *value_offsets,
294 children, field_names, type_codes_));
295 ASSERT_OK(result->ValidateFull());
296 union_array = checked_cast<const UnionArray*>(result.get());
297 CheckUnionArray(*union_array, UnionMode::DENSE, field_names, type_codes_);
298
299 // Invalid type codes
300 ASSERT_OK_AND_ASSIGN(result, DenseUnionArray::Make(*invalid_type_ids1_, *value_offsets,
301 children, type_codes_));
302 ASSERT_RAISES(Invalid, result->ValidateFull());
303 ASSERT_OK_AND_ASSIGN(result, DenseUnionArray::Make(*invalid_type_ids2_, *value_offsets,
304 children, type_codes_));
305 ASSERT_RAISES(Invalid, result->ValidateFull());
306

Callers 1

ASSERT_OK_AND_ASSIGNFunction · 0.70

Calls 4

ASSERT_OK_AND_ASSIGNFunction · 0.70
MakeFunction · 0.70
ValidateFullMethod · 0.45
getMethod · 0.45

Tested by

no test coverage detected