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 201a3bc  ARROW-4929: [GLib] Add garrow_array_count_values()
201a3bc is described below

commit 201a3bc9186aecd3b22529d97af30ac1fab25a3a
Author: Kouhei Sutou <k...@clear-code.com>
AuthorDate: Mon Mar 18 08:39:42 2019 +0900

    ARROW-4929: [GLib] Add garrow_array_count_values()
    
    Author: Kouhei Sutou <k...@clear-code.com>
    
    Closes #3941 from kou/glib-count-values and squashes the following commits:
    
    f9e3bc51 <Kouhei Sutou> Don't use special characters in HTML
    321fe28a <Kouhei Sutou> Move compute related code to compute.{cpp,h}
    c8bd73bc <Kouhei Sutou> Add missing (nullable) attribute
    7ff43645 <Kouhei Sutou> Fix a typo
    18b8d89e <Kouhei Sutou> Fix markup
    95c08075 <Kouhei Sutou>  Add garrow_array_count_values()
---
 c_glib/arrow-glib/basic-array.cpp         | 570 ----------------------------
 c_glib/arrow-glib/basic-array.h           |  66 ----
 c_glib/arrow-glib/composite-array.h       |  43 +--
 c_glib/arrow-glib/compute.cpp             | 612 +++++++++++++++++++++++++++++-
 c_glib/arrow-glib/compute.h               |  71 +++-
 c_glib/doc/arrow-glib/arrow-glib-docs.xml |   5 +-
 c_glib/gandiva-glib/node.cpp              |   2 +-
 c_glib/test/test-count-values.rb          |  51 +++
 8 files changed, 738 insertions(+), 682 deletions(-)

diff --git a/c_glib/arrow-glib/basic-array.cpp 
b/c_glib/arrow-glib/basic-array.cpp
index 8f27e26..b051c97 100644
--- a/c_glib/arrow-glib/basic-array.cpp
+++ b/c_glib/arrow-glib/basic-array.cpp
@@ -24,7 +24,6 @@
 #include <arrow-glib/array.hpp>
 #include <arrow-glib/basic-data-type.hpp>
 #include <arrow-glib/buffer.hpp>
-#include <arrow-glib/compute.hpp>
 #include <arrow-glib/decimal128.hpp>
 #include <arrow-glib/error.hpp>
 #include <arrow-glib/type.hpp>
@@ -83,34 +82,6 @@ garrow_primitive_array_new(GArrowDataType *data_type,
   return garrow_array_new_raw(&arrow_array);
 };
 
