| 204 | } |
| 205 | |
| 206 | Result<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 | |
| 233 | Result<std::shared_ptr<ChunkedArray>> ChunkedArray::View( |
| 234 | const std::shared_ptr<DataType>& type) const { |