thisisnic commented on a change in pull request #10100: URL: https://github.com/apache/arrow/pull/10100#discussion_r615966252
########## File path: cpp/src/arrow/record_batch.cc ########## @@ -253,6 +253,26 @@ bool RecordBatch::ApproxEquals(const RecordBatch& other) const { return true; } +Result<std::shared_ptr<RecordBatch>> RecordBatch::SelectColumns(const std::vector<int>& indices) const{ + int n = static_cast<int>(indices.size()); + + std::vector<std::shared_ptr<Field>> fields(n); + std::vector<std::shared_ptr<Array>> columns(n); + + for (int i = 0; i < n; i++) { + int pos = indices[i]; + if (pos < 0 || pos > num_columns() - 1) { + return Status::Invalid("Invalid column index ", pos, " to select columns."); + } + fields[i] = schema()->field(pos); + columns[i] = column(pos); + } + + auto schema = std::make_shared<arrow::Schema>(std::move(fields)); Review comment: Oops, completely missed that - will update now, thanks for highlighting! -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. For queries about this service, please contact Infrastructure at: us...@infra.apache.org