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