You are viewing a plain text version of this content. The canonical link for it is here.
Posted to github@arrow.apache.org by GitBox <gi...@apache.org> on 2021/04/19 15:41:49 UTC

[GitHub] [arrow] jorisvandenbossche commented on a change in pull request #10100: ARROW-11660: [C++] Move RecordBatch::SelectColumns method from R to C++ library

jorisvandenbossche commented on a change in pull request #10100:
URL: https://github.com/apache/arrow/pull/10100#discussion_r615961099



##########
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:
       Here we probably want to preserve the metadata of the schema (see the `Table::SelectColumns` method)




-- 
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:
users@infra.apache.org