diff --git a/c_glib/arrow-glib/chunked-array.cpp b/c_glib/arrow-glib/chunked-array.cpp index 69195c57b176..a4f81755974f 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 0c3c81a744ce..d109150d2fd4 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 4f6a4fb0df0b..252e1e2bbd06 100644 --- a/c_glib/test/test-chunked-array.rb +++ b/c_glib/test/test-chunked-array.rb @@ -95,4 +95,18 @@ def test_chunks 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