This is an automated email from the ASF dual-hosted git repository.

wesm pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/arrow.git


The following commit(s) were added to refs/heads/master by this push:
     new e8870d1  ARROW-2166: [GLib] Add Slice api to Column
e8870d1 is described below

commit e8870d1cfae9ecd62c69e7b9f57da0bdfb3a8dc2
Author: yosuke shiro <[email protected]>
AuthorDate: Fri Feb 16 14:31:29 2018 -0500

    ARROW-2166: [GLib] Add Slice api to Column
    
    Add Slice api to Column.
    
    Author: yosuke shiro <[email protected]>
    
    Closes #1617 from shiro615/ARROW-2166 and squashes the following commits:
    
    bd39d756 [yosuke shiro] ARROW-2166: [GLib] Add Slice api to Column
---
 c_glib/arrow-glib/column.cpp | 20 ++++++++++++++++++++
 c_glib/arrow-glib/column.h   |  3 +++
 c_glib/test/test-column.rb   | 16 ++++++++++++++++
 3 files changed, 39 insertions(+)

diff --git a/c_glib/arrow-glib/column.cpp b/c_glib/arrow-glib/column.cpp
index a7222b1..55d06ea 100644
--- a/c_glib/arrow-glib/column.cpp
+++ b/c_glib/arrow-glib/column.cpp
@@ -161,6 +161,26 @@ garrow_column_new_chunked_array(GArrowField *field,
 }
 
 /**
+ * garrow_column_slice:
+ * @column: A #GArrowColumn.
+ * @offset: The offset of sub #GArrowColumn.
+ * @length: The length of sub #GArrowColumn.
+ *
+ * Returns: (transfer full): The sub #GArrowColumn. It covers only from
+ *   `offset` to `offset + length` range. The sub #GArrowColumn shares
+ *   values with the base #GArrowColumn.
+ */
+GArrowColumn *
+garrow_column_slice(GArrowColumn *column,
+                    guint64 offset,
+                    guint64 length)
+{
+  const auto arrow_column = garrow_column_get_raw(column);
+  auto arrow_sub_column = arrow_column->Slice(offset, length);
+  return garrow_column_new_raw(&arrow_sub_column);
+}
+
+/**
  * garrow_column_equal:
  * @column: A #GArrowColumn.
  * @other_column: A #GArrowColumn to be compared.
diff --git a/c_glib/arrow-glib/column.h b/c_glib/arrow-glib/column.h
index b649c5f..f2c181d 100644
--- a/c_glib/arrow-glib/column.h
+++ b/c_glib/arrow-glib/column.h
@@ -71,6 +71,9 @@ GArrowColumn *garrow_column_new_array(GArrowField *field,
                                       GArrowArray *array);
 GArrowColumn *garrow_column_new_chunked_array(GArrowField *field,
                                               GArrowChunkedArray 
*chunked_array);
+GArrowColumn *garrow_column_slice(GArrowColumn *column,
+                                  guint64 offset,
+                                  guint64 length);
 
 gboolean            garrow_column_equal         (GArrowColumn *column,
                                                  GArrowColumn *other_column);
diff --git a/c_glib/test/test-column.rb b/c_glib/test/test-column.rb
index 96e02b6..01127de 100644
--- a/c_glib/test/test-column.rb
+++ b/c_glib/test/test-column.rb
@@ -96,4 +96,20 @@ class TestColumn < Test::Unit::TestCase
     column = Arrow::Column.new(field, chunked_array)
     assert_equal(3, column.data.length)
   end
+
+  def test_slice
+    field = Arrow::Field.new("enabled", Arrow::BooleanDataType.new)
+    chunks1 = [
+      build_boolean_array([true, false, true]),
+      build_boolean_array([false, true]),
+    ]
+    chunks2 = [
+      build_boolean_array([false, true]),
+      build_boolean_array([false]),
+    ]
+    chunked_array = Arrow::ChunkedArray.new(chunks1)
+    column = Arrow::Column.new(field, chunked_array)
+    sub_column = column.slice(1, 3)
+    assert_equal(chunks2, sub_column.data.chunks)
+  end
 end

-- 
To stop receiving notification emails like this one, please contact
[email protected].

Reply via email to