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

Method Flatten

cpp/src/arrow/chunked_array.cc:206–231  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

204}
205
206Result<std::vector<std::shared_ptr<ChunkedArray>>> ChunkedArray::Flatten(
207 MemoryPool* pool) const {
208 if (type()->id() != Type::STRUCT) {
209 // Emulate nonexistent copy constructor
210 return std::vector<std::shared_ptr<ChunkedArray>>{
211 std::make_shared<ChunkedArray>(chunks_, type_)};
212 }
213
214 std::vector<ArrayVector> flattened_chunks(type()->num_fields());
215 for (const auto& chunk : chunks_) {
216 ARROW_ASSIGN_OR_RAISE(auto arrays,
217 checked_cast<const StructArray&>(*chunk).Flatten(pool));
218 DCHECK_EQ(arrays.size(), flattened_chunks.size());
219 for (size_t i = 0; i < arrays.size(); ++i) {
220 flattened_chunks[i].push_back(arrays[i]);
221 }
222 }
223
224 std::vector<std::shared_ptr<ChunkedArray>> flattened(type()->num_fields());
225 for (size_t i = 0; i < flattened.size(); ++i) {
226 auto child_type = type()->field(static_cast<int>(i))->type();
227 flattened[i] =
228 std::make_shared<ChunkedArray>(std::move(flattened_chunks[i]), child_type);
229 }
230 return flattened;
231}
232
233Result<std::shared_ptr<ChunkedArray>> ChunkedArray::View(
234 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