-template <typename ArrowType, typename GArrowArrayType>
-typename ArrowType::c_type
-garrow_numeric_array_sum(GArrowArrayType array,
-                         GError **error,
-                         const gchar *tag,
-                         typename ArrowType::c_type default_value)
-{
-  auto arrow_array = garrow_array_get_raw(GARROW_ARRAY(array));
-  auto memory_pool = arrow::default_memory_pool();
-  arrow::compute::FunctionContext context(memory_pool);
-  arrow::compute::Datum sum_datum;
-  auto status = arrow::compute::Sum(&context,
-                                    arrow_array,
-                                    &sum_datum);
-  if (garrow_error_check(error, status, tag)) {
-    using ScalarType = typename arrow::TypeTraits<ArrowType>::ScalarType;
-    auto arrow_numeric_scalar =
-      std::dynamic_pointer_cast<ScalarType>(sum_datum.scalar());
-    if (arrow_numeric_scalar->is_valid) {
-      return arrow_numeric_scalar->value;
-    } else {
-      return default_value;
-    }
-  } else {
-    return default_value;
-  }
-}
-
 G_BEGIN_DECLS
 
 /**
@@ -545,177 +516,6 @@ garrow_array_to_string(GArrowArray *array, GError **error)
   }
 }
 
-/**
- * garrow_array_cast:
- * @array: A #GArrowArray.
- * @target_data_type: A #GArrowDataType of cast target data.
- * @options: (nullable): A #GArrowCastOptions.
- * @error: (nullable): Return location for a #GError or %NULL.
- *
- * Returns: (nullable) (transfer full):
- *   A newly created casted array on success, %NULL on error.
- *
- * Since: 0.7.0
- */
-GArrowArray *
-garrow_array_cast(GArrowArray *array,
-                  GArrowDataType *target_data_type,
-                  GArrowCastOptions *options,
-                  GError **error)
-{
-  auto arrow_array = garrow_array_get_raw(array);
-  auto arrow_array_raw = arrow_array.get();
-  auto memory_pool = arrow::default_memory_pool();
-  arrow::compute::FunctionContext context(memory_pool);
-  auto arrow_target_data_type = garrow_data_type_get_raw(target_data_type);
-  std::shared_ptr<arrow::Array> arrow_casted_array;
-  arrow::Status status;
-  if (options) {
-    auto arrow_options = garrow_cast_options_get_raw(options);
-    status = arrow::compute::Cast(&context,
-                                  *arrow_array_raw,
-                                  arrow_target_data_type,
-                                  *arrow_options,
-                                  &arrow_casted_array);
-  } else {
-    arrow::compute::CastOptions arrow_options;
-    status = arrow::compute::Cast(&context,
-                                  *arrow_array_raw,
-                                  arrow_target_data_type,
-                                  arrow_options,
-                                  &arrow_casted_array);
-  }
-
-  if (!status.ok()) {
-    std::stringstream message;
-    message << "[array][cast] <";
-    message << arrow_array->type()->ToString();
-    message << "> -> <";
-    message << arrow_target_data_type->ToString();
-    message << ">";
-    garrow_error_check(error, status, message.str().c_str());
-    return NULL;
-  }
-
-  return garrow_array_new_raw(&arrow_casted_array);
-}
-
-/**
- * garrow_array_unique:
- * @array: A #GArrowArray.
- * @error: (nullable): Return location for a #GError or %NULL.
- *
- * Returns: (nullable) (transfer full):
- *   A newly created unique elements array on success, %NULL on error.
- *
- * Since: 0.8.0
- */
-GArrowArray *
-garrow_array_unique(GArrowArray *array,
-                    GError **error)
-{
-  auto arrow_array = garrow_array_get_raw(array);
-  auto memory_pool = arrow::default_memory_pool();
-  arrow::compute::FunctionContext context(memory_pool);
-  std::shared_ptr<arrow::Array> arrow_unique_array;
-  auto status = arrow::compute::Unique(&context,
-                                       arrow::compute::Datum(arrow_array),
-                                       &arrow_unique_array);
-  if (!status.ok()) {
-    std::stringstream message;
-    message << "[array][unique] <";
-    message << arrow_array->type()->ToString();
-    message << ">";
-    garrow_error_check(error, status, message.str().c_str());
-    return NULL;
-  }
-
-  return garrow_array_new_raw(&arrow_unique_array);
-}
-
-/**
- * garrow_array_dictionary_encode:
- * @array: A #GArrowArray.
- * @error: (nullable): Return location for a #GError or %NULL.
- *
- * Returns: (nullable) (transfer full):
- *   A newly created #GArrowDictionaryArray for the @array on success,
- *   %NULL on error.
- *
- * Since: 0.8.0
- */
-GArrowArray *
-garrow_array_dictionary_encode(GArrowArray *array,
-                               GError **error)
-{
-  auto arrow_array = garrow_array_get_raw(array);
-  auto memory_pool = arrow::default_memory_pool();
-  arrow::compute::FunctionContext context(memory_pool);
-  arrow::compute::Datum dictionary_encoded_datum;
-  auto status =
-    arrow::compute::DictionaryEncode(&context,
-                                     arrow::compute::Datum(arrow_array),
-                                     &dictionary_encoded_datum);
-  if (!status.ok()) {
-    std::stringstream message;
-    message << "[array][dictionary-encode] <";
-    message << arrow_array->type()->ToString();
-    message << ">";
-    garrow_error_check(error, status, message.str().c_str());
-    return NULL;
-  }
-
-  auto arrow_dictionary_encoded_array =
-    arrow::MakeArray(dictionary_encoded_datum.array());
-
-  return garrow_array_new_raw(&arrow_dictionary_encoded_array);
-}
-
-/**
- * garrow_array_count:
- * @array: A #GArrowArray.
- * @options: (nullable): A #GArrowCountOptions.
- * @error: (nullable): Return location for a #GError or %NULL.
- *
- * Returns: The number of target values on success. If an error is occurred,
- *   the returned value is untrustful value.
- *
- * Since: 0.13.0
- */
-gint64
-garrow_array_count(GArrowArray *array,
-                   GArrowCountOptions *options,
-                   GError **error)
-{
-  auto arrow_array = garrow_array_get_raw(array);
-  auto arrow_array_raw = arrow_array.get();
-  auto memory_pool = arrow::default_memory_pool();
-  arrow::compute::FunctionContext context(memory_pool);
-  arrow::compute::Datum counted_datum;
-  arrow::Status status;
-  if (options) {
-    auto arrow_options = garrow_count_options_get_raw(options);
-    status = arrow::compute::Count(&context,
-                                   *arrow_options,
-                                   *arrow_array_raw,
-                                   &counted_datum);
-  } else {
-    arrow::compute::CountOptions 
arrow_options(arrow::compute::CountOptions::COUNT_ALL);
-    status = arrow::compute::Count(&context,
-                                   arrow_options,
-                                   *arrow_array_raw,
-                                   &counted_datum);
-  }
-
-  if (garrow_error_check(error, status, "[array][count]")) {
-    using ScalarType = typename 
arrow::TypeTraits<arrow::Int64Type>::ScalarType;
-    auto counted_scalar = 
std::dynamic_pointer_cast<ScalarType>(counted_datum.scalar());
-    return counted_scalar->value;
-  } else {
-    return 0;
-  }
-}
-
 
 G_DEFINE_TYPE(GArrowNullArray,
               garrow_null_array,
@@ -860,143 +660,6 @@ 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,
@@ -1012,38 +675,6 @@ garrow_numeric_array_class_init(GArrowNumericArrayClass 
*klass)
 {
 }
 
-/**
- * garrow_numeric_array_mean:
- * @array: A #GArrowNumericArray.
- * @error: (nullable): Return location for a #GError or %NULL.
- *
- * Returns: The value of the computed mean.
- *
- * Since: 0.13.0
- */
-gdouble
-garrow_numeric_array_mean(GArrowNumericArray *array,
-                          GError **error)
-{
-  auto arrow_array = garrow_array_get_raw(GARROW_ARRAY(array));
-  auto memory_pool = arrow::default_memory_pool();
-  arrow::compute::FunctionContext context(memory_pool);
-  arrow::compute::Datum mean_datum;
-  auto status = arrow::compute::Mean(&context, arrow_array, &mean_datum);
-  if (garrow_error_check(error, status, "[numeric-array][mean]")) {
-    using ScalarType = typename 
arrow::TypeTraits<arrow::DoubleType>::ScalarType;
-    auto arrow_numeric_scalar =
-      std::dynamic_pointer_cast<ScalarType>(mean_datum.scalar());
-    if (arrow_numeric_scalar->is_valid) {
-      return arrow_numeric_scalar->value;
-    } else {
-      return 0.0;
-    }
-  } else {
-    return 0.0;
-  }
-}
-
 
 G_DEFINE_TYPE(GArrowInt8Array,
               garrow_int8_array,
@@ -1117,27 +748,6 @@ garrow_int8_array_get_values(GArrowInt8Array *array,
   return garrow_array_get_values_raw<arrow::Int8Type>(arrow_array, length);
 }
 
-/**
- * garrow_int8_array_sum:
- * @array: A #GArrowInt8Array.
- * @error: (nullable): Return location for a #GError or %NULL.
- *
- * Returns: The value of the computed sum on success,
- *   If an error is occurred, the returned value is untrustful value.
- *
- * Since: 0.13.0
- */
-gint64
-garrow_int8_array_sum(GArrowInt8Array *array,
-                      GError **error)
-{
-  return garrow_numeric_array_sum<arrow::Int64Type>(array,
-                                                    error,
-                                                    "[int8-array][sum]",
-                                                    0);
-}
-
-
 G_DEFINE_TYPE(GArrowUInt8Array,
               garrow_uint8_array,
               GARROW_TYPE_NUMERIC_ARRAY)
@@ -1210,26 +820,6 @@ garrow_uint8_array_get_values(GArrowUInt8Array *array,
   return garrow_array_get_values_raw<arrow::UInt8Type>(arrow_array, length);
 }
 
-/**
- * garrow_uint8_array_sum:
- * @array: A #GArrowUInt8Array.
- * @error: (nullable): Return location for a #GError or %NULL.
- *
- * Returns: The value of the computed sum on success,
- *   If an error is occurred, the returned value is untrustful value.
- *
- * Since: 0.13.0
- */
-guint64
-garrow_uint8_array_sum(GArrowUInt8Array *array,
-                       GError **error)
-{
-  return garrow_numeric_array_sum<arrow::UInt64Type>(array,
-                                                     error,
-                                                     "[uint8-array][sum]",
-                                                     0);
-}
-
 
 G_DEFINE_TYPE(GArrowInt16Array,
               garrow_int16_array,
@@ -1303,26 +893,6 @@ garrow_int16_array_get_values(GArrowInt16Array *array,
   return garrow_array_get_values_raw<arrow::Int16Type>(arrow_array, length);
 }
 
-/**
- * garrow_int16_array_sum:
- * @array: A #GArrowInt16Array.
- * @error: (nullable): Return location for a #GError or %NULL.
- *
- * Returns: The value of the computed sum on success,
- *   If an error is occurred, the returned value is untrustful value.
- *
- * Since: 0.13.0
- */
-gint64
-garrow_int16_array_sum(GArrowInt16Array *array,
-                       GError **error)
-{
-  return garrow_numeric_array_sum<arrow::Int64Type>(array,
-                                                    error,
-                                                    "[int16-array][sum]",
-                                                    0);
-}
-
 
 G_DEFINE_TYPE(GArrowUInt16Array,
               garrow_uint16_array,
@@ -1396,26 +966,6 @@ garrow_uint16_array_get_values(GArrowUInt16Array *array,
   return garrow_array_get_values_raw<arrow::UInt16Type>(arrow_array, length);
 }
 
-/**
- * garrow_uint16_array_sum:
- * @array: A #GArrowUInt16Array.
- * @error: (nullable): Return location for a #GError or %NULL.
- *
- * Returns: The value of the computed sum on success,
- *   If an error is occurred, the returned value is untrustful value.
- *
- * Since: 0.13.0
- */
-guint64
-garrow_uint16_array_sum(GArrowUInt16Array *array,
-                        GError **error)
-{
-  return garrow_numeric_array_sum<arrow::UInt64Type>(array,
-                                                     error,
-                                                     "[uint16-array][sum]",
-                                                     0);
-}
-
 
 G_DEFINE_TYPE(GArrowInt32Array,
               garrow_int32_array,
@@ -1489,26 +1039,6 @@ garrow_int32_array_get_values(GArrowInt32Array *array,
   return garrow_array_get_values_raw<arrow::Int32Type>(arrow_array, length);
 }
 
-/**
- * garrow_int32_array_sum:
- * @array: A #GArrowInt32Array.
- * @error: (nullable): Return location for a #GError or %NULL.
- *
- * Returns: The value of the computed sum on success,
- *   If an error is occurred, the returned value is untrustful value.
- *
- * Since: 0.13.0
- */
-gint64
-garrow_int32_array_sum(GArrowInt32Array *array,
-                       GError **error)
-{
-  return garrow_numeric_array_sum<arrow::Int64Type>(array,
-                                                    error,
-                                                    "[int32-array][sum]",
-                                                    0);
-}
-
 
 G_DEFINE_TYPE(GArrowUInt32Array,
               garrow_uint32_array,
@@ -1582,26 +1112,6 @@ garrow_uint32_array_get_values(GArrowUInt32Array *array,
   return garrow_array_get_values_raw<arrow::UInt32Type>(arrow_array, length);
 }
 
-/**
- * garrow_uint32_array_sum:
- * @array: A #GArrowUInt32Array.
- * @error: (nullable): Return location for a #GError or %NULL.
- *
- * Returns: The value of the computed sum on success,
- *   If an error is occurred, the returned value is untrustful value.
- *
- * Since: 0.13.0
- */
-guint64
-garrow_uint32_array_sum(GArrowUInt32Array *array,
-                        GError **error)
-{
-  return garrow_numeric_array_sum<arrow::UInt64Type>(array,
-                                                    error,
-                                                    "[uint32-array][sum]",
-                                                    0);
-}
-
 
 G_DEFINE_TYPE(GArrowInt64Array,
               garrow_int64_array,
@@ -1677,26 +1187,6 @@ garrow_int64_array_get_values(GArrowInt64Array *array,
   return reinterpret_cast<const gint64 *>(values);
 }
 
-/**
- * garrow_int64_array_sum:
- * @array: A #GArrowInt64Array.
- * @error: (nullable): Return location for a #GError or %NULL.
- *
- * Returns: The value of the computed sum on success,
- *   If an error is occurred, the returned value is untrustful value.
- *
- * Since: 0.13.0
- */
-gint64
-garrow_int64_array_sum(GArrowInt64Array *array,
-                       GError **error)
-{
-  return garrow_numeric_array_sum<arrow::Int64Type>(array,
-                                                    error,
-                                                    "[int64-array][sum]",
-                                                    0);
-}
-
 
 G_DEFINE_TYPE(GArrowUInt64Array,
               garrow_uint64_array,
@@ -1772,26 +1262,6 @@ garrow_uint64_array_get_values(GArrowUInt64Array *array,
   return reinterpret_cast<const guint64 *>(values);
 }
 
-/**
- * garrow_uint64_array_sum:
- * @array: A #GArrowUInt64Array.
- * @error: (nullable): Return location for a #GError or %NULL.
- *
- * Returns: The value of the computed sum on success,
- *   If an error is occurred, the returned value is untrustful value.
- *
- * Since: 0.13.0
- */
-guint64
-garrow_uint64_array_sum(GArrowUInt64Array *array,
-                        GError **error)
-{
-  return garrow_numeric_array_sum<arrow::UInt64Type>(array,
-                                                    error,
-                                                    "[uint64-array][sum]",
-                                                    0);
-}
-
 
 G_DEFINE_TYPE(GArrowFloatArray,
               garrow_float_array,
@@ -1865,26 +1335,6 @@ garrow_float_array_get_values(GArrowFloatArray *array,
   return garrow_array_get_values_raw<arrow::FloatType>(arrow_array, length);
 }
 
-/**
- * garrow_float_array_sum:
- * @array: A #GArrowFloatArray.
- * @error: (nullable): Return location for a #GError or %NULL.
- *
- * Returns: The value of the computed sum on success,
- *   If an error is occurred, the returned value is untrustful value.
- *
- * Since: 0.13.0
- */
-gdouble
-garrow_float_array_sum(GArrowFloatArray *array,
-                       GError **error)
-{
-  return garrow_numeric_array_sum<arrow::DoubleType>(array,
-                                                     error,
-                                                     "[float-array][sum]",
-                                                     0);
-}
-
 
 G_DEFINE_TYPE(GArrowDoubleArray,
               garrow_double_array,
@@ -1958,26 +1408,6 @@ garrow_double_array_get_values(GArrowDoubleArray *array,
   return garrow_array_get_values_raw<arrow::DoubleType>(arrow_array, length);
 }
 
-/**
- * garrow_double_array_sum:
- * @array: A #GArrowDoubleArray.
- * @error: (nullable): Return location for a #GError or %NULL.
- *
- * Returns: The value of the computed sum on success,
- *   If an error is occurred, the returned value is untrustful value.
- *
- * Since: 0.13.0
- */
-gdouble
-garrow_double_array_sum(GArrowDoubleArray *array,
-                        GError **error)
-{
-  return garrow_numeric_array_sum<arrow::DoubleType>(array,
-                                                     error,
-                                                     "[double-array][sum]",
-                                                     0);
-}
-
 
 G_DEFINE_TYPE(GArrowBinaryArray,
               garrow_binary_array,
diff --git a/c_glib/arrow-glib/basic-array.h b/c_glib/arrow-glib/basic-array.h
index 00ec773..33a1f1c 100644
--- a/c_glib/arrow-glib/basic-array.h
+++ b/c_glib/arrow-glib/basic-array.h
@@ -20,7 +20,6 @@
 #pragma once
 
 #include <arrow-glib/buffer.h>
-#include <arrow-glib/compute.h>
 #include <arrow-glib/basic-data-type.h>
 
 G_BEGIN_DECLS
@@ -62,19 +61,6 @@ GArrowArray   *garrow_array_slice       (GArrowArray *array,
 gchar         *garrow_array_to_string   (GArrowArray *array,
                                          GError **error);
 
-GArrowArray   *garrow_array_cast        (GArrowArray *array,
-                                         GArrowDataType *target_data_type,
-                                         GArrowCastOptions *options,
-                                         GError **error);
-GArrowArray   *garrow_array_unique      (GArrowArray *array,
-                                         GError **error);
-GArrowArray   *garrow_array_dictionary_encode(GArrowArray *array,
-                                              GError **error);
-GARROW_AVAILABLE_IN_0_13
-gint64
-garrow_array_count(GArrowArray *array,
-                   GArrowCountOptions *options,
-                   GError **error);
 
 #define GARROW_TYPE_NULL_ARRAY                  \
   (garrow_null_array_get_type())
@@ -186,25 +172,6 @@ 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,
@@ -217,9 +184,6 @@ struct _GArrowNumericArrayClass
   GArrowPrimitiveArrayClass parent_class;
 };
 
-GARROW_AVAILABLE_IN_0_13
-gdouble garrow_numeric_array_mean(GArrowNumericArray *array,
-                                  GError **error);
 
 #define GARROW_TYPE_INT8_ARRAY (garrow_int8_array_get_type())
 G_DECLARE_DERIVABLE_TYPE(GArrowInt8Array,
@@ -241,9 +205,6 @@ gint8 garrow_int8_array_get_value(GArrowInt8Array *array,
                                   gint64 i);
 const gint8 *garrow_int8_array_get_values(GArrowInt8Array *array,
                                           gint64 *length);
-GARROW_AVAILABLE_IN_0_13
-gint64 garrow_int8_array_sum(GArrowInt8Array *array,
-                             GError **error);
 
 
 #define GARROW_TYPE_UINT8_ARRAY (garrow_uint8_array_get_type())
@@ -266,9 +227,6 @@ guint8 garrow_uint8_array_get_value(GArrowUInt8Array *array,
                                     gint64 i);
 const guint8 *garrow_uint8_array_get_values(GArrowUInt8Array *array,
                                             gint64 *length);
-GARROW_AVAILABLE_IN_0_13
-guint64 garrow_uint8_array_sum(GArrowUInt8Array *array,
-                               GError **error);
 
 
 #define GARROW_TYPE_INT16_ARRAY (garrow_int16_array_get_type())
@@ -291,9 +249,6 @@ gint16 garrow_int16_array_get_value(GArrowInt16Array *array,
                                     gint64 i);
 const gint16 *garrow_int16_array_get_values(GArrowInt16Array *array,
                                             gint64 *length);
-GARROW_AVAILABLE_IN_0_13
-gint64 garrow_int16_array_sum(GArrowInt16Array *array,
-                              GError **error);
 
 
 #define GARROW_TYPE_UINT16_ARRAY (garrow_uint16_array_get_type())
@@ -316,9 +271,6 @@ guint16 garrow_uint16_array_get_value(GArrowUInt16Array 
*array,
                                       gint64 i);
 const guint16 *garrow_uint16_array_get_values(GArrowUInt16Array *array,
                                               gint64 *length);
-GARROW_AVAILABLE_IN_0_13
-guint64 garrow_uint16_array_sum(GArrowUInt16Array *array,
-                                GError **error);
 
 
 #define GARROW_TYPE_INT32_ARRAY (garrow_int32_array_get_type())
@@ -341,9 +293,6 @@ gint32 garrow_int32_array_get_value(GArrowInt32Array *array,
                                     gint64 i);
 const gint32 *garrow_int32_array_get_values(GArrowInt32Array *array,
                                             gint64 *length);
-GARROW_AVAILABLE_IN_0_13
-gint64 garrow_int32_array_sum(GArrowInt32Array *array,
-                              GError **error);
 
 
 #define GARROW_TYPE_UINT32_ARRAY (garrow_uint32_array_get_type())
@@ -366,9 +315,6 @@ guint32 garrow_uint32_array_get_value(GArrowUInt32Array 
*array,
                                       gint64 i);
 const guint32 *garrow_uint32_array_get_values(GArrowUInt32Array *array,
                                               gint64 *length);
-GARROW_AVAILABLE_IN_0_13
-guint64 garrow_uint32_array_sum(GArrowUInt32Array *array,
-                                GError **error);
 
 
 #define GARROW_TYPE_INT64_ARRAY (garrow_int64_array_get_type())
@@ -391,9 +337,6 @@ gint64 garrow_int64_array_get_value(GArrowInt64Array *array,
                                     gint64 i);
 const gint64 *garrow_int64_array_get_values(GArrowInt64Array *array,
                                             gint64 *length);
-GARROW_AVAILABLE_IN_0_13
-gint64 garrow_int64_array_sum(GArrowInt64Array *array,
-                              GError **error);
 
 
 #define GARROW_TYPE_UINT64_ARRAY (garrow_uint64_array_get_type())
@@ -416,9 +359,6 @@ guint64 garrow_uint64_array_get_value(GArrowUInt64Array 
*array,
                                       gint64 i);
 const guint64 *garrow_uint64_array_get_values(GArrowUInt64Array *array,
                                               gint64 *length);
-GARROW_AVAILABLE_IN_0_13
-guint64 garrow_uint64_array_sum(GArrowUInt64Array *array,
-                                GError **error);
 
 
 #define GARROW_TYPE_FLOAT_ARRAY (garrow_float_array_get_type())
@@ -441,9 +381,6 @@ gfloat garrow_float_array_get_value(GArrowFloatArray *array,
                                     gint64 i);
 const gfloat *garrow_float_array_get_values(GArrowFloatArray *array,
                                             gint64 *length);
-GARROW_AVAILABLE_IN_0_13
-gdouble garrow_float_array_sum(GArrowFloatArray *array,
-                               GError **error);
 
 
 #define GARROW_TYPE_DOUBLE_ARRAY (garrow_double_array_get_type())
@@ -466,9 +403,6 @@ gdouble garrow_double_array_get_value(GArrowDoubleArray 
*array,
                                       gint64 i);
 const gdouble *garrow_double_array_get_values(GArrowDoubleArray *array,
                                               gint64 *length);
-GARROW_AVAILABLE_IN_0_13
-gdouble garrow_double_array_sum(GArrowDoubleArray *array,
-                                GError **error);
 
 
 #define GARROW_TYPE_BINARY_ARRAY                \
diff --git a/c_glib/arrow-glib/composite-array.h 
b/c_glib/arrow-glib/composite-array.h
index 275ae43..47cd573 100644
--- a/c_glib/arrow-glib/composite-array.h
+++ b/c_glib/arrow-glib/composite-array.h
@@ -80,48 +80,17 @@ GArrowArray *garrow_list_array_get_value(GArrowListArray 
*array,
                                          gint64 i);
 
 
-#define GARROW_TYPE_STRUCT_ARRAY                \
-  (garrow_struct_array_get_type())
-#define GARROW_STRUCT_ARRAY(obj)                        \
-  (G_TYPE_CHECK_INSTANCE_CAST((obj),                    \
-                              GARROW_TYPE_STRUCT_ARRAY, \
-                              GArrowStructArray))
-#define GARROW_STRUCT_ARRAY_CLASS(klass)                \
-  (G_TYPE_CHECK_CLASS_CAST((klass),                     \
-                           GARROW_TYPE_STRUCT_ARRAY,    \
-                           GArrowStructArrayClass))
-#define GARROW_IS_STRUCT_ARRAY(obj)                             \
-  (G_TYPE_CHECK_INSTANCE_TYPE((obj),                            \
-                              GARROW_TYPE_STRUCT_ARRAY))
-#define GARROW_IS_STRUCT_ARRAY_CLASS(klass)             \
-  (G_TYPE_CHECK_CLASS_TYPE((klass),                     \
-                           GARROW_TYPE_STRUCT_ARRAY))
-#define GARROW_STRUCT_ARRAY_GET_CLASS(obj)              \
-  (G_TYPE_INSTANCE_GET_CLASS((obj),                     \
-                             GARROW_TYPE_STRUCT_ARRAY,  \
-                             GArrowStructArrayClass))
-
-typedef struct _GArrowStructArray         GArrowStructArray;
-typedef struct _GArrowStructArrayClass    GArrowStructArrayClass;
-
-/**
- * GArrowStructArray:
- *
- * It wraps `arrow::StructArray`.
- */
-struct _GArrowStructArray
-{
-  /*< private >*/
-  GArrowArray parent_instance;
-};
-
+#define GARROW_TYPE_STRUCT_ARRAY (garrow_struct_array_get_type())
+G_DECLARE_DERIVABLE_TYPE(GArrowStructArray,
+                         garrow_struct_array,
+                         GARROW,
+                         STRUCT_ARRAY,
+                         GArrowArray)
 struct _GArrowStructArrayClass
 {
   GArrowArrayClass parent_class;
 };
 
-GType garrow_struct_array_get_type(void) G_GNUC_CONST;
-
 GArrowStructArray *garrow_struct_array_new(GArrowDataType *data_type,
                                            gint64 length,
                                            GList *fields,
diff --git a/c_glib/arrow-glib/compute.cpp b/c_glib/arrow-glib/compute.cpp
index 3dd226e..8effe69 100644
--- a/c_glib/arrow-glib/compute.cpp
+++ b/c_glib/arrow-glib/compute.cpp
@@ -21,20 +21,53 @@
 #  include <config.h>
 #endif
 
+#include <arrow-glib/array.hpp>
 #include <arrow-glib/compute.hpp>
+#include <arrow-glib/data-type.hpp>
 #include <arrow-glib/enums.h>
+#include <arrow-glib/error.hpp>
+
+template <typename ArrowType, typename GArrowArrayType>
+typename ArrowType::c_type
+garrow_numeric_array_sum(GArrowArrayType array,
+                         GError **error,
+                         const gchar *tag,
+                         typename ArrowType::c_type default_value)
+{
+  auto arrow_array = garrow_array_get_raw(GARROW_ARRAY(array));
+  auto memory_pool = arrow::default_memory_pool();
+  arrow::compute::FunctionContext context(memory_pool);
+  arrow::compute::Datum sum_datum;
+  auto status = arrow::compute::Sum(&context,
+                                    arrow_array,
+                                    &sum_datum);
+  if (garrow_error_check(error, status, tag)) {
+    using ScalarType = typename arrow::TypeTraits<ArrowType>::ScalarType;
+    auto arrow_numeric_scalar =
+      std::dynamic_pointer_cast<ScalarType>(sum_datum.scalar());
+    if (arrow_numeric_scalar->is_valid) {
+      return arrow_numeric_scalar->value;
+    } else {
+      return default_value;
+    }
+  } else {
+    return default_value;
+  }
+}
 
 G_BEGIN_DECLS
 
 /**
  * SECTION: compute
- * @section_id: compute-classes
- * @title: Classes for computation
+ * @section_id: compute
+ * @title: Computation on array
  * @include: arrow-glib/arrow-glib.h
  *
  * #GArrowCastOptions is a class to customize garrow_array_cast().
  *
  * #GArrowCountOptions is a class to customize garrow_array_count().
+ *
+ * There are many functions to compute data on an array.
  */
 
 typedef struct GArrowCastOptionsPrivate_ {
@@ -295,6 +328,581 @@ garrow_count_options_new(void)
   return GARROW_COUNT_OPTIONS(count_options);
 }
 
+
+/**
+ * garrow_array_cast:
+ * @array: A #GArrowArray.
+ * @target_data_type: A #GArrowDataType of cast target data.
+ * @options: (nullable): A #GArrowCastOptions.
+ * @error: (nullable): Return location for a #GError or %NULL.
+ *
+ * Returns: (nullable) (transfer full):
+ *   A newly created casted array on success, %NULL on error.
+ *
+ * Since: 0.7.0
+ */
+GArrowArray *
+garrow_array_cast(GArrowArray *array,
+                  GArrowDataType *target_data_type,
+                  GArrowCastOptions *options,
+                  GError **error)
+{
+  auto arrow_array = garrow_array_get_raw(array);
+  auto arrow_array_raw = arrow_array.get();
+  auto memory_pool = arrow::default_memory_pool();
+  arrow::compute::FunctionContext context(memory_pool);
+  auto arrow_target_data_type = garrow_data_type_get_raw(target_data_type);
+  std::shared_ptr<arrow::Array> arrow_casted_array;
+  arrow::Status status;
+  if (options) {
+    auto arrow_options = garrow_cast_options_get_raw(options);
+    status = arrow::compute::Cast(&context,
+                                  *arrow_array_raw,
+                                  arrow_target_data_type,
+                                  *arrow_options,
+                                  &arrow_casted_array);
+  } else {
+    arrow::compute::CastOptions arrow_options;
+    status = arrow::compute::Cast(&context,
+                                  *arrow_array_raw,
+                                  arrow_target_data_type,
+                                  arrow_options,
+                                  &arrow_casted_array);
+  }
+
+  if (!status.ok()) {
+    std::stringstream message;
+    message << "[array][cast] <";
+    message << arrow_array->type()->ToString();
+    message << "> -> <";
+    message << arrow_target_data_type->ToString();
+    message << ">";
+    garrow_error_check(error, status, message.str().c_str());
+    return NULL;
+  }
+
+  return garrow_array_new_raw(&arrow_casted_array);
+}
+
+/**
+ * garrow_array_unique:
+ * @array: A #GArrowArray.
+ * @error: (nullable): Return location for a #GError or %NULL.
+ *
+ * Returns: (nullable) (transfer full):
+ *   A newly created unique elements array on success, %NULL on error.
+ *
+ * Since: 0.8.0
+ */
+GArrowArray *
+garrow_array_unique(GArrowArray *array,
+                    GError **error)
+{
+  auto arrow_array = garrow_array_get_raw(array);
+  auto memory_pool = arrow::default_memory_pool();
+  arrow::compute::FunctionContext context(memory_pool);
+  std::shared_ptr<arrow::Array> arrow_unique_array;
+  auto status = arrow::compute::Unique(&context,
+                                       arrow::compute::Datum(arrow_array),
+                                       &arrow_unique_array);
+  if (!status.ok()) {
+    std::stringstream message;
+    message << "[array][unique] <";
+    message << arrow_array->type()->ToString();
+    message << ">";
+    garrow_error_check(error, status, message.str().c_str());
+    return NULL;
+  }
+
+  return garrow_array_new_raw(&arrow_unique_array);
+}
+
+/**
+ * garrow_array_dictionary_encode:
+ * @array: A #GArrowArray.
+ * @error: (nullable): Return location for a #GError or %NULL.
+ *
+ * Returns: (nullable) (transfer full):
+ *   A newly created #GArrowDictionaryArray for the @array on success,
+ *   %NULL on error.
+ *
+ * Since: 0.8.0
+ */
+GArrowDictionaryArray *
+garrow_array_dictionary_encode(GArrowArray *array,
+                               GError **error)
+{
+  auto arrow_array = garrow_array_get_raw(array);
+  auto memory_pool = arrow::default_memory_pool();
+  arrow::compute::FunctionContext context(memory_pool);
+  arrow::compute::Datum dictionary_encoded_datum;
+  auto status =
+    arrow::compute::DictionaryEncode(&context,
+                                     arrow::compute::Datum(arrow_array),
+                                     &dictionary_encoded_datum);
+  if (!status.ok()) {
+    std::stringstream message;
+    message << "[array][dictionary-encode] <";
+    message << arrow_array->type()->ToString();
+    message << ">";
+    garrow_error_check(error, status, message.str().c_str());
+    return NULL;
+  }
+
+  auto arrow_dictionary_encoded_array =
+    arrow::MakeArray(dictionary_encoded_datum.array());
+  auto dictionary_encoded_array =
+    garrow_array_new_raw(&arrow_dictionary_encoded_array);
+  return GARROW_DICTIONARY_ARRAY(dictionary_encoded_array);
+}
+
+/**
+ * garrow_array_count:
+ * @array: A #GArrowArray.
+ * @options: (nullable): A #GArrowCountOptions.
+ * @error: (nullable): Return location for a #GError or %NULL.
+ *
+ * Returns: The number of target values on success. If an error is occurred,
+ *   the returned value is untrustful value.
+ *
+ * Since: 0.13.0
+ */
+gint64
+garrow_array_count(GArrowArray *array,
+                   GArrowCountOptions *options,
+                   GError **error)
+{
+  auto arrow_array = garrow_array_get_raw(array);
+  auto arrow_array_raw = arrow_array.get();
+  auto memory_pool = arrow::default_memory_pool();
+  arrow::compute::FunctionContext context(memory_pool);
+  arrow::compute::Datum counted_datum;
+  arrow::Status status;
+  if (options) {
+    auto arrow_options = garrow_count_options_get_raw(options);
+    status = arrow::compute::Count(&context,
+                                   *arrow_options,
+                                   *arrow_array_raw,
+                                   &counted_datum);
+  } else {
+    arrow::compute::CountOptions 
arrow_options(arrow::compute::CountOptions::COUNT_ALL);
+    status = arrow::compute::Count(&context,
+                                   arrow_options,
+                                   *arrow_array_raw,
+                                   &counted_datum);
+  }
+
+  if (garrow_error_check(error, status, "[array][count]")) {
+    using ScalarType = typename 
arrow::TypeTraits<arrow::Int64Type>::ScalarType;
+    auto counted_scalar = 
std::dynamic_pointer_cast<ScalarType>(counted_datum.scalar());
+    return counted_scalar->value;
+  } else {
+    return 0;
+  }
+}
+
+/**
+ * garrow_array_count_values:
+ * @array: A #GArrowArray.
+ * @error: (nullable): Return location for a #GError or %NULL.
+ *
+ * Returns: (nullable) (transfer full):
+ *   A #GArrowStructArray of `{input type "values", int64_t "counts"}`
+ *   on success, %NULL on error.
+ *
+ * Since: 0.13.0
+ */
+GArrowStructArray *
+garrow_array_count_values(GArrowArray *array,
+                          GError **error)
+{
+  auto arrow_array = garrow_array_get_raw(array);
+  auto memory_pool = arrow::default_memory_pool();
+  arrow::compute::FunctionContext context(memory_pool);
+  std::shared_ptr<arrow::Array> arrow_counted_values;
+  auto status = arrow::compute::ValueCounts(&context,
+                                            arrow::compute::Datum(arrow_array),
+                                            &arrow_counted_values);
+  if (garrow_error_check(error, status, "[array][count-values]")) {
+    return GARROW_STRUCT_ARRAY(garrow_array_new_raw(&arrow_counted_values));
+  } else {
+    return NULL;
+  }
+}
+
+
+/**
+ * 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;
+  }
+}
+
+
+/**
+ * garrow_numeric_array_mean:
+ * @array: A #GArrowNumericArray.
+ * @error: (nullable): Return location for a #GError or %NULL.
+ *
+ * Returns: The value of the computed mean.
+ *
+ * Since: 0.13.0
+ */
+gdouble
+garrow_numeric_array_mean(GArrowNumericArray *array,
+                          GError **error)
+{
+  auto arrow_array = garrow_array_get_raw(GARROW_ARRAY(array));
+  auto memory_pool = arrow::default_memory_pool();
+  arrow::compute::FunctionContext context(memory_pool);
+  arrow::compute::Datum mean_datum;
+  auto status = arrow::compute::Mean(&context, arrow_array, &mean_datum);
+  if (garrow_error_check(error, status, "[numeric-array][mean]")) {
+    using ScalarType = typename 
arrow::TypeTraits<arrow::DoubleType>::ScalarType;
+    auto arrow_numeric_scalar =
+      std::dynamic_pointer_cast<ScalarType>(mean_datum.scalar());
+    if (arrow_numeric_scalar->is_valid) {
+      return arrow_numeric_scalar->value;
+    } else {
+      return 0.0;
+    }
+  } else {
+    return 0.0;
+  }
+}
+
+
+/**
+ * garrow_int8_array_sum:
+ * @array: A #GArrowInt8Array.
+ * @error: (nullable): Return location for a #GError or %NULL.
+ *
+ * Returns: The value of the computed sum on success,
+ *   If an error is occurred, the returned value is untrustful value.
+ *
+ * Since: 0.13.0
+ */
+gint64
+garrow_int8_array_sum(GArrowInt8Array *array,
+                      GError **error)
+{
+  return garrow_numeric_array_sum<arrow::Int64Type>(array,
+                                                    error,
+                                                    "[int8-array][sum]",
+                                                    0);
+}
+
+/**
+ * garrow_uint8_array_sum:
+ * @array: A #GArrowUInt8Array.
+ * @error: (nullable): Return location for a #GError or %NULL.
+ *
+ * Returns: The value of the computed sum on success,
+ *   If an error is occurred, the returned value is untrustful value.
+ *
+ * Since: 0.13.0
+ */
+guint64
+garrow_uint8_array_sum(GArrowUInt8Array *array,
+                       GError **error)
+{
+  return garrow_numeric_array_sum<arrow::UInt64Type>(array,
+                                                     error,
+                                                     "[uint8-array][sum]",
+                                                     0);
+}
+
+/**
+ * garrow_int16_array_sum:
+ * @array: A #GArrowInt16Array.
+ * @error: (nullable): Return location for a #GError or %NULL.
+ *
+ * Returns: The value of the computed sum on success,
+ *   If an error is occurred, the returned value is untrustful value.
+ *
+ * Since: 0.13.0
+ */
+gint64
+garrow_int16_array_sum(GArrowInt16Array *array,
+                       GError **error)
+{
+  return garrow_numeric_array_sum<arrow::Int64Type>(array,
+                                                    error,
+                                                    "[int16-array][sum]",
+                                                    0);
+}
+
+/**
+ * garrow_uint16_array_sum:
+ * @array: A #GArrowUInt16Array.
+ * @error: (nullable): Return location for a #GError or %NULL.
+ *
+ * Returns: The value of the computed sum on success,
+ *   If an error is occurred, the returned value is untrustful value.
+ *
+ * Since: 0.13.0
+ */
+guint64
+garrow_uint16_array_sum(GArrowUInt16Array *array,
+                        GError **error)
+{
+  return garrow_numeric_array_sum<arrow::UInt64Type>(array,
+                                                     error,
+                                                     "[uint16-array][sum]",
+                                                     0);
+}
+
+/**
+ * garrow_int32_array_sum:
+ * @array: A #GArrowInt32Array.
+ * @error: (nullable): Return location for a #GError or %NULL.
+ *
+ * Returns: The value of the computed sum on success,
+ *   If an error is occurred, the returned value is untrustful value.
+ *
+ * Since: 0.13.0
+ */
+gint64
+garrow_int32_array_sum(GArrowInt32Array *array,
+                       GError **error)
+{
+  return garrow_numeric_array_sum<arrow::Int64Type>(array,
+                                                    error,
+                                                    "[int32-array][sum]",
+                                                    0);
+}
+
+/**
+ * garrow_uint32_array_sum:
+ * @array: A #GArrowUInt32Array.
+ * @error: (nullable): Return location for a #GError or %NULL.
+ *
+ * Returns: The value of the computed sum on success,
+ *   If an error is occurred, the returned value is untrustful value.
+ *
+ * Since: 0.13.0
+ */
+guint64
+garrow_uint32_array_sum(GArrowUInt32Array *array,
+                        GError **error)
+{
+  return garrow_numeric_array_sum<arrow::UInt64Type>(array,
+                                                    error,
+                                                    "[uint32-array][sum]",
+                                                    0);
+}
+
+/**
+ * garrow_int64_array_sum:
+ * @array: A #GArrowInt64Array.
+ * @error: (nullable): Return location for a #GError or %NULL.
+ *
+ * Returns: The value of the computed sum on success,
+ *   If an error is occurred, the returned value is untrustful value.
+ *
+ * Since: 0.13.0
+ */
+gint64
+garrow_int64_array_sum(GArrowInt64Array *array,
+                       GError **error)
+{
+  return garrow_numeric_array_sum<arrow::Int64Type>(array,
+                                                    error,
+                                                    "[int64-array][sum]",
+                                                    0);
+}
+
+/**
+ * garrow_uint64_array_sum:
+ * @array: A #GArrowUInt64Array.
+ * @error: (nullable): Return location for a #GError or %NULL.
+ *
+ * Returns: The value of the computed sum on success,
+ *   If an error is occurred, the returned value is untrustful value.
+ *
+ * Since: 0.13.0
+ */
+guint64
+garrow_uint64_array_sum(GArrowUInt64Array *array,
+                        GError **error)
+{
+  return garrow_numeric_array_sum<arrow::UInt64Type>(array,
+                                                    error,
+                                                    "[uint64-array][sum]",
+                                                    0);
+}
+
+/**
+ * garrow_float_array_sum:
+ * @array: A #GArrowFloatArray.
+ * @error: (nullable): Return location for a #GError or %NULL.
+ *
+ * Returns: The value of the computed sum on success,
+ *   If an error is occurred, the returned value is untrustful value.
+ *
+ * Since: 0.13.0
+ */
+gdouble
+garrow_float_array_sum(GArrowFloatArray *array,
+                       GError **error)
+{
+  return garrow_numeric_array_sum<arrow::DoubleType>(array,
+                                                     error,
+                                                     "[float-array][sum]",
+                                                     0);
+}
+
+/**
+ * garrow_double_array_sum:
+ * @array: A #GArrowDoubleArray.
+ * @error: (nullable): Return location for a #GError or %NULL.
+ *
+ * Returns: The value of the computed sum on success,
+ *   If an error is occurred, the returned value is untrustful value.
+ *
+ * Since: 0.13.0
+ */
+gdouble
+garrow_double_array_sum(GArrowDoubleArray *array,
+                        GError **error)
+{
+  return garrow_numeric_array_sum<arrow::DoubleType>(array,
+                                                     error,
+                                                     "[double-array][sum]",
+                                                     0);
+}
+
+
 G_END_DECLS
 
 GArrowCastOptions *
diff --git a/c_glib/arrow-glib/compute.h b/c_glib/arrow-glib/compute.h
index 88ba270..72bb0cb 100644
--- a/c_glib/arrow-glib/compute.h
+++ b/c_glib/arrow-glib/compute.h
@@ -19,8 +19,7 @@
 
 #pragma once
 
-#include <arrow-glib/gobject-type.h>
-#include <arrow-glib/version.h>
+#include <arrow-glib/array.h>
 
 G_BEGIN_DECLS
 
@@ -65,4 +64,72 @@ GARROW_AVAILABLE_IN_0_13
 GArrowCountOptions *
 garrow_count_options_new(void);
 
+
+GArrowArray *garrow_array_cast(GArrowArray *array,
+                               GArrowDataType *target_data_type,
+                               GArrowCastOptions *options,
+                               GError **error);
+GArrowArray *garrow_array_unique(GArrowArray *array,
+                                GError **error);
+GArrowDictionaryArray *garrow_array_dictionary_encode(GArrowArray *array,
+                                                      GError **error);
+GARROW_AVAILABLE_IN_0_13
+gint64 garrow_array_count(GArrowArray *array,
+                          GArrowCountOptions *options,
+                          GError **error);
+GARROW_AVAILABLE_IN_0_13
+GArrowStructArray *garrow_array_count_values(GArrowArray *array,
+                                             GError **error);
+
+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);
+
+GARROW_AVAILABLE_IN_0_13
+gdouble garrow_numeric_array_mean(GArrowNumericArray *array,
+                                  GError **error);
+
+GARROW_AVAILABLE_IN_0_13
+gint64 garrow_int8_array_sum(GArrowInt8Array *array,
+                             GError **error);
+GARROW_AVAILABLE_IN_0_13
+guint64 garrow_uint8_array_sum(GArrowUInt8Array *array,
+                               GError **error);
+GARROW_AVAILABLE_IN_0_13
+gint64 garrow_int16_array_sum(GArrowInt16Array *array,
+                              GError **error);
+GARROW_AVAILABLE_IN_0_13
+guint64 garrow_uint16_array_sum(GArrowUInt16Array *array,
+                                GError **error);
+GARROW_AVAILABLE_IN_0_13
+gint64 garrow_int32_array_sum(GArrowInt32Array *array,
+                              GError **error);
+GARROW_AVAILABLE_IN_0_13
+guint64 garrow_uint32_array_sum(GArrowUInt32Array *array,
+                                GError **error);
+GARROW_AVAILABLE_IN_0_13
+gint64 garrow_int64_array_sum(GArrowInt64Array *array,
+                              GError **error);
+GARROW_AVAILABLE_IN_0_13
+guint64 garrow_uint64_array_sum(GArrowUInt64Array *array,
+                                GError **error);
+GARROW_AVAILABLE_IN_0_13
+gdouble garrow_float_array_sum(GArrowFloatArray *array,
+                               GError **error);
+GARROW_AVAILABLE_IN_0_13
+gdouble garrow_double_array_sum(GArrowDoubleArray *array,
+                                GError **error);
+
 G_END_DECLS
diff --git a/c_glib/doc/arrow-glib/arrow-glib-docs.xml 
b/c_glib/doc/arrow-glib/arrow-glib-docs.xml
index 1016703..3dcc7fe 100644
--- a/c_glib/doc/arrow-glib/arrow-glib-docs.xml
+++ b/c_glib/doc/arrow-glib/arrow-glib-docs.xml
@@ -42,15 +42,12 @@
       <title>Array</title>
       <xi:include href="xml/basic-array.xml"/>
       <xi:include href="xml/composite-array.xml"/>
+      <xi:include href="xml/compute.xml"/>
     </chapter>
     <chapter id="array-builder">
       <title>Array builder</title>
       <xi:include href="xml/array-builder.xml"/>
     </chapter>
-    <chapter id="compute">
-      <title>Compute</title>
-      <xi:include href="xml/compute.xml"/>
-    </chapter>
     <chapter id="decimal">
       <title>Decimal</title>
       <xi:include href="xml/decimal128.xml"/>
diff --git a/c_glib/gandiva-glib/node.cpp b/c_glib/gandiva-glib/node.cpp
index b2adf85..347473b 100644
--- a/c_glib/gandiva-glib/node.cpp
+++ b/c_glib/gandiva-glib/node.cpp
@@ -1323,7 +1323,7 @@ ggandiva_if_node_class_init(GGandivaIfNodeClass *klass)
  * @return_type: A #GArrowDataType.
  * @error: (nullable): Return location for a #GError or %NULL.
  *
- * Returns: (nullable): A newly created #GGandivaIfNode or %NULl on error.
+ * Returns: (nullable): A newly created #GGandivaIfNode or %NULL on error.
  *
  * Since: 0.12.0
  */
diff --git a/c_glib/test/test-count-values.rb b/c_glib/test/test-count-values.rb
new file mode 100644
index 0000000..46c36cf
--- /dev/null
+++ b/c_glib/test/test-count-values.rb
@@ -0,0 +1,51 @@
+# 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 TestCountValues < Test::Unit::TestCase
+  include Helper::Buildable
+  include Helper::Omittable
+
+  def test_int32
+    array = build_int32_array([1, 3, 1, -1, -3, -1])
+    fields = [
+      Arrow::Field.new("values", Arrow::Int32DataType.new),
+      Arrow::Field.new("counts", Arrow::Int64DataType.new),
+    ]
+    structs = [
+      {"values" =>  1, "counts" => 2},
+      {"values" =>  3, "counts" => 1},
+      {"values" => -1, "counts" => 2},
+      {"values" => -3, "counts" => 1},
+    ]
+    assert_equal(build_struct_array(fields, structs),
+                 array.count_values)
+  end
+
+  def test_string
+    array = build_string_array(["Ruby", "Python", "Ruby"])
+    fields = [
+      Arrow::Field.new("values", Arrow::StringDataType.new),
+      Arrow::Field.new("counts", Arrow::Int64DataType.new),
+    ]
+    structs = [
+      {"values" => "Ruby",   "counts" => 2},
+      {"values" => "Python", "counts" => 1},
+    ]
+    assert_equal(build_struct_array(fields, structs),
+                 array.count_values)
+  end
+end

Reply via email to