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

Function FlattenSparseUnionArray

cpp/src/arrow/adapters/orc/adapter_test.cc:1052–1062  ·  view source on GitHub ↗

The random array generator fills random unselected values in the child arrays of SparseUnionArray. However, orc file only contains dense union type meaning that these unselected values will not be written to the file (so we can never read them back and compare equality in the unit test). Because the orc reader fills unselected values to nulls when reading from the file. So flattening the SparseUni

Source from the content-addressed store, hash-verified

1050// fills unselected values to nulls when reading from the file. So flattening
1051// the SparseUnionArray before writing makes it easy for the array equality check.
1052std::shared_ptr<Array> FlattenSparseUnionArray(std::shared_ptr<Array> array) {
1053 auto union_array = checked_pointer_cast<SparseUnionArray>(array);
1054 ArrayVector children;
1055 for (int i = 0; i < array->num_fields(); ++i) {
1056 ASSIGN_OR_ABORT(auto flattened_child, union_array->GetFlattenedField(i));
1057 children.emplace_back(std::move(flattened_child));
1058 }
1059 return std::make_shared<SparseUnionArray>(array->type(), array->length(),
1060 std::move(children),
1061 union_array->type_codes(), array->offset());
1062}
1063
1064void TestUnionConversion(std::shared_ptr<Array> array) {
1065 auto length = array->length();

Callers 2

TEST_FFunction · 0.85
TESTFunction · 0.85

Calls 5

emplace_backMethod · 0.80
num_fieldsMethod · 0.45
typeMethod · 0.45
lengthMethod · 0.45
offsetMethod · 0.45

Tested by

no test coverage detected