You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@arrow.apache.org by ko...@apache.org on 2025/06/22 11:21:29 UTC
(arrow) branch main updated: GH-45713: [GLib] Add garrow_chunked_array_(import|export)() (#46876)
This is an automated email from the ASF dual-hosted git repository.
kou pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/arrow.git
The following commit(s) were added to refs/heads/main by this push:
new 118ca35440 GH-45713: [GLib] Add garrow_chunked_array_(import|export)() (#46876)
118ca35440 is described below
commit 118ca35440345ebf2dfa4bf40721d8a58c9fb5b8
Author: takuya kodama <a....@gmail.com>
AuthorDate: Sun Jun 22 20:21:23 2025 +0900
GH-45713: [GLib] Add garrow_chunked_array_(import|export)() (#46876)
### Rationale for this change
The GLib bindings were missing C data interface
functions for ChunkedArray import|export operations.
### What changes are included in this PR?
This PR added the follwoings.
- Add garrow_chunked_array_import()
- Add garrow_chunked_array_export()
- Add round-trip test with boolean chunked array data
### Are these changes tested?
Yes.
### Are there any user-facing changes?
No.
* GitHub Issue: #45713
Authored-by: otegami <a....@gmail.com>
Signed-off-by: Sutou Kouhei <ko...@clear-code.com>
---
c_glib/arrow-glib/chunked-array.cpp | 52 +++++++++++++++++++++++++++++++++++++
c_glib/arrow-glib/chunked-array.h | 8 ++++++
c_glib/test/test-chunked-array.rb | 11 ++++++++
3 files changed, 71 insertions(+)
diff --git a/c_glib/arrow-glib/chunked-array.cpp b/c_glib/arrow-glib/chunked-array.cpp
index 39c8faad6c..8870e71894 100644
--- a/c_glib/arrow-glib/chunked-array.cpp
+++ b/c_glib/arrow-glib/chunked-array.cpp
@@ -23,6 +23,8 @@
#include <arrow-glib/type.hpp>
#include <arrow-glib/error.hpp>
+#include <arrow/c/bridge.h>
+
#include <sstream>
G_BEGIN_DECLS
@@ -406,6 +408,56 @@ garrow_chunked_array_combine(GArrowChunkedArray *chunked_array, GError **error)
}
}
+/**
+ * garrow_chunked_array_import:
+ * @c_abi_array_stream: (not nullable): A `struct ArrowArrayStream *`.
+ * @error: (nullable): Return location for a #GError or %NULL.
+ *
+ * Returns: (transfer full) (nullable): An imported chunked array on success,
+ * %NULL on error.
+ *
+ * Since: 21.0.0
+ */
+GArrowChunkedArray *
+garrow_chunked_array_import(gpointer c_abi_array_stream, GError **error)
+{
+ auto arrow_chunked_array_result =
+ arrow::ImportChunkedArray(static_cast<struct ArrowArrayStream *>(c_abi_array_stream));
+ if (garrow::check(error, arrow_chunked_array_result, "[chunked-array][import]")) {
+ return garrow_chunked_array_new_raw(&(*arrow_chunked_array_result));
+ } else {
+ return NULL;
+ }
+}
+
+/**
+ * garrow_chunked_array_export:
+ * @chunked_array: A #GArrowChunkedArray to be exported.
+ * @error: (nullable): Return location for a #GError or %NULL.
+ *
+ * Returns: (transfer full) (nullable): An exported chunked array as
+ * `struct ArrowArrayStream *` on success, %NULL on error.
+ * It should be freed with the `ArrowArrayStream::release` callback then
+ * g_free() when no longer needed.
+ *
+ * Since: 21.0.0
+ */
+gpointer
+garrow_chunked_array_export(GArrowChunkedArray *chunked_array, GError **error)
+{
+ const auto arrow_chunked_array = garrow_chunked_array_get_raw(chunked_array);
+ auto c_abi_array_stream = g_new(struct ArrowArrayStream, 1);
+ auto status =
+ arrow::ExportChunkedArray(arrow_chunked_array,
+ static_cast<struct ArrowArrayStream *>(c_abi_array_stream));
+ if (garrow::check(error, status, "[chunked-array][export]")) {
+ return c_abi_array_stream;
+ } else {
+ g_free(c_abi_array_stream);
+ 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 712d16504f..27fedb6a4f 100644
--- a/c_glib/arrow-glib/chunked-array.h
+++ b/c_glib/arrow-glib/chunked-array.h
@@ -83,4 +83,12 @@ GARROW_AVAILABLE_IN_4_0
GArrowArray *
garrow_chunked_array_combine(GArrowChunkedArray *chunked_array, GError **error);
+GARROW_AVAILABLE_IN_21_0
+GArrowChunkedArray *
+garrow_chunked_array_import(gpointer c_abi_array_stream, GError **error);
+
+GARROW_AVAILABLE_IN_21_0
+gpointer
+garrow_chunked_array_export(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 86bd23af6f..2d5dd5cd64 100644
--- a/c_glib/test/test-chunked-array.rb
+++ b/c_glib/test/test-chunked-array.rb
@@ -144,4 +144,15 @@ class TestChunkedArray < Test::Unit::TestCase
assert_equal(build_boolean_array([true, false, nil]),
chunked_array.combine)
end
+
+ def test_export_import
+ chunks = [
+ build_boolean_array([true, false, true]),
+ build_boolean_array([false, nil]),
+ ]
+ original_chunked_array = Arrow::ChunkedArray.new(chunks)
+ c_abi_array_stream = original_chunked_array.export
+ assert_equal(original_chunked_array,
+ Arrow::ChunkedArray.import(c_abi_array_stream))
+ end
end