| 370 | } |
| 371 | |
| 372 | Result<std::shared_ptr<Table>> Table::SelectColumns( |
| 373 | const std::vector<int>& indices) const { |
| 374 | int n = static_cast<int>(indices.size()); |
| 375 | |
| 376 | std::vector<std::shared_ptr<ChunkedArray>> columns(n); |
| 377 | std::vector<std::shared_ptr<Field>> fields(n); |
| 378 | for (int i = 0; i < n; i++) { |
| 379 | int pos = indices[i]; |
| 380 | if (pos < 0 || pos > num_columns() - 1) { |
| 381 | return Status::Invalid("Invalid column index ", pos, " to select columns."); |
| 382 | } |
| 383 | columns[i] = column(pos); |
| 384 | fields[i] = field(pos); |
| 385 | } |
| 386 | |
| 387 | auto new_schema = |
| 388 | std::make_shared<arrow::Schema>(std::move(fields), schema()->metadata()); |
| 389 | return Table::Make(std::move(new_schema), std::move(columns), num_rows()); |
| 390 | } |
| 391 | |
| 392 | std::string Table::ToString() const { |
| 393 | std::stringstream ss; |