This is an automated email from the ASF dual-hosted git repository.
shiro 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 c1debde ARROW-4835: [GLib] Add boolean operations
c1debde is described below
commit c1debdea66f6b4ea877f8e4053c07996504419d0
Author: Kouhei Sutou <[email protected]>
AuthorDate: Wed Mar 13 09:06:51 2019 +0900
ARROW-4835: [GLib] Add boolean operations
Author: Kouhei Sutou <[email protected]>
Closes #3873 from kou/glib-boolean and squashes the following commits:
16923a14 <Kouhei Sutou> Fix lint
792b9eb2 <Kouhei Sutou> Add boolean operations
---
c_glib/arrow-glib/basic-array.cpp | 137 ++++++++++++++++++++++++++++++++++++++
c_glib/arrow-glib/basic-array.h | 19 ++++++
c_glib/test/test-boolean-array.rb | 26 ++++++++
cpp/src/arrow/compute/api.h | 5 +-
4 files changed, 185 insertions(+), 2 deletions(-)
diff --git a/c_glib/arrow-glib/basic-array.cpp
b/c_glib/arrow-glib/basic-array.cpp
index 9aebd9c..7409945 100644
--- a/c_glib/arrow-glib/basic-array.cpp
+++ b/c_glib/arrow-glib/basic-array.cpp
@@ -787,6 +787,143 @@ garrow_boolean_array_get_values(GArrowBooleanArray *array,
return values;
}
+/**
+ * garrow_boolean_array_invert:
+ * @array: A #GArrowBooleanArray.
+ * @error: (nullable): Return location for a #GError or %NULL.
+ *
+ * Returns: (transfer full): The element-wise inverted boolean array.
+ *
+ * It should be freed with g_object_unref() when no longer needed.
+ *
+ * Since: 0.13.0
+ */
+GArrowBooleanArray *
+garrow_boolean_array_invert(GArrowBooleanArray *array,
+ GError **error)
+{
+ auto arrow_array = garrow_array_get_raw(GARROW_ARRAY(array));
+ auto datum = arrow::compute::Datum(arrow_array);
+ auto memory_pool = arrow::default_memory_pool();
+ arrow::compute::FunctionContext context(memory_pool);
+ arrow::compute::Datum inverted_datum;
+ auto status = arrow::compute::Invert(&context, datum, &inverted_datum);
+ if (garrow_error_check(error, status, "[boolean-array][invert]")) {
+ auto arrow_inverted_array = inverted_datum.make_array();
+ return GARROW_BOOLEAN_ARRAY(garrow_array_new_raw(&arrow_inverted_array));
+ } else {
+ return NULL;
+ }
+}
+
+/**
+ * garrow_boolean_array_and:
+ * @left: A left hand side #GArrowBooleanArray.
+ * @right: A right hand side #GArrowBooleanArray.
+ * @error: (nullable): Return location for a #GError or %NULL.
+ *
+ * Returns: (transfer full): The element-wise AND operated boolean array.
+ *
+ * It should be freed with g_object_unref() when no longer needed.
+ *
+ * Since: 0.13.0
+ */
+GArrowBooleanArray *
+garrow_boolean_array_and(GArrowBooleanArray *left,
+ GArrowBooleanArray *right,
+ GError **error)
+{
+ auto arrow_left = garrow_array_get_raw(GARROW_ARRAY(left));
+ auto left_datum = arrow::compute::Datum(arrow_left);
+ auto arrow_right = garrow_array_get_raw(GARROW_ARRAY(right));
+ auto right_datum = arrow::compute::Datum(arrow_right);
+ auto memory_pool = arrow::default_memory_pool();
+ arrow::compute::FunctionContext context(memory_pool);
+ arrow::compute::Datum operated_datum;
+ auto status = arrow::compute::And(&context,
+ left_datum,
+ right_datum,
+ &operated_datum);
+ if (garrow_error_check(error, status, "[boolean-array][and]")) {
+ auto arrow_operated_array = operated_datum.make_array();
+ return GARROW_BOOLEAN_ARRAY(garrow_array_new_raw(&arrow_operated_array));
+ } else {
+ return NULL;
+ }
+}
+
+/**
+ * garrow_boolean_array_or:
+ * @left: A left hand side #GArrowBooleanArray.
+ * @right: A right hand side #GArrowBooleanArray.
+ * @error: (nullable): Return location for a #GError or %NULL.
+ *
+ * Returns: (transfer full): The element-wise OR operated boolean array.
+ *
+ * It should be freed with g_object_unref() when no longer needed.
+ *
+ * Since: 0.13.0
+ */
+GArrowBooleanArray *
+garrow_boolean_array_or(GArrowBooleanArray *left,
+ GArrowBooleanArray *right,
+ GError **error)
+{
+ auto arrow_left = garrow_array_get_raw(GARROW_ARRAY(left));
+ auto left_datum = arrow::compute::Datum(arrow_left);
+ auto arrow_right = garrow_array_get_raw(GARROW_ARRAY(right));
+ auto right_datum = arrow::compute::Datum(arrow_right);
+ auto memory_pool = arrow::default_memory_pool();
+ arrow::compute::FunctionContext context(memory_pool);
+ arrow::compute::Datum operated_datum;
+ auto status = arrow::compute::Or(&context,
+ left_datum,
+ right_datum,
+ &operated_datum);
+ if (garrow_error_check(error, status, "[boolean-array][or]")) {
+ auto arrow_operated_array = operated_datum.make_array();
+ return GARROW_BOOLEAN_ARRAY(garrow_array_new_raw(&arrow_operated_array));
+ } else {
+ return NULL;
+ }
+}
+
+/**
+ * garrow_boolean_array_xor:
+ * @left: A left hand side #GArrowBooleanArray.
+ * @right: A right hand side #GArrowBooleanArray.
+ * @error: (nullable): Return location for a #GError or %NULL.
+ *
+ * Returns: (transfer full): The element-wise XOR operated boolean array.
+ *
+ * It should be freed with g_object_unref() when no longer needed.
+ *
+ * Since: 0.13.0
+ */
+GArrowBooleanArray *
+garrow_boolean_array_xor(GArrowBooleanArray *left,
+ GArrowBooleanArray *right,
+ GError **error)
+{
+ auto arrow_left = garrow_array_get_raw(GARROW_ARRAY(left));
+ auto left_datum = arrow::compute::Datum(arrow_left);
+ auto arrow_right = garrow_array_get_raw(GARROW_ARRAY(right));
+ auto right_datum = arrow::compute::Datum(arrow_right);
+ auto memory_pool = arrow::default_memory_pool();
+ arrow::compute::FunctionContext context(memory_pool);
+ arrow::compute::Datum operated_datum;
+ auto status = arrow::compute::Xor(&context,
+ left_datum,
+ right_datum,
+ &operated_datum);
+ if (garrow_error_check(error, status, "[boolean-array][xor]")) {
+ auto arrow_operated_array = operated_datum.make_array();
+ return GARROW_BOOLEAN_ARRAY(garrow_array_new_raw(&arrow_operated_array));
+ } else {
+ return NULL;
+ }
+}
+
G_DEFINE_TYPE(GArrowNumericArray,
garrow_numeric_array,
diff --git a/c_glib/arrow-glib/basic-array.h b/c_glib/arrow-glib/basic-array.h
index 78a004e..592699d 100644
--- a/c_glib/arrow-glib/basic-array.h
+++ b/c_glib/arrow-glib/basic-array.h
@@ -181,6 +181,25 @@ gboolean garrow_boolean_array_get_value
(GArrowBooleanArray *array,
gint64 i);
gboolean *garrow_boolean_array_get_values(GArrowBooleanArray *array,
gint64 *length);
+GARROW_AVAILABLE_IN_0_13
+GArrowBooleanArray *
+garrow_boolean_array_invert(GArrowBooleanArray *array,
+ GError **error);
+GARROW_AVAILABLE_IN_0_13
+GArrowBooleanArray *
+garrow_boolean_array_and(GArrowBooleanArray *left,
+ GArrowBooleanArray *right,
+ GError **error);
+GARROW_AVAILABLE_IN_0_13
+GArrowBooleanArray *
+garrow_boolean_array_or(GArrowBooleanArray *left,
+ GArrowBooleanArray *right,
+ GError **error);
+GARROW_AVAILABLE_IN_0_13
+GArrowBooleanArray *
+garrow_boolean_array_xor(GArrowBooleanArray *left,
+ GArrowBooleanArray *right,
+ GError **error);
#define GARROW_TYPE_NUMERIC_ARRAY (garrow_numeric_array_get_type())
G_DECLARE_DERIVABLE_TYPE(GArrowNumericArray,
diff --git a/c_glib/test/test-boolean-array.rb
b/c_glib/test/test-boolean-array.rb
index e8c7e5e..4a80f94 100644
--- a/c_glib/test/test-boolean-array.rb
+++ b/c_glib/test/test-boolean-array.rb
@@ -52,4 +52,30 @@ class TestBooleanArray < Test::Unit::TestCase
array = builder.finish
assert_equal([true, false, true], array.values)
end
+
+ def test_invert
+ assert_equal(build_boolean_array([true, nil, false]),
+ build_boolean_array([false, nil, true]).invert)
+ end
+
+ def test_and
+ left = build_boolean_array([true, false, nil, true])
+ right = build_boolean_array([true, nil, true, false])
+ assert_equal(build_boolean_array([true, nil, nil, false]),
+ left.and(right))
+ end
+
+ def test_or
+ left = build_boolean_array([true, false, nil, false])
+ right = build_boolean_array([false, nil, true, false])
+ assert_equal(build_boolean_array([true, nil, nil, false]),
+ left.or(right))
+ end
+
+ def test_xor
+ left = build_boolean_array([true, false, nil, true])
+ right = build_boolean_array([false, nil, true, true])
+ assert_equal(build_boolean_array([true, nil, nil, false]),
+ left.xor(right))
+ end
end
diff --git a/cpp/src/arrow/compute/api.h b/cpp/src/arrow/compute/api.h
index 8ef3ea4..cd5f11e 100644
--- a/cpp/src/arrow/compute/api.h
+++ b/cpp/src/arrow/compute/api.h
@@ -21,7 +21,8 @@
#include "arrow/compute/context.h" // IWYU pragma: export
#include "arrow/compute/kernel.h" // IWYU pragma: export
-#include "arrow/compute/kernels/cast.h" // IWYU pragma: export
-#include "arrow/compute/kernels/hash.h" // IWYU pragma: export
+#include "arrow/compute/kernels/boolean.h" // IWYU pragma: export
+#include "arrow/compute/kernels/cast.h" // IWYU pragma: export
+#include "arrow/compute/kernels/hash.h" // IWYU pragma: export
#endif // ARROW_COMPUTE_API_H