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