Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions c_glib/arrow-glib/chunked-array.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 *
Expand Down
3 changes: 3 additions & 0 deletions c_glib/arrow-glib/chunked-array.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
14 changes: 14 additions & 0 deletions c_glib/test/test-chunked-array.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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