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 2018/08/27 04:49:32 UTC
[arrow] branch master updated: ARROW-3117: [GLib] Add
garrow_chunked_array_to_string()
This is an automated email from the ASF dual-hosted git repository.
kou 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 a5c8a02 ARROW-3117: [GLib] Add garrow_chunked_array_to_string()
a5c8a02 is described below
commit a5c8a02b1d370bfcb04a2eaad17580dfb770b228
Author: yosuke shiro <ys...@gmail.com>
AuthorDate: Mon Aug 27 13:49:07 2018 +0900
ARROW-3117: [GLib] Add garrow_chunked_array_to_string()
Author: yosuke shiro <ys...@gmail.com>
Closes #2471 from shiro615/add-garrow-chunked-array-to-string and squashes the following commits:
e9c4c021 <yosuke shiro> Add garrow_chunked_array_to_string
---
c_glib/arrow-glib/chunked-array.cpp | 28 ++++++++++++++++++++++++++++
c_glib/arrow-glib/chunked-array.h | 2 ++
c_glib/test/test-chunked-array.rb | 19 +++++++++++++++++++
3 files changed, 49 insertions(+)
diff --git a/c_glib/arrow-glib/chunked-array.cpp b/c_glib/arrow-glib/chunked-array.cpp
index a4f8175..dbbf053 100644
--- a/c_glib/arrow-glib/chunked-array.cpp
+++ b/c_glib/arrow-glib/chunked-array.cpp
@@ -25,6 +25,9 @@
#include <arrow-glib/chunked-array.hpp>
#include <arrow-glib/data-type.hpp>
#include <arrow-glib/type.hpp>
+#include <arrow-glib/error.hpp>
+
+#include <sstream>
G_BEGIN_DECLS
@@ -294,6 +297,31 @@ garrow_chunked_array_slice(GArrowChunkedArray *chunked_array,
return garrow_chunked_array_new_raw(&arrow_sub_chunked_array);
}
+/**
+ * garrow_chunked_array_to_string:
+ * @chunked_array: A #GArrowChunkedArray.
+ * @error: (nullable): Return location for a #GError or %NULL.
+ *
+ * Returns: (nullable): The formatted chunked array content or %NULL on error.
+ *
+ * The returned string should be freed when with g_free() when no
+ * longer needed.
+ *
+ * Since: 0.11.0
+ */
+gchar *
+garrow_chunked_array_to_string(GArrowChunkedArray *chunked_array, GError **error)
+{
+ const auto arrow_chunked_array = garrow_chunked_array_get_raw(chunked_array);
+ std::stringstream sink;
+ auto status = arrow::PrettyPrint(*arrow_chunked_array, 0, &sink);
+ if (garrow_error_check(error, status, "[chunked-array][to-string]")) {
+ return g_strdup(sink.str().c_str());
+ } 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 d109150..a1712a2 100644
--- a/c_glib/arrow-glib/chunked-array.h
+++ b/c_glib/arrow-glib/chunked-array.h
@@ -85,5 +85,7 @@ GList *garrow_chunked_array_get_chunks(GArrowChunkedArray *chunked_array);
GArrowChunkedArray *garrow_chunked_array_slice(GArrowChunkedArray *chunked_array,
guint64 offset,
guint64 length);
+gchar *garrow_chunked_array_to_string(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 252e1e2..05ea66b 100644
--- a/c_glib/test/test-chunked-array.rb
+++ b/c_glib/test/test-chunked-array.rb
@@ -109,4 +109,23 @@ class TestChunkedArray < Test::Unit::TestCase
sub_chunked_array = chunked_array.slice(1, 3)
assert_equal(chunks2, sub_chunked_array.chunks)
end
+
+ def test_to_s
+ chunks = [
+ build_boolean_array([true, false]),
+ build_boolean_array([true]),
+ ]
+ chunked_array = Arrow::ChunkedArray.new(chunks)
+ assert_equal(<<-PRETTY_PRINT.chomp, chunked_array.to_s)
+[
+ [
+ true,
+ false
+ ],
+ [
+ true
+ ]
+]
+ PRETTY_PRINT
+ end
end