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/07/13 14:41:18 UTC

arrow git commit: ARROW-1212: [GLib] Add garrow_binary_array_get_offsets_buffer()

Repository: arrow
Updated Branches:
  refs/heads/master 85892a288 -> 248a9d830


ARROW-1212: [GLib] Add garrow_binary_array_get_offsets_buffer()

Author: Kouhei Sutou <ko...@clear-code.com>

Closes #836 from kou/glib-add-binary-get-offsets-buffer and squashes the following commits:

3b15321 [Kouhei Sutou] Add garrow_binary_array_get_offsets_buffer()


Project: http://git-wip-us.apache.org/repos/asf/arrow/repo
Commit: http://git-wip-us.apache.org/repos/asf/arrow/commit/248a9d83
Tree: http://git-wip-us.apache.org/repos/asf/arrow/tree/248a9d83
Diff: http://git-wip-us.apache.org/repos/asf/arrow/diff/248a9d83

Branch: refs/heads/master
Commit: 248a9d8303101c76be7bceb1254855121a188b33
Parents: 85892a2
Author: Kouhei Sutou <ko...@clear-code.com>
Authored: Thu Jul 13 10:41:12 2017 -0400
Committer: Wes McKinney <we...@twosigma.com>
Committed: Thu Jul 13 10:41:12 2017 -0400

----------------------------------------------------------------------
 c_glib/arrow-glib/array.cpp      | 16 ++++++++++++++++
 c_glib/arrow-glib/array.h        |  1 +
 c_glib/test/test-binary-array.rb | 12 ++++++++++++
 3 files changed, 29 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/arrow/blob/248a9d83/c_glib/arrow-glib/array.cpp
----------------------------------------------------------------------
diff --git a/c_glib/arrow-glib/array.cpp b/c_glib/arrow-glib/array.cpp
index ab62bba..30e51fb 100644
--- a/c_glib/arrow-glib/array.cpp
+++ b/c_glib/arrow-glib/array.cpp
@@ -1429,6 +1429,22 @@ garrow_binary_array_get_buffer(GArrowBinaryArray *array)
   return garrow_buffer_new_raw(&arrow_data);
 }
 
+/**
+ * garrow_binary_array_get_offsets_buffer:
+ * @array: A #GArrowBinaryArray.
+ *
+ * Returns: (transfer full): The offsets of the array as #GArrowBuffer.
+ */
+GArrowBuffer *
+garrow_binary_array_get_offsets_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_offsets = arrow_binary_array->value_offsets();
+  return garrow_buffer_new_raw(&arrow_offsets);
+}
+
 
 G_DEFINE_TYPE(GArrowStringArray,               \
               garrow_string_array,             \

http://git-wip-us.apache.org/repos/asf/arrow/blob/248a9d83/c_glib/arrow-glib/array.h
----------------------------------------------------------------------
diff --git a/c_glib/arrow-glib/array.h b/c_glib/arrow-glib/array.h
index 6043e90..1b2ba9f 100644
--- a/c_glib/arrow-glib/array.h
+++ b/c_glib/arrow-glib/array.h
@@ -804,6 +804,7 @@ GArrowBinaryArray *garrow_binary_array_new(gint64 length,
 GBytes *garrow_binary_array_get_value(GArrowBinaryArray *array,
                                       gint64 i);
 GArrowBuffer *garrow_binary_array_get_buffer(GArrowBinaryArray *array);
+GArrowBuffer *garrow_binary_array_get_offsets_buffer(GArrowBinaryArray *array);
 
 #define GARROW_TYPE_STRING_ARRAY                \
   (garrow_string_array_get_type())

http://git-wip-us.apache.org/repos/asf/arrow/blob/248a9d83/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 9ae122a..2dfd9cf 100644
--- a/c_glib/test/test-binary-array.rb
+++ b/c_glib/test/test-binary-array.rb
@@ -46,4 +46,16 @@ class TestBinaryArray < Test::Unit::TestCase
     array = builder.finish
     assert_equal(data1 + data2, array.buffer.data.to_s)
   end
+
+  def test_offsets_buffer
+    data1 = "\x00\x01"
+    data2 = "\x02\x03\x04"
+    builder = Arrow::BinaryArrayBuilder.new
+    builder.append(data1)
+    builder.append(data2)
+    array = builder.finish
+    byte_per_offset = 4
+    assert_equal([0, 2, 5].pack("l*"),
+                 array.offsets_buffer.data.to_s[0, byte_per_offset * 3])
+  end
 end