[ 
https://issues.apache.org/jira/browse/ARROW-969?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16357434#comment-16357434
 ] 

ASF GitHub Bot commented on ARROW-969:
--------------------------------------

wesm commented on a change in pull request #1574: ARROW-969: [C++] Add 
add/remove field functions for RecordBatch
URL: https://github.com/apache/arrow/pull/1574#discussion_r167037375
 
 

 ##########
 File path: cpp/src/arrow/record_batch.cc
 ##########
 @@ -78,6 +79,52 @@ class SimpleRecordBatch : public RecordBatch {
 
   std::shared_ptr<ArrayData> column_data(int i) const override { return 
columns_[i]; }
 
+  Status AddColumn(int i, const std::shared_ptr<Field>& field,
+                   const std::shared_ptr<ArrayData>& column,
+                   std::shared_ptr<RecordBatch>* out) const override {
+    if (i < 0 || i > num_columns() + 1) {
+      return Status::Invalid("Invalid column index");
+    }
+    if (field == nullptr) {
+      std::stringstream ss;
+      ss << "Field " << i << " was null";
+      return Status::Invalid(ss.str());
+    }
+    if (column == nullptr) {
+      std::stringstream ss;
+      ss << "Column " << i << " was null";
+      return Status::Invalid(ss.str());
+    }
+    if (!field->type()->Equals(column->type)) {
+      std::stringstream ss;
+      ss << "Column data type " << field->type()->name()
+         << " does not match field data type " << column->type->name();
+      return Status::Invalid(ss.str());
+    }
+    if (column->length != num_rows_) {
+      std::stringstream ss;
+      ss << "Added column's length must match record batch's length. Expected 
length "
+         << num_rows_ << " but got length " << column->length;
+      return Status::Invalid(ss.str());
+    }
+
+    std::shared_ptr<Schema> new_schema;
+    RETURN_NOT_OK(schema_->AddField(i, field, &new_schema));
 
 Review comment:
   We could leave the boundschecking above to `Schema::AddField` -- could you 
also check whether that function has the issues described above?

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on 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


> [C++/Python] Add add/remove field functions for RecordBatch
> -----------------------------------------------------------
>
>                 Key: ARROW-969
>                 URL: https://issues.apache.org/jira/browse/ARROW-969
>             Project: Apache Arrow
>          Issue Type: New Feature
>          Components: C++, Python
>            Reporter: Wes McKinney
>            Assignee: Panchen Xue
>            Priority: Major
>              Labels: pull-request-available
>             Fix For: 0.9.0
>
>
> Analogous to the Table equivalents



--
This message was sent by Atlassian JIRA
(v7.6.3#76005)

Reply via email to