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

Function TEST_F

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

Source from the content-addressed store, hash-verified

292};
293
294TEST_F(TestUnionArrayFactories, TestMakeDense) {
295 std::shared_ptr<Array> value_offsets;
296 // type_ids_: {0, 1, 2, 0, 1, 3, 2, 0, 2, 1}
297 ArrayFromVector<Int32Type, int32_t>({0, 0, 0, 1, 1, 0, 1, 2, 1, 2}, &value_offsets);
298
299 auto children = std::vector<std::shared_ptr<Array>>(4);
300 ArrayFromVector<StringType, std::string>({"abc", "def", "xyz"}, &children[0]);
301 ArrayFromVector<UInt8Type>({10, 20, 30}, &children[1]);
302 ArrayFromVector<DoubleType>({1.618, 2.718, 3.142}, &children[2]);
303 ArrayFromVector<Int8Type>({-12}, &children[3]);
304
305 std::vector<std::string> field_names = {"str", "int1", "real", "int2"};
306
307 std::shared_ptr<Array> result;
308 const UnionArray* union_array;
309
310 // without field names and type codes
311 ASSERT_OK_AND_ASSIGN(result,
312 DenseUnionArray::Make(*type_ids_, *value_offsets, children));
313 ASSERT_OK(result->ValidateFull());
314 union_array = checked_cast<const UnionArray*>(result.get());
315 CheckUnionArray(*union_array, UnionMode::DENSE, {"0", "1", "2", "3"}, {0, 1, 2, 3});
316
317 // with field name
318 ASSERT_RAISES(Invalid,
319 DenseUnionArray::Make(*type_ids_, *value_offsets, children, {"one"}));
320 ASSERT_OK_AND_ASSIGN(
321 result, DenseUnionArray::Make(*type_ids_, *value_offsets, children, field_names));
322 ASSERT_OK(result->ValidateFull());
323 union_array = checked_cast<const UnionArray*>(result.get());
324 CheckUnionArray(*union_array, UnionMode::DENSE, field_names, {0, 1, 2, 3});
325
326 // with type codes
327 ASSERT_RAISES(Invalid, DenseUnionArray::Make(*logical_type_ids_, *value_offsets,
328 children, std::vector<int8_t>{0}));
329 ASSERT_OK_AND_ASSIGN(result, DenseUnionArray::Make(*logical_type_ids_, *value_offsets,
330 children, type_codes_));
331 ASSERT_OK(result->ValidateFull());
332 union_array = checked_cast<const UnionArray*>(result.get());
333 CheckUnionArray(*union_array, UnionMode::DENSE, {"0", "1", "2", "3"}, type_codes_);
334
335 // with field names and type codes
336 ASSERT_RAISES(Invalid, DenseUnionArray::Make(*logical_type_ids_, *value_offsets,
337 children, {"one"}, type_codes_));
338 ASSERT_OK_AND_ASSIGN(result, DenseUnionArray::Make(*logical_type_ids_, *value_offsets,
339 children, field_names, type_codes_));
340 ASSERT_OK(result->ValidateFull());
341 union_array = checked_cast<const UnionArray*>(result.get());
342 CheckUnionArray(*union_array, UnionMode::DENSE, field_names, type_codes_);
343
344 // Invalid type codes
345 ASSERT_OK_AND_ASSIGN(result, DenseUnionArray::Make(*invalid_type_ids1_, *value_offsets,
346 children, type_codes_));
347 ASSERT_RAISES(Invalid, result->ValidateFull());
348 ASSERT_OK_AND_ASSIGN(result, DenseUnionArray::Make(*invalid_type_ids2_, *value_offsets,
349 children, type_codes_));
350 ASSERT_RAISES(Invalid, result->ValidateFull());
351

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