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 2019/08/15 21:35:05 UTC

[arrow] branch master updated: ARROW-6204: [GLib] Add garrow_array_is_in_chunked_array()

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 9a6c82e  ARROW-6204: [GLib] Add garrow_array_is_in_chunked_array()
9a6c82e is described below

commit 9a6c82e9799cfb213f8103dfacaf36f5a30f4be8
Author: Yosuke Shiro <yo...@gmail.com>
AuthorDate: Fri Aug 16 06:34:52 2019 +0900

    ARROW-6204: [GLib] Add garrow_array_is_in_chunked_array()
    
    This is follow-up of https://github.com/apache/arrow/pull/5047#issuecomment-520103706.
    
    Closes #5086 from shiro615/glib-isin-chunked-array and squashes the following commits:
    
    6724dfdc4 <Yosuke Shiro> Simplify
    6d5105a73 <Yosuke Shiro> Fix documents
    798b6ed85 <Yosuke Shiro> Fix test cases for Arrow::Array#is_in_chunked_array
    ad98fd972 <Yosuke Shiro> Add garrow_array_is_in_chunked_array()
    
    Authored-by: Yosuke Shiro <yo...@gmail.com>
    Signed-off-by: Sutou Kouhei <ko...@clear-code.com>
---
 c_glib/arrow-glib/compute.cpp | 39 +++++++++++++++++-
 c_glib/arrow-glib/compute.h   |  6 +++
 c_glib/test/test-is-in.rb     | 92 ++++++++++++++++++++++++++++++++-----------
 3 files changed, 114 insertions(+), 23 deletions(-)

diff --git a/c_glib/arrow-glib/compute.cpp b/c_glib/arrow-glib/compute.cpp
index b489913..fb33e72 100644
--- a/c_glib/arrow-glib/compute.cpp
+++ b/c_glib/arrow-glib/compute.cpp
@@ -25,6 +25,7 @@
 
 #include <arrow-glib/array.hpp>
 #include <arrow-glib/compute.hpp>
+#include <arrow-glib/chunked-array.hpp>
 #include <arrow-glib/data-type.hpp>
 #include <arrow-glib/enums.h>
 #include <arrow-glib/error.hpp>
@@ -1440,7 +1441,43 @@ garrow_array_is_in(GArrowArray *left,
                                      arrow_left_datum,
                                      arrow_right_datum,
                                      &arrow_datum);
