You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@arrow.apache.org by we...@apache.org on 2017/04/11 17:55:16 UTC
arrow git commit: ARROW-806: [GLib] Support add/remove a column from
table
Repository: arrow
Updated Branches:
refs/heads/master b3cec804b -> f5245cc6b
ARROW-806: [GLib] Support add/remove a column from table
Author: Kouhei Sutou <ko...@clear-code.com>
Closes #525 from kou/glib-add-remove-column and squashes the following commits:
72d495a [Kouhei Sutou] [GLib] Support add/remove a column from table
Project: http://git-wip-us.apache.org/repos/asf/arrow/repo
Commit: http://git-wip-us.apache.org/repos/asf/arrow/commit/f5245cc6
Tree: http://git-wip-us.apache.org/repos/asf/arrow/tree/f5245cc6
Diff: http://git-wip-us.apache.org/repos/asf/arrow/diff/f5245cc6
Branch: refs/heads/master
Commit: f5245cc6b1811217df78acfb7bf6163d9dd09f32
Parents: b3cec80
Author: Kouhei Sutou <ko...@clear-code.com>
Authored: Tue Apr 11 13:55:11 2017 -0400
Committer: Wes McKinney <we...@twosigma.com>
Committed: Tue Apr 11 13:55:11 2017 -0400
----------------------------------------------------------------------
c_glib/arrow-glib/table.cpp | 58 ++++++++++++++++++++++++++++++++++++++++
c_glib/arrow-glib/table.h | 8 ++++++
c_glib/test/test-table.rb | 14 ++++++++++
3 files changed, 80 insertions(+)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/arrow/blob/f5245cc6/c_glib/arrow-glib/table.cpp
----------------------------------------------------------------------
diff --git a/c_glib/arrow-glib/table.cpp b/c_glib/arrow-glib/table.cpp
index 2f82ffa..1d743b7 100644
--- a/c_glib/arrow-glib/table.cpp
+++ b/c_glib/arrow-glib/table.cpp
@@ -22,6 +22,7 @@
#endif
#include <arrow-glib/column.hpp>
+#include <arrow-glib/error.hpp>
#include <arrow-glib/schema.hpp>
#include <arrow-glib/table.hpp>
@@ -203,6 +204,63 @@ garrow_table_get_n_rows(GArrowTable *table)
return arrow_table->num_rows();
}
+/**
+ * garrow_table_add_column:
+ * @table: A #GArrowTable.
+ * @i: The index of the new column.
+ * @column: The column to be added.
+ * @error: (nullable): Return location for a #GError or %NULL.
+ *
+ * Returns: (nullable) (transfer full): The newly allocated
+ * #GArrowTable that has a new column or %NULL on error.
+ *
+ * Since: 0.3.0
+ */
+GArrowTable *
+garrow_table_add_column(GArrowTable *table,
+ guint i,
+ GArrowColumn *column,
+ GError **error)
+{
+ const auto arrow_table = garrow_table_get_raw(table);
+ const auto arrow_column = garrow_column_get_raw(column);
+ std::shared_ptr<arrow::Table> arrow_new_table;
+ auto status = arrow_table->AddColumn(i, arrow_column, &arrow_new_table);
+ if (status.ok()) {
+ return garrow_table_new_raw(&arrow_new_table);
+ } else {
+ garrow_error_set(error, status, "[table][add-column]");
+ return NULL;
+ }
+}
+
+/**
+ * garrow_table_remove_column:
+ * @table: A #GArrowTable.
+ * @i: The index of the column to be removed.
+ * @error: (nullable): Return location for a #GError or %NULL.
+ *
+ * Returns: (nullable) (transfer full): The newly allocated
+ * #GArrowTable that doesn't have the column or %NULL on error.
+ *
+ * Since: 0.3.0
+ */
+GArrowTable *
+garrow_table_remove_column(GArrowTable *table,
+ guint i,
+ GError **error)
+{
+ const auto arrow_table = garrow_table_get_raw(table);
+ std::shared_ptr<arrow::Table> arrow_new_table;
+ auto status = arrow_table->RemoveColumn(i, &arrow_new_table);
+ if (status.ok()) {
+ return garrow_table_new_raw(&arrow_new_table);
+ } else {
+ garrow_error_set(error, status, "[table][remove-column]");
+ return NULL;
+ }
+}
+
G_END_DECLS
GArrowTable *
http://git-wip-us.apache.org/repos/asf/arrow/blob/f5245cc6/c_glib/arrow-glib/table.h
----------------------------------------------------------------------
diff --git a/c_glib/arrow-glib/table.h b/c_glib/arrow-glib/table.h
index 4dbb8c5..9ae0cce 100644
--- a/c_glib/arrow-glib/table.h
+++ b/c_glib/arrow-glib/table.h
@@ -75,4 +75,12 @@ GArrowColumn *garrow_table_get_column (GArrowTable *table,
guint garrow_table_get_n_columns (GArrowTable *table);
guint64 garrow_table_get_n_rows (GArrowTable *table);
+GArrowTable *garrow_table_add_column (GArrowTable *table,
+ guint i,
+ GArrowColumn *column,
+ GError **error);
+GArrowTable *garrow_table_remove_column (GArrowTable *table,
+ guint i,
+ GError **error);
+
G_END_DECLS
http://git-wip-us.apache.org/repos/asf/arrow/blob/f5245cc6/c_glib/test/test-table.rb
----------------------------------------------------------------------
diff --git a/c_glib/test/test-table.rb b/c_glib/test/test-table.rb
index e2b71b3..da6871e 100644
--- a/c_glib/test/test-table.rb
+++ b/c_glib/test/test-table.rb
@@ -82,5 +82,19 @@ class TestTable < Test::Unit::TestCase
def test_n_rows
assert_equal(1, @table.n_rows)
end
+
+ def test_add_column
+ field = Arrow::Field.new("added", Arrow::BooleanDataType.new)
+ column = Arrow::Column.new(field, build_boolean_array([true]))
+ new_table = @table.add_column(1, column)
+ assert_equal(["visible", "added", "valid"],
+ new_table.schema.fields.collect(&:name))
+ end
+
+ def test_remove_column
+ new_table = @table.remove_column(0)
+ assert_equal(["valid"],
+ new_table.schema.fields.collect(&:name))
+ end
end
end