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/10 03:56:37 UTC

[arrow] branch master updated: ARROW-6188: [GLib] Add garrow_array_is_in()

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 af9e583  ARROW-6188: [GLib] Add garrow_array_is_in()
af9e583 is described below

commit af9e58307d3e656f15ced297c30fea56c5bdf9fd
Author: Yosuke Shiro <yo...@gmail.com>
AuthorDate: Sat Aug 10 12:56:22 2019 +0900

    ARROW-6188: [GLib] Add garrow_array_is_in()
    
    Closes #5047 from shiro615/glib-isin and squashes the following commits:
    
    a9d843286 <Yosuke Shiro> Use different size array in test cases
    ebb1ff52d <Yosuke Shiro> Rename to garrow_array_is_in()
    49cbdc2bc <Yosuke Shiro>  Add garrow_array_isin()
    
    Authored-by: Yosuke Shiro <yo...@gmail.com>
    Signed-off-by: Sutou Kouhei <ko...@clear-code.com>
---
 c_glib/arrow-glib/compute.cpp | 36 ++++++++++++++++++++++++++++++++
 c_glib/arrow-glib/compute.h   |  5 +++++
 c_glib/test/test-is-in.rb     | 48 +++++++++++++++++++++++++++++++++++++++++++
 cpp/src/arrow/compute/api.h   |  1 +
 4 files changed, 90 insertions(+)

diff --git a/c_glib/arrow-glib/compute.cpp b/c_glib/arrow-glib/compute.cpp
index 06adbb3..b489913 100644
--- a/c_glib/arrow-glib/compute.cpp
+++ b/c_glib/arrow-glib/compute.cpp
@@ -1412,6 +1412,42 @@ garrow_array_filter(GArrowArray *array,
   }
 }
 
+/**
+ * garrow_array_is_in:
+ * @left: A left hand side #GArrowArray.
+ * @right: A right hand side #GArrowArray.
+ * @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 array.
+ *
+ * Since: 0.15.0
+ */
+GArrowBooleanArray *
+garrow_array_is_in(GArrowArray *left,
+                   GArrowArray *right,
+                   GError **error)
+{
+  auto arrow_left = garrow_array_get_raw(left);
+  auto arrow_left_datum = arrow::compute::Datum(arrow_left);
+  auto arrow_right = garrow_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][isin]")) {
+    auto arrow_array = arrow_datum.make_array();
+    return GARROW_BOOLEAN_ARRAY(garrow_array_new_raw(&arrow_array));
+  } else {
+    return NULL;
+  }
+}
+
 G_END_DECLS
 
 GArrowCastOptions *
diff --git a/c_glib/arrow-glib/compute.h b/c_glib/arrow-glib/compute.h
index 3f771b3..3a0b3a8 100644
--- a/c_glib/arrow-glib/compute.h
+++ b/c_glib/arrow-glib/compute.h
@@ -253,5 +253,10 @@ GArrowArray *
 garrow_array_filter(GArrowArray *array,
                     GArrowBooleanArray *filter,
                     GError **error);
+GARROW_AVAILABLE_IN_0_15
+GArrowBooleanArray *
+garrow_array_is_in(GArrowArray *left,
+                   GArrowArray *right,
+                   GError **error);
 
 G_END_DECLS
diff --git a/c_glib/test/test-is-in.rb b/c_glib/test/test-is-in.rb
new file mode 100644
index 0000000..1af6ac0
--- /dev/null
+++ b/c_glib/test/test-is-in.rb
@@ -0,0 +1,48 @@
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements.  See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership.  The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License.  You may obtain a copy of the License at
+#
+#   http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied.  See the License for the
+# specific language governing permissions and limitations
+# under the License.
+
+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
+
+  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_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))
+  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))
+  end
+end
diff --git a/cpp/src/arrow/compute/api.h b/cpp/src/arrow/compute/api.h
index 66cd468..bf5de84 100644
--- a/cpp/src/arrow/compute/api.h
+++ b/cpp/src/arrow/compute/api.h
@@ -27,6 +27,7 @@
 #include "arrow/compute/kernels/count.h"    // IWYU pragma: export
 #include "arrow/compute/kernels/filter.h"   // IWYU pragma: export
 #include "arrow/compute/kernels/hash.h"     // IWYU pragma: export
+#include "arrow/compute/kernels/isin.h"     // IWYU pragma: export
 #include "arrow/compute/kernels/mean.h"     // IWYU pragma: export
 #include "arrow/compute/kernels/sum.h"      // IWYU pragma: export
 #include "arrow/compute/kernels/take.h"     // IWYU pragma: export