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

Method Flatten

cpp/src/arrow/chunked_array.cc:218–243  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

216}
217
218Result<std::vector<std::shared_ptr<ChunkedArray>>> ChunkedArray::Flatten(
219 MemoryPool* pool) const {
220 if (type()->id() != Type::STRUCT) {
221 // Emulate nonexistent copy constructor
222 return std::vector<std::shared_ptr<ChunkedArray>>{
223 std::make_shared<ChunkedArray>(chunks_, type_)};
224 }
225
226 std::vector<ArrayVector> flattened_chunks(type()->num_fields());
227 for (const auto& chunk : chunks_) {
228 ARROW_ASSIGN_OR_RAISE(auto arrays,
229 checked_cast<const StructArray&>(*chunk).Flatten(pool));
230 DCHECK_EQ(arrays.size(), flattened_chunks.size());
231 for (size_t i = 0; i < arrays.size(); ++i) {
232 flattened_chunks[i].push_back(arrays[i]);
233 }
234 }
235
236 std::vector<std::shared_ptr<ChunkedArray>> flattened(type()->num_fields());
237 for (size_t i = 0; i < flattened.size(); ++i) {
238 auto child_type = type()->field(static_cast<int>(i))->type();
239 flattened[i] =
240 std::make_shared<ChunkedArray>(std::move(flattened_chunks[i]), child_type);
241 }
242 return flattened;
243}
244
245Result<std::shared_ptr<ChunkedArray>> ChunkedArray::View(
246 const std::shared_ptr<DataType>& type) const {

Callers

nothing calls this directly

Calls 7

push_backMethod · 0.80
typeFunction · 0.70
idMethod · 0.45
num_fieldsMethod · 0.45
sizeMethod · 0.45
typeMethod · 0.45
fieldMethod · 0.45

Tested by

no test coverage detected