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

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

xhochy closed pull request #1632: ARROW-2190: [GLib] Add add/remove field 
functions for RecordBatch
URL: https://github.com/apache/arrow/pull/1632
 
 
   

This is a PR merged from a forked repository.
As GitHub hides the original diff on merge, it is displayed below for
the sake of provenance:

As this is a foreign pull request (from a fork), the diff is supplied
below (as it won't show otherwise due to GitHub magic):

diff --git a/c_glib/arrow-glib/record-batch.cpp 
b/c_glib/arrow-glib/record-batch.cpp
index 64f2020ad..0d0777dab 100644
--- a/c_glib/arrow-glib/record-batch.cpp
+++ b/c_glib/arrow-glib/record-batch.cpp
@@ -25,6 +25,7 @@
 #include <arrow-glib/error.hpp>
 #include <arrow-glib/record-batch.hpp>
 #include <arrow-glib/schema.hpp>
+#include <arrow-glib/field.hpp>
 
 #include <sstream>
 
@@ -350,6 +351,63 @@ garrow_record_batch_to_string(GArrowRecordBatch 
*record_batch, GError **error)
   }
 }
 
+/**
+ * garrow_record_batch_add_column:
+ * @record_batch: A #GArrowRecordBatch.
+ * @i: The index of the new column.
+ * @field: The field to be added.
+ * @column: The column to be added.
+ * @error: (nullable): Return location for a #GError or %NULL.
+ *
+ * Returns: (nullable) (transfer full): The newly allocated
+ *   #GArrowRecordBatch that has a new column or %NULL on error.
+ *
+ * Since: 0.9.0
+ */
+GArrowRecordBatch *
+garrow_record_batch_add_column(GArrowRecordBatch *record_batch,
+                               guint i,
+                               GArrowField *field,
+                               GArrowArray *column,
+                               GError **error)
+{
+  const auto arrow_record_batch = garrow_record_batch_get_raw(record_batch);
+  const auto arrow_field = garrow_field_get_raw(field);
+  const auto arrow_column = garrow_array_get_raw(column);
+  std::shared_ptr<arrow::RecordBatch> arrow_new_record_batch;
+  auto status = arrow_record_batch->AddColumn(i, arrow_field, arrow_column, 
&arrow_new_record_batch);
+  if (garrow_error_check(error, status, "[record-batch][add-column]")) {
+    return garrow_record_batch_new_raw(&arrow_new_record_batch);
+  } else {
+    return NULL;
+  }
+}
+
+/**
+ * garrow_record_batch_remove_column:
+ * @record_batch: A #GArrowRecordBatch.
+ * @i: The index of the new column.
+ * @error: (nullable): Return location for a #GError or %NULL.
+ *
+ * Returns: (nullable) (transfer full): The newly allocated
+ *   #GArrowRecordBatch that doesn't have the column or %NULL on error.
+ *
+ * Since: 0.9.0
+ */
+GArrowRecordBatch *
+garrow_record_batch_remove_column(GArrowRecordBatch *record_batch,
+                                  guint i,
+                                  GError **error)
+{
+  const auto arrow_record_batch = garrow_record_batch_get_raw(record_batch);
+  std::shared_ptr<arrow::RecordBatch> arrow_new_record_batch;
+  auto status = arrow_record_batch->RemoveColumn(i, &arrow_new_record_batch);
+  if (garrow_error_check(error, status, "[record-batch][remove-column]")) {
+    return garrow_record_batch_new_raw(&arrow_new_record_batch);
+  } else {
+    return NULL;
+  }
+}
 
 G_END_DECLS
 
diff --git a/c_glib/arrow-glib/record-batch.h b/c_glib/arrow-glib/record-batch.h
index d31edf439..bd6a1ce2f 100644
--- a/c_glib/arrow-glib/record-batch.h
+++ b/c_glib/arrow-glib/record-batch.h
@@ -88,5 +88,13 @@ GArrowRecordBatch *garrow_record_batch_slice     
(GArrowRecordBatch *record_batc
 
 gchar        *garrow_record_batch_to_string      (GArrowRecordBatch 
*record_batch,
                                                   GError **error);
+GArrowRecordBatch *garrow_record_batch_add_column(GArrowRecordBatch 
*record_batch,
+                                                  guint i,
+                                                  GArrowField *field,
+                                                  GArrowArray *column,
+                                                  GError **error);
+GArrowRecordBatch *garrow_record_batch_remove_column(GArrowRecordBatch 
*record_batch,
+                                                     guint i,
+                                                     GError **error);
 
 G_END_DECLS
diff --git a/c_glib/test/test-record-batch.rb b/c_glib/test/test-record-batch.rb
index 365922f49..b215e725a 100644
--- a/c_glib/test/test-record-batch.rb
+++ b/c_glib/test/test-record-batch.rb
@@ -135,5 +135,19 @@ def test_to_s
 valid: [false, true, false, true, false]
       PRETTY_PRINT
     end
+
+    def test_add_column
+      field = Arrow::Field.new("added", Arrow::BooleanDataType.new)
+      column = build_boolean_array([false, false, true, true, true])
+      new_record_batch = @record_batch.add_column(1, field, column)
+      assert_equal(["visible", "added", "valid"],
+                   new_record_batch.schema.fields.collect(&:name))
+    end
+
+    def test_remove_column
+      new_record_batch = @record_batch.remove_column(0)
+      assert_equal(["valid"],
+                   new_record_batch.schema.fields.collect(&:name))
+    end
   end
 end


 

----------------------------------------------------------------
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:
[email protected]


> [GLib] Add add/remove field functions for RecordBatch.
> ------------------------------------------------------
>
>                 Key: ARROW-2190
>                 URL: https://issues.apache.org/jira/browse/ARROW-2190
>             Project: Apache Arrow
>          Issue Type: New Feature
>            Reporter: yosuke shiro
>            Priority: Major
>              Labels: pull-request-available
>             Fix For: 0.9.0
>
>
> Add AddColumn and RemoveColumn api to RecordBatch.



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

Reply via email to