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

uwe 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 d28f055  ARROW-2146: [GLib] Add Slice api to ChunkedArray
d28f055 is described below

commit d28f055ee20ae57b9acf16d47baa328f132d9ea3
Author: yosuke shiro <ys201...@gmail.com>
AuthorDate: Tue Feb 13 13:33:51 2018 +0100

    ARROW-2146: [GLib] Add Slice api to ChunkedArray
    
    Add Slice api to ChunkedArray.
    
    Author: yosuke shiro <ys201...@gmail.com>
    
    Closes #1600 from shiro615/ARROW-2146 and squashes the following commits:
    
    9b95c70 [yosuke shiro] ARROW-2146: [GLib] Add Slice api to ChunkedArray
---
 c_glib/arrow-glib/chunked-array.cpp | 20 ++++++++++++++++++++
 c_glib/arrow-glib/chunked-array.h   |  3 +++
 c_glib/test/test-chunked-array.rb   | 14 ++++++++++++++
 3 files changed, 37 insertions(+)

diff --git a/c_glib/arrow-glib/chunked-array.cpp 
b/c_glib/arrow-glib/chunked-array.cpp
index 69195c5..a4f8175 100644
--- a/c_glib/arrow-glib/chunked-array.cpp
+++ b/c_glib/arrow-glib/chunked-array.cpp
@@ -274,6 +274,26 @@ garrow_chunked_array_get_chunks(GArrowChunkedArray 
*chunked_array)
   return g_list_reverse(chunks);
 }
 
+/**
+ * garrow_chunked_array_slice:
+ * @chunked_array: A #GArrowChunkedArray.
+ * @offset: The offset of sub #GArrowChunkedArray.
+ * @length: The length of sub #GArrowChunkedArray.
+ *
+ * Returns: (transfer full): The sub #GArrowChunkedArray. It covers only from
+ *   `offset` to `offset + length` range. The sub #GArrowChunkedArray shares
+ *   values with the base #GArrowChunkedArray.
+ */
+GArrowChunkedArray  *
+garrow_chunked_array_slice(GArrowChunkedArray *chunked_array,
+                           guint64 offset,
+                           guint64 length)
+{
+  const auto arrow_chunked_array = garrow_chunked_array_get_raw(chunked_array);
+  auto arrow_sub_chunked_array = arrow_chunked_array->Slice(offset, length);
+  return garrow_chunked_array_new_raw(&arrow_sub_chunked_array);
+}
+
 G_END_DECLS
 
 GArrowChunkedArray *
diff --git a/c_glib/arrow-glib/chunked-array.h 
b/c_glib/arrow-glib/chunked-array.h
index 0c3c81a..d109150 100644
--- a/c_glib/arrow-glib/chunked-array.h
+++ b/c_glib/arrow-glib/chunked-array.h
@@ -82,5 +82,8 @@ guint   garrow_chunked_array_get_n_chunks (GArrowChunkedArray 
*chunked_array);
 GArrowArray *garrow_chunked_array_get_chunk(GArrowChunkedArray *chunked_array,
                                             guint i);
 GList *garrow_chunked_array_get_chunks(GArrowChunkedArray *chunked_array);
+GArrowChunkedArray *garrow_chunked_array_slice(GArrowChunkedArray 
*chunked_array,
+                                               guint64 offset,
+                                               guint64 length);
 
 G_END_DECLS
diff --git a/c_glib/test/test-chunked-array.rb 
b/c_glib/test/test-chunked-array.rb
index 4f6a4fb..252e1e2 100644
--- a/c_glib/test/test-chunked-array.rb
+++ b/c_glib/test/test-chunked-array.rb
@@ -95,4 +95,18 @@ class TestChunkedArray < Test::Unit::TestCase
     assert_equal([2, 1],
                  chunked_array.chunks.collect(&:length))
   end
+
+  def test_slice
+    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)
+    sub_chunked_array = chunked_array.slice(1, 3)
+    assert_equal(chunks2, sub_chunked_array.chunks)
+  end
 end

-- 
To stop receiving notification emails like this one, please contact
u...@apache.org.

Reply via email to