From a68a38d00ef685723067a7b42a362b4f5d3407a7 Mon Sep 17 00:00:00 2001 From: Sutou Kouhei Date: Sun, 14 Mar 2021 07:07:53 +0900 Subject: [PATCH] ARROW-11958: [GLib] Add garrow_chunked_array_combine() --- c_glib/arrow-glib/chunked-array.cpp | 24 ++++++++++++++++++++++++ c_glib/arrow-glib/chunked-array.h | 3 +++ c_glib/test/test-chunked-array.rb | 10 ++++++++++ 3 files changed, 37 insertions(+) diff --git a/c_glib/arrow-glib/chunked-array.cpp b/c_glib/arrow-glib/chunked-array.cpp index d2ba8ffbb799..bdb8976f35b9 100644 --- a/c_glib/arrow-glib/chunked-array.cpp +++ b/c_glib/arrow-glib/chunked-array.cpp @@ -330,6 +330,30 @@ garrow_chunked_array_to_string(GArrowChunkedArray *chunked_array, GError **error return g_strdup(arrow_chunked_array->ToString().c_str()); } +/** + * garrow_chunked_array_combine: + * @chunked_array: A #GArrowChunkedArray. + * @error: (nullable): Return location for a #GError or %NULL. + * + * Returns: (nullable) (transfer full): The combined array that has + * all data in all chunks. + * + * Since: 4.0.0 + */ +GArrowArray * +garrow_chunked_array_combine(GArrowChunkedArray *chunked_array, GError **error) +{ + const auto arrow_chunked_array = garrow_chunked_array_get_raw(chunked_array); + auto arrow_combined_array = arrow::Concatenate(arrow_chunked_array->chunks()); + if (garrow::check(error, + arrow_combined_array, + "[chunked-array][combine]")) { + return garrow_array_new_raw(&(*arrow_combined_array)); + } else { + return NULL; + } +} + G_END_DECLS GArrowChunkedArray * diff --git a/c_glib/arrow-glib/chunked-array.h b/c_glib/arrow-glib/chunked-array.h index 1f7347f2b0fa..8e721f0bf992 100644 --- a/c_glib/arrow-glib/chunked-array.h +++ b/c_glib/arrow-glib/chunked-array.h @@ -59,5 +59,8 @@ GArrowChunkedArray *garrow_chunked_array_slice(GArrowChunkedArray *chunked_array guint64 length); gchar *garrow_chunked_array_to_string(GArrowChunkedArray *chunked_array, GError **error); +GARROW_AVAILABLE_IN_4_0 +GArrowArray *garrow_chunked_array_combine(GArrowChunkedArray *chunked_array, + GError **error); G_END_DECLS diff --git a/c_glib/test/test-chunked-array.rb b/c_glib/test/test-chunked-array.rb index 82b46968a0d8..8f912ac846bb 100644 --- a/c_glib/test/test-chunked-array.rb +++ b/c_glib/test/test-chunked-array.rb @@ -128,4 +128,14 @@ def test_to_s ] PRETTY_PRINT end + + def test_combine + chunks = [ + build_boolean_array([true]), + build_boolean_array([false, nil]), + ] + chunked_array = Arrow::ChunkedArray.new(chunks) + assert_equal(build_boolean_array([true, false, nil]), + chunked_array.combine) + end end