arrow-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From w...@apache.org
Subject arrow git commit: ARROW-1323: [GLib] Add garrow_boolean_array_get_values()
Date Wed, 02 Aug 2017 22:28:22 GMT
Repository: arrow
Updated Branches:
  refs/heads/master 93b51a039 -> 21a019157


ARROW-1323: [GLib] Add garrow_boolean_array_get_values()

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

Closes #934 from kou/glib-add-boolean-get-values and squashes the following commits:

d6502ba2 [Kouhei Sutou] [GLib] Add garrow_boolean_array_get_values()


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

Branch: refs/heads/master
Commit: 21a0191579e1065212d2a435a51d9721dd33c176
Parents: 93b51a0
Author: Kouhei Sutou <kou@clear-code.com>
Authored: Wed Aug 2 18:28:18 2017 -0400
Committer: Wes McKinney <wes.mckinney@twosigma.com>
Committed: Wed Aug 2 18:28:18 2017 -0400

----------------------------------------------------------------------
 c_glib/arrow-glib/array.cpp       | 24 ++++++++++++++++++++++++
 c_glib/arrow-glib/array.h         |  2 ++
 c_glib/test/test-boolean-array.rb | 11 +++++++++++
 3 files changed, 37 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/arrow/blob/21a01915/c_glib/arrow-glib/array.cpp
----------------------------------------------------------------------
diff --git a/c_glib/arrow-glib/array.cpp b/c_glib/arrow-glib/array.cpp
index 30e51fb..a3c45a8 100644
--- a/c_glib/arrow-glib/array.cpp
+++ b/c_glib/arrow-glib/array.cpp
@@ -557,6 +557,30 @@ garrow_boolean_array_get_value(GArrowBooleanArray *array,
   return static_cast<arrow::BooleanArray *>(arrow_array.get())->Value(i);
 }
 
+/**
+ * garrow_boolean_array_get_values:
+ * @array: A #GArrowBooleanArray.
+ * @length: (out): The number of values.
+ *
+ * Returns: (array length=length): The raw boolean values.
+ *
+ *   It should be freed with g_free() when no longer needed.
+ */
+gboolean *
+garrow_boolean_array_get_values(GArrowBooleanArray *array,
+                                gint64 *length)
+{
+  auto arrow_array = garrow_array_get_raw(GARROW_ARRAY(array));
+  auto arrow_boolean_array =
+    std::static_pointer_cast<arrow::BooleanArray>(arrow_array);
+  *length = arrow_boolean_array->length();
+  auto values = static_cast<gboolean *>(g_new(gboolean, *length));
+  for (gint64 i = 0; i < *length; ++i) {
+    values[i] = arrow_boolean_array->Value(i);
+  }
+  return values;
+}
+
 
 G_DEFINE_TYPE(GArrowInt8Array,               \
               garrow_int8_array,             \

http://git-wip-us.apache.org/repos/asf/arrow/blob/21a01915/c_glib/arrow-glib/array.h
----------------------------------------------------------------------
diff --git a/c_glib/arrow-glib/array.h b/c_glib/arrow-glib/array.h
index 1b2ba9f..10b2279 100644
--- a/c_glib/arrow-glib/array.h
+++ b/c_glib/arrow-glib/array.h
@@ -221,6 +221,8 @@ GArrowBooleanArray *garrow_boolean_array_new(gint64 length,
 
 gboolean       garrow_boolean_array_get_value (GArrowBooleanArray *array,
                                                gint64 i);
+gboolean      *garrow_boolean_array_get_values(GArrowBooleanArray *array,
+                                               gint64 *length);
 
 
 #define GARROW_TYPE_INT8_ARRAY                  \

http://git-wip-us.apache.org/repos/asf/arrow/blob/21a01915/c_glib/test/test-boolean-array.rb
----------------------------------------------------------------------
diff --git a/c_glib/test/test-boolean-array.rb b/c_glib/test/test-boolean-array.rb
index 43b8365..622e4e9 100644
--- a/c_glib/test/test-boolean-array.rb
+++ b/c_glib/test/test-boolean-array.rb
@@ -17,6 +17,7 @@
 
 class TestBooleanArray < Test::Unit::TestCase
   include Helper::Buildable
+  include Helper::Omittable
 
   def test_new
     assert_equal(build_boolean_array([true, false, nil]),
@@ -41,4 +42,14 @@ class TestBooleanArray < Test::Unit::TestCase
     array = builder.finish
     assert_equal(true, array.get_value(0))
   end
+
+  def test_values
+    require_gi(3, 1, 9)
+    builder = Arrow::BooleanArrayBuilder.new
+    builder.append(true)
+    builder.append(false)
+    builder.append(true)
+    array = builder.finish
+    assert_equal([true, false, true], array.values)
+  end
 end


Mime
View raw message