You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@arrow.apache.org by we...@apache.org on 2017/05/15 20:13:33 UTC
arrow git commit: ARROW-1031: [GLib] Support pretty print
Repository: arrow
Updated Branches:
refs/heads/master edfb2dca8 -> ba9348fb3
ARROW-1031: [GLib] Support pretty print
Author: Kouhei Sutou <ko...@clear-code.com>
Closes #688 from kou/glib-support-pretty-print and squashes the following commits:
815f87f [Kouhei Sutou] [GLib] Support pretty print
Project: http://git-wip-us.apache.org/repos/asf/arrow/repo
Commit: http://git-wip-us.apache.org/repos/asf/arrow/commit/ba9348fb
Tree: http://git-wip-us.apache.org/repos/asf/arrow/tree/ba9348fb
Diff: http://git-wip-us.apache.org/repos/asf/arrow/diff/ba9348fb
Branch: refs/heads/master
Commit: ba9348fb3aec4d39a66faa8ab9d063223dd7e7a9
Parents: edfb2dc
Author: Kouhei Sutou <ko...@clear-code.com>
Authored: Mon May 15 16:13:25 2017 -0400
Committer: Wes McKinney <we...@twosigma.com>
Committed: Mon May 15 16:13:25 2017 -0400
----------------------------------------------------------------------
c_glib/arrow-glib/array.cpp | 27 +++++++++++++++++++++++++++
c_glib/arrow-glib/array.h | 2 ++
c_glib/arrow-glib/record-batch.cpp | 29 +++++++++++++++++++++++++++++
c_glib/arrow-glib/record-batch.h | 3 +++
c_glib/arrow-glib/table.h | 2 ++
c_glib/test/test-array.rb | 5 +++++
c_glib/test/test-record-batch.rb | 7 +++++++
7 files changed, 75 insertions(+)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/arrow/blob/ba9348fb/c_glib/arrow-glib/array.cpp
----------------------------------------------------------------------
diff --git a/c_glib/arrow-glib/array.cpp b/c_glib/arrow-glib/array.cpp
index 8bc6ea9..e9a6a49 100644
--- a/c_glib/arrow-glib/array.cpp
+++ b/c_glib/arrow-glib/array.cpp
@@ -24,9 +24,11 @@
#include <arrow-glib/array.hpp>
#include <arrow-glib/buffer.hpp>
#include <arrow-glib/data-type.hpp>
+#include <arrow-glib/error.hpp>
#include <arrow-glib/type.hpp>
#include <iostream>
+#include <sstream>
G_BEGIN_DECLS
@@ -395,6 +397,31 @@ garrow_array_slice(GArrowArray *array,
return garrow_array_new_raw(&arrow_sub_array);
}
+/**
+ * garrow_array_to_string:
+ * @array: A #GArrowArray.
+ * @error: (nullable): Return location for a #GError or %NULL.
+ *
+ * Returns: (nullable): The formatted array content or %NULL on error.
+ *
+ * The returned string should be freed when with g_free() when no
+ * longer needed.
+ *
+ * Since: 0.4.0
+ */
+gchar *
+garrow_array_to_string(GArrowArray *array, GError **error)
+{
+ const auto arrow_array = garrow_array_get_raw(array);
+ std::stringstream sink;
+ auto status = arrow::PrettyPrint(*arrow_array, 0, &sink);
+ if (garrow_error_check(error, status, "[array][to-string]")) {
+ return g_strdup(sink.str().c_str());
+ } else {
+ return NULL;
+ }
+}
+
G_DEFINE_TYPE(GArrowNullArray, \
garrow_null_array, \
http://git-wip-us.apache.org/repos/asf/arrow/blob/ba9348fb/c_glib/arrow-glib/array.h
----------------------------------------------------------------------
diff --git a/c_glib/arrow-glib/array.h b/c_glib/arrow-glib/array.h
index c4efeaf..d32157b 100644
--- a/c_glib/arrow-glib/array.h
+++ b/c_glib/arrow-glib/array.h
@@ -79,6 +79,8 @@ GArrowType garrow_array_get_value_type(GArrowArray *array);
GArrowArray *garrow_array_slice (GArrowArray *array,
gint64 offset,
gint64 length);
+gchar *garrow_array_to_string (GArrowArray *array,
+ GError **error);
#define GARROW_TYPE_NULL_ARRAY \
(garrow_null_array_get_type())
http://git-wip-us.apache.org/repos/asf/arrow/blob/ba9348fb/c_glib/arrow-glib/record-batch.cpp
----------------------------------------------------------------------
diff --git a/c_glib/arrow-glib/record-batch.cpp b/c_glib/arrow-glib/record-batch.cpp
index 3eed1a0..cd030de 100644
--- a/c_glib/arrow-glib/record-batch.cpp
+++ b/c_glib/arrow-glib/record-batch.cpp
@@ -22,9 +22,12 @@
#endif
#include <arrow-glib/array.hpp>
+#include <arrow-glib/error.hpp>
#include <arrow-glib/record-batch.hpp>
#include <arrow-glib/schema.hpp>
+#include <sstream>
+
G_BEGIN_DECLS
/**
@@ -286,6 +289,32 @@ garrow_record_batch_slice(GArrowRecordBatch *record_batch,
return garrow_record_batch_new_raw(&arrow_sub_record_batch);
}
+/**
+ * garrow_record_batch_to_string:
+ * @record_batch: A #GArrowRecordBatch.
+ * @error: (nullable): Return location for a #GError or %NULL.
+ *
+ * Returns: (nullable): The formatted record batch content or %NULL on error.
+ *
+ * The returned string should be freed when with g_free() when no
+ * longer needed.
+ *
+ * Since: 0.4.0
+ */
+gchar *
+garrow_record_batch_to_string(GArrowRecordBatch *record_batch, GError **error)
+{
+ const auto arrow_record_batch = garrow_record_batch_get_raw(record_batch);
+ std::stringstream sink;
+ auto status = arrow::PrettyPrint(*arrow_record_batch, 0, &sink);
+ if (garrow_error_check(error, status, "[record-batch][to-string]")) {
+ return g_strdup(sink.str().c_str());
+ } else {
+ return NULL;
+ }
+}
+
+
G_END_DECLS
GArrowRecordBatch *
http://git-wip-us.apache.org/repos/asf/arrow/blob/ba9348fb/c_glib/arrow-glib/record-batch.h
----------------------------------------------------------------------
diff --git a/c_glib/arrow-glib/record-batch.h b/c_glib/arrow-glib/record-batch.h
index 61e8f3d..021f894 100644
--- a/c_glib/arrow-glib/record-batch.h
+++ b/c_glib/arrow-glib/record-batch.h
@@ -85,4 +85,7 @@ GArrowRecordBatch *garrow_record_batch_slice (GArrowRecordBatch *record_batc
gint64 offset,
gint64 length);
+gchar *garrow_record_batch_to_string (GArrowRecordBatch *record_batch,
+ GError **error);
+
G_END_DECLS
http://git-wip-us.apache.org/repos/asf/arrow/blob/ba9348fb/c_glib/arrow-glib/table.h
----------------------------------------------------------------------
diff --git a/c_glib/arrow-glib/table.h b/c_glib/arrow-glib/table.h
index 9e21669..7f83872 100644
--- a/c_glib/arrow-glib/table.h
+++ b/c_glib/arrow-glib/table.h
@@ -86,4 +86,6 @@ GArrowTable *garrow_table_remove_column (GArrowTable *table,
guint i,
GError **error);
+gchar *garrow_table_to_string (GArrowTable *table);
+
G_END_DECLS
http://git-wip-us.apache.org/repos/asf/arrow/blob/ba9348fb/c_glib/test/test-array.rb
----------------------------------------------------------------------
diff --git a/c_glib/test/test-array.rb b/c_glib/test/test-array.rb
index ca02fa2..bd0c7d6 100644
--- a/c_glib/test/test-array.rb
+++ b/c_glib/test/test-array.rb
@@ -96,4 +96,9 @@ class TestArray < Test::Unit::TestCase
assert_equal([false, true],
sub_array.length.times.collect {|i| sub_array.get_value(i)})
end
+
+ def test_to_s
+ assert_equal("[true, false, true]",
+ build_boolean_array([true, false, true]).to_s)
+ end
end
http://git-wip-us.apache.org/repos/asf/arrow/blob/ba9348fb/c_glib/test/test-record-batch.rb
----------------------------------------------------------------------
diff --git a/c_glib/test/test-record-batch.rb b/c_glib/test/test-record-batch.rb
index 048f6de..9fd34b7 100644
--- a/c_glib/test/test-record-batch.rb
+++ b/c_glib/test/test-record-batch.rb
@@ -91,5 +91,12 @@ class TestTable < Test::Unit::TestCase
assert_equal([false, true],
sub_visible_values)
end
+
+ def test_to_s
+ assert_equal(<<-PRETTY_PRINT, @record_batch.to_s)
+visible: [true, false, true, false, true, false]
+valid: [false, true, false, true, false]
+ PRETTY_PRINT
+ end
end
end