| 421 | } |
| 422 | |
| 423 | Result<std::shared_ptr<RecordBatch>> RecordBatch::SelectColumns( |
| 424 | const std::vector<int>& indices) const { |
| 425 | int n = static_cast<int>(indices.size()); |
| 426 | |
| 427 | FieldVector fields(n); |
| 428 | ArrayVector columns(n); |
| 429 | |
| 430 | for (int i = 0; i < n; i++) { |
| 431 | int pos = indices[i]; |
| 432 | if (pos < 0 || pos > num_columns() - 1) { |
| 433 | return Status::Invalid("Invalid column index ", pos, " to select columns."); |
| 434 | } |
| 435 | fields[i] = schema()->field(pos); |
| 436 | columns[i] = column(pos); |
| 437 | } |
| 438 | |
| 439 | auto new_schema = |
| 440 | std::make_shared<arrow::Schema>(std::move(fields), schema()->metadata()); |
| 441 | return RecordBatch::Make(std::move(new_schema), num_rows(), std::move(columns), |
| 442 | GetSyncEvent()); |
| 443 | } |
| 444 | |
| 445 | std::shared_ptr<RecordBatch> RecordBatch::Slice(int64_t offset) const { |
| 446 | return Slice(offset, this->num_rows() - offset); |