Repository: arrow Updated Branches: refs/heads/master 07c6ade9b -> 39a37f76f
ARROW-878: [GLib] Add garrow_binary_array_get_buffer() This will be conflicted with #582 . Author: Kouhei Sutou <[email protected]> Closes #583 from kou/glib-binary-array-buffer and squashes the following commits: a84b8e8 [Kouhei Sutou] [GLib] Add garrow_binary_array_get_buffer() Project: http://git-wip-us.apache.org/repos/asf/arrow/repo Commit: http://git-wip-us.apache.org/repos/asf/arrow/commit/39a37f76 Tree: http://git-wip-us.apache.org/repos/asf/arrow/tree/39a37f76 Diff: http://git-wip-us.apache.org/repos/asf/arrow/diff/39a37f76 Branch: refs/heads/master Commit: 39a37f76fa2cbf1dd52d3bc51b277553b772c343 Parents: 07c6ade Author: Kouhei Sutou <[email protected]> Authored: Sat Apr 22 11:59:59 2017 -0400 Committer: Wes McKinney <[email protected]> Committed: Sat Apr 22 11:59:59 2017 -0400 ---------------------------------------------------------------------- c_glib/arrow-glib/array.cpp | 16 ++++++++++++++++ c_glib/arrow-glib/array.h | 1 + c_glib/test/test-binary-array.rb | 10 ++++++++++ c_glib/test/test-string-array.rb | 8 ++++++++ 4 files changed, 35 insertions(+) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/arrow/blob/39a37f76/c_glib/arrow-glib/array.cpp ---------------------------------------------------------------------- diff --git a/c_glib/arrow-glib/array.cpp b/c_glib/arrow-glib/array.cpp index 1229f27..2fd0901 100644 --- a/c_glib/arrow-glib/array.cpp +++ b/c_glib/arrow-glib/array.cpp @@ -707,6 +707,22 @@ garrow_binary_array_get_value(GArrowBinaryArray *array, return g_bytes_new_static(value, length); } +/** + * garrow_binary_array_get_buffer: + * @array: A #GArrowBinaryArray. + * + * Returns: (transfer full): The data of the array as #GArrowBuffer. + */ +GArrowBuffer * +garrow_binary_array_get_buffer(GArrowBinaryArray *array) +{ + auto arrow_array = garrow_array_get_raw(GARROW_ARRAY(array)); + auto arrow_binary_array = + static_cast<arrow::BinaryArray *>(arrow_array.get()); + auto arrow_data = arrow_binary_array->data(); + return garrow_buffer_new_raw(&arrow_data); +} + G_DEFINE_TYPE(GArrowStringArray, \ garrow_string_array, \ http://git-wip-us.apache.org/repos/asf/arrow/blob/39a37f76/c_glib/arrow-glib/array.h ---------------------------------------------------------------------- diff --git a/c_glib/arrow-glib/array.h b/c_glib/arrow-glib/array.h index f08ab84..f8c6734 100644 --- a/c_glib/arrow-glib/array.h +++ b/c_glib/arrow-glib/array.h @@ -664,6 +664,7 @@ GType garrow_binary_array_get_type(void) G_GNUC_CONST; GBytes *garrow_binary_array_get_value(GArrowBinaryArray *array, gint64 i); +GArrowBuffer *garrow_binary_array_get_buffer(GArrowBinaryArray *array); #define GARROW_TYPE_STRING_ARRAY \ (garrow_string_array_get_type()) http://git-wip-us.apache.org/repos/asf/arrow/blob/39a37f76/c_glib/test/test-binary-array.rb ---------------------------------------------------------------------- diff --git a/c_glib/test/test-binary-array.rb b/c_glib/test/test-binary-array.rb index 6fe8924..ccdf378 100644 --- a/c_glib/test/test-binary-array.rb +++ b/c_glib/test/test-binary-array.rb @@ -23,4 +23,14 @@ class TestBinaryArray < Test::Unit::TestCase array = builder.finish assert_equal(data, array.get_value(0).to_s) end + + def test_buffer + data1 = "\x00\x01\x02" + data2 = "\x03\x04\x05" + builder = Arrow::BinaryArrayBuilder.new + builder.append(data1) + builder.append(data2) + array = builder.finish + assert_equal(data1 + data2, array.buffer.data.to_s) + end end http://git-wip-us.apache.org/repos/asf/arrow/blob/39a37f76/c_glib/test/test-string-array.rb ---------------------------------------------------------------------- diff --git a/c_glib/test/test-string-array.rb b/c_glib/test/test-string-array.rb index a0f5a7b..a076c22 100644 --- a/c_glib/test/test-string-array.rb +++ b/c_glib/test/test-string-array.rb @@ -22,4 +22,12 @@ class TestStringArray < Test::Unit::TestCase array = builder.finish assert_equal("Hello", array.get_string(0)) end + + def test_buffer + builder = Arrow::StringArrayBuilder.new + builder.append("Hello") + builder.append("World") + array = builder.finish + assert_equal("HelloWorld", array.buffer.data.to_s) + end end
