| 216 | } |
| 217 | |
| 218 | Result<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 | |
| 245 | Result<std::shared_ptr<ChunkedArray>> ChunkedArray::View( |
| 246 | const std::shared_ptr<DataType>& type) const { |