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/07 21:25:01 UTC

[arrow] branch master updated: ARROW-6039: [GLib] Add garrow_array_filter()

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 6110ba6  ARROW-6039: [GLib] Add garrow_array_filter()
6110ba6 is described below

commit 6110ba60d473521d4e7157089909d9f48c360d24
Author: Yosuke Shiro <yo...@gmail.com>
AuthorDate: Thu Aug 8 06:24:31 2019 +0900

    ARROW-6039: [GLib] Add garrow_array_filter()
    
    This PR add support for boolean selection filter.
    
    Closes #5025 from shiro615/glib-boolean-filter and squashes the following commits:
    
    c14b75ce7 <Yosuke Shiro> Use a nil value in filter for a test case
    0ce27176a <Yosuke Shiro> Pass GArrowBooleanArray for garrow_array_filter()
    28ffe8d75 <Yosuke Shiro> Use 0.15.0 version check macros
    113f70d3c <Yosuke Shiro> Add garrow_array_filter()
    
    Authored-by: Yosuke Shiro <yo...@gmail.com>
    Signed-off-by: Sutou Kouhei <ko...@clear-code.com>
---
 c_glib/arrow-glib/compute.cpp             | 34 +++++++++++++++++++++++++++++++
 c_glib/arrow-glib/compute.h               |  5 +++++
 c_glib/arrow-glib/version.h.in            | 23 +++++++++++++++++++++
 c_glib/doc/arrow-glib/arrow-glib-docs.xml |  4 ++++
 c_glib/test/test-filter.rb                | 33 ++++++++++++++++++++++++++++++
 cpp/src/arrow/compute/api.h               |  1 +
 6 files changed, 100 insertions(+)

diff --git a/c_glib/arrow-glib/compute.cpp b/c_glib/arrow-glib/compute.cpp
index c97485f..06adbb3 100644
--- a/c_glib/arrow-glib/compute.cpp
+++ b/c_glib/arrow-glib/compute.cpp
@@ -1377,6 +1377,40 @@ garrow_double_array_compare(GArrowDoubleArray *array,
                                       "[double-array][compare]");
 }
 
+/**
+ * garrow_array_filter:
+ * @array: A #GArrowArray.
+ * @filter: The values indicates which values should be filtered out.
+ * @error: (nullable): Return location for a #GError or %NULL.
+ *
+ * Returns: (nullable) (transfer full): The #GArrowArray filterd
+ *   with a boolean selection filter. Nulls in the filter will
+ *   result in nulls in the output.
+ *
+ * Since: 0.15.0
+ */
+GArrowArray *
+garrow_array_filter(GArrowArray *array,
+                    GArrowBooleanArray *filter,
+                    GError **error)
+{
+  auto arrow_array = garrow_array_get_raw(array);
+  auto arrow_array_raw = arrow_array.get();
+  auto arrow_filter = garrow_array_get_raw(GARROW_ARRAY(filter));
+  auto arrow_filter_raw = arrow_filter.get();
+  auto memory_pool = arrow::default_memory_pool();
+  arrow::compute::FunctionContext context(memory_pool);
+  std::shared_ptr<arrow::Array> arrow_filtered_array;
+  auto status = arrow::compute::Filter(&context,
+                                       *arrow_array_raw,
+                                       *arrow_filter_raw,
+                                       &arrow_filtered_array);
+  if (garrow_error_check(error, status, "[array][filter]")) {
+    return garrow_array_new_raw(&arrow_filtered_array);
+  } else {
+    return NULL;
+  }
+}
 
 G_END_DECLS
 
diff --git a/c_glib/arrow-glib/compute.h b/c_glib/arrow-glib/compute.h
index 79d4b63..3f771b3 100644
--- a/c_glib/arrow-glib/compute.h
+++ b/c_glib/arrow-glib/compute.h
@@ -248,5 +248,10 @@ garrow_double_array_compare(GArrowDoubleArray *array,
                             gdouble value,
                             GArrowCompareOptions *options,
                             GError **error);
+GARROW_AVAILABLE_IN_0_15
+GArrowArray *
+garrow_array_filter(GArrowArray *array,
+                    GArrowBooleanArray *filter,
+                    GError **error);
 
 G_END_DECLS