-  if (garrow_error_check(error, status, "[array][isin]")) {
+  if (garrow_error_check(error, status, "[array][is-in]")) {
+    auto arrow_array = arrow_datum.make_array();
+    return GARROW_BOOLEAN_ARRAY(garrow_array_new_raw(&arrow_array));
+  } else {
+    return NULL;
+  }
+}
+
+/**
+ * garrow_array_is_in_chunked_array:
+ * @left: A left hand side #GArrowArray.
+ * @right: A right hand side #GArrowChunkedArray.
+ * @error: (nullable): Return location for a #GError or %NULL.
+ *
+ * Returns: (nullable) (transfer full): The #GArrowBooleanArray
+ *   showing whether each element in the left array is contained
+ *   in right chunked array.
+ *
+ * Since: 0.15.0
+ */
+GArrowBooleanArray *
+garrow_array_is_in_chunked_array(GArrowArray *left,
+                                 GArrowChunkedArray *right,
+                                 GError **error)
+{
+  auto arrow_left = garrow_array_get_raw(left);
+  auto arrow_left_datum = arrow::compute::Datum(arrow_left);
+  auto arrow_right = garrow_chunked_array_get_raw(right);
+  auto arrow_right_datum = arrow::compute::Datum(arrow_right);
+  auto memory_pool = arrow::default_memory_pool();
+  arrow::compute::FunctionContext context(memory_pool);
+  arrow::compute::Datum arrow_datum;
+  auto status = arrow::compute::IsIn(&context,
+                                     arrow_left_datum,
+                                     arrow_right_datum,
+                                     &arrow_datum);
+  if (garrow_error_check(error, status, "[array][is-in-chunked-array]")) {
     auto arrow_array = arrow_datum.make_array();
     return GARROW_BOOLEAN_ARRAY(garrow_array_new_raw(&arrow_array));
   } else {
diff --git a/c_glib/arrow-glib/compute.h b/c_glib/arrow-glib/compute.h
index 3a0b3a8..79e43e8 100644
--- a/c_glib/arrow-glib/compute.h
+++ b/c_glib/arrow-glib/compute.h
@@ -20,6 +20,7 @@
 #pragma once
 
 #include <arrow-glib/array.h>
+#include <arrow-glib/chunked-array.h>
 
 G_BEGIN_DECLS
 
@@ -258,5 +259,10 @@ GArrowBooleanArray *
 garrow_array_is_in(GArrowArray *left,
                    GArrowArray *right,
                    GError **error);
+GARROW_AVAILABLE_IN_0_15
+GArrowBooleanArray *
+garrow_array_is_in_chunked_array(GArrowArray *left,
+                                 GArrowChunkedArray *right,
+                                 GError **error);
 
 G_END_DECLS
diff --git a/c_glib/test/test-is-in.rb b/c_glib/test/test-is-in.rb
index 1af6ac0..5b1b360 100644
--- a/c_glib/test/test-is-in.rb
+++ b/c_glib/test/test-is-in.rb
@@ -18,31 +18,79 @@
 class TestIsIn < Test::Unit::TestCase
   include Helper::Buildable
 
-  def test_no_null
-    left_array = build_int16_array([1, 0, 1, 2])
-    right_array = build_int16_array([2, 0])
-    assert_equal(build_boolean_array([false, true, false, true]),
-                 left_array.is_in(right_array))
-  end
+  sub_test_case("Array") do
+    def test_no_null
+      left = build_int16_array([1, 0, 1, 2])
+      right = build_int16_array([2, 0])
+      assert_equal(build_boolean_array([false, true, false, true]),
+                   left.is_in(right))
+    end
 
-  def test_null_in_left_array
-    left_array = build_int16_array([1, 0, nil, 2])
-    right_array = build_int16_array([2, 0, 3])
-    assert_equal(build_boolean_array([false, true, nil, true]),
-                 left_array.is_in(right_array))
-  end
+    def test_null_in_left
+      left = build_int16_array([1, 0, nil, 2])
+      right = build_int16_array([2, 0, 3])
+      assert_equal(build_boolean_array([false, true, nil, true]),
+                   left.is_in(right))
+    end
+
+    def test_null_in_right
+      left = build_int16_array([1, 0, 1, 2])
+      right = build_int16_array([2, 0, nil, 2, 0])
+      assert_equal(build_boolean_array([false, true, false, true]),
+                   left.is_in(right))
+    end
 
-  def test_null_in_right_array
-    left_array = build_int16_array([1, 0, 1, 2])
-    right_array = build_int16_array([2, 0, nil, 2, 0])
-    assert_equal(build_boolean_array([false, true, false, true]),
-                 left_array.is_in(right_array))
+    def test_null_in_both
+      left = build_int16_array([1, 0, nil, 2])
+      right = build_int16_array([2, 0, nil, 2, 0, nil])
+      assert_equal(build_boolean_array([false, true, true, true]),
+                   left.is_in(right))
+    end
   end
 
-  def test_null_in_both_arrays
-    left_array = build_int16_array([1, 0, nil, 2])
-    right_array = build_int16_array([2, 0, nil, 2, 0, nil])
-    assert_equal(build_boolean_array([false, true, true, true]),
-                 left_array.is_in(right_array))
+  sub_test_case("ChunkedArray") do
+    def test_no_null
+      left = build_int16_array([1, 0, 1, 2])
+      chunks = [
+        build_int16_array([1, 0]),
+        build_int16_array([1, 0, 3])
+      ]
+      right = Arrow::ChunkedArray.new(chunks)
+      assert_equal(build_boolean_array([true, true, true, false]),
+                   left.is_in_chunked_array(right))
+    end
+
+    def test_null_in_left
+      left = build_int16_array([1, 0, nil, 2])
+      chunks = [
+        build_int16_array([2, 0, 3]),
+        build_int16_array([3, 0, 2, 2])
+      ]
+      right = Arrow::ChunkedArray.new(chunks)
+      assert_equal(build_boolean_array([false, true, nil, true]),
+                   left.is_in_chunked_array(right))
+    end
+
+    def test_null_in_right
+      left = build_int16_array([1, 0, 1, 2])
+      chunks = [
+        build_int16_array([2, 0, nil, 2, 0]),
+        build_int16_array([2, 3, nil])
+      ]
+      right = Arrow::ChunkedArray.new(chunks)
+      assert_equal(build_boolean_array([false, true, false, true]),
+                   left.is_in_chunked_array(right))
+    end
+
+    def test_null_in_both
+      left = build_int16_array([1, 0, nil, 2])
+      chunks = [
+        build_int16_array([2, 0, nil, 2, 0, nil]),
+        build_int16_array([2, 3, nil])
+      ]
+      right = Arrow::ChunkedArray.new(chunks)
+      assert_equal(build_boolean_array([false, true, true, true]),
+                   left.is_in_chunked_array(right))
+    end
   end
 end