diff --git a/c_glib/arrow-glib/version.h.in b/c_glib/arrow-glib/version.h.in
index dc925dd..aaa6ec8 100644
--- a/c_glib/arrow-glib/version.h.in
+++ b/c_glib/arrow-glib/version.h.in
@@ -120,6 +120,15 @@
 #define GARROW_VERSION_1_0 G_ENCODE_VERSION(1, 0)
 
 /**
+ * GARROW_VERSION_0_15:
+ *
+ * You can use this macro value for compile time API version check.
+ *
+ * Since: 0.15.0
+ */
+#define GARROW_VERSION_0_15 G_ENCODE_VERSION(0, 15)
+
+/**
  * GARROW_VERSION_0_14:
  *
  * You can use this macro value for compile time API version check.
@@ -216,6 +225,20 @@
 #  define GARROW_AVAILABLE_IN_1_0
 #endif
 
+#if GARROW_VERSION_MIN_REQUIRED >= GARROW_VERSION_0_15
+#  define GARROW_DEPRECATED_IN_0_15               GARROW_DEPRECATED
+#  define GARROW_DEPRECATED_IN_0_15_FOR(function) GARROW_DEPRECATED_FOR(function)
+#else
+#  define GARROW_DEPRECATED_IN_0_15
+#  define GARROW_DEPRECATED_IN_0_15_FOR(function)
+#endif
+
+#if GARROW_VERSION_MAX_ALLOWED < GARROW_VERSION_0_15
+#  define GARROW_AVAILABLE_IN_0_15 GARROW_UNAVAILABLE(0, 15)
+#else
+#  define GARROW_AVAILABLE_IN_0_15
+#endif
+
 #if GARROW_VERSION_MIN_REQUIRED >= GARROW_VERSION_0_14
 #  define GARROW_DEPRECATED_IN_0_14               GARROW_DEPRECATED
 #  define GARROW_DEPRECATED_IN_0_14_FOR(function) GARROW_DEPRECATED_FOR(function)
diff --git a/c_glib/doc/arrow-glib/arrow-glib-docs.xml b/c_glib/doc/arrow-glib/arrow-glib-docs.xml
index 47e96a4..69c7bb5 100644
--- a/c_glib/doc/arrow-glib/arrow-glib-docs.xml
+++ b/c_glib/doc/arrow-glib/arrow-glib-docs.xml
@@ -163,6 +163,10 @@
     <title>Index of new symbols in 1.0.0</title>
     <xi:include href="xml/api-index-1.0.0.xml"><xi:fallback /></xi:include>
   </index>
+  <index id="api-index-0-15-0" role="0.15.0">
+    <title>Index of new symbols in 0.15.0</title>
+    <xi:include href="xml/api-index-0.15.0.xml"><xi:fallback /></xi:include>
+  </index>
   <index id="api-index-0-14-0" role="0.14.0">
     <title>Index of new symbols in 0.14.0</title>
     <xi:include href="xml/api-index-0.14.0.xml"><xi:fallback /></xi:include>
diff --git a/c_glib/test/test-filter.rb b/c_glib/test/test-filter.rb
new file mode 100644
index 0000000..e5c07cf
--- /dev/null
+++ b/c_glib/test/test-filter.rb
@@ -0,0 +1,33 @@
+# 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 TestFilter < Test::Unit::TestCase
+  include Helper::Buildable
+
+  def test_filter
+    filter = build_boolean_array([false, true, true, nil])
+    assert_equal(build_int16_array([1, 0, nil]),
+                 build_int16_array([0, 1, 0, 2]).filter(filter))
+  end
+
+  def test_invalid_array_length
+    filter = build_boolean_array([false, true, true, false])
+    assert_raise(Arrow::Error::Invalid) do
+      build_int16_array([0, 1, 0]).filter(filter)
+    end
+  end
+end
diff --git a/cpp/src/arrow/compute/api.h b/cpp/src/arrow/compute/api.h
index 2a2e79f..66cd468 100644
--- a/cpp/src/arrow/compute/api.h
+++ b/cpp/src/arrow/compute/api.h
@@ -25,6 +25,7 @@
 #include "arrow/compute/kernels/cast.h"     // IWYU pragma: export
 #include "arrow/compute/kernels/compare.h"  // IWYU pragma: export
 #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/mean.h"     // IWYU pragma: export
 #include "arrow/compute/kernels/sum.h"      // IWYU pragma: export