This is an automated email from the ASF dual-hosted git repository.

kou pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/arrow.git


The following commit(s) were added to refs/heads/main by this push:
     new 744f0ec2cf GH-48496: [GLib][Ruby] Add PairwiseOptions (#48517)
744f0ec2cf is described below

commit 744f0ec2cf9f8716fcea408d67ede9c14a7e6954
Author: Sten Larsson <[email protected]>
AuthorDate: Thu Dec 25 02:58:48 2025 +0100

    GH-48496: [GLib][Ruby] Add PairwiseOptions (#48517)
    
    ### Rationale for this change
    
    The `PairwiseOptions` class is not available in GLib/Ruby, and it is used 
together with the `pairwise_diff` compute function.
    
    ### What changes are included in this PR?
    
    This adds the `PairwiseOptions` class to GLib.
    
    ### Are these changes tested?
    
    Yes, with Ruby unit tests.
    
    ### Are there any user-facing changes?
    
    Yes, a new class.
    
    * GitHub Issue: #48496
    
    Authored-by: Sten Larsson <[email protected]>
    Signed-off-by: Sutou Kouhei <[email protected]>
---
 c_glib/arrow-glib/compute.cpp        | 116 +++++++++++++++++++++++++++++++++++
 c_glib/arrow-glib/compute.h          |  16 +++++
 c_glib/arrow-glib/compute.hpp        |   5 ++
 c_glib/test/test-pairwise-options.rb |  42 +++++++++++++
 4 files changed, 179 insertions(+)

diff --git a/c_glib/arrow-glib/compute.cpp b/c_glib/arrow-glib/compute.cpp
index 8d16b9abee..df6fab4f30 100644
--- a/c_glib/arrow-glib/compute.cpp
+++ b/c_glib/arrow-glib/compute.cpp
@@ -293,6 +293,9 @@ G_BEGIN_DECLS
  * `utf8_lpad`, `utf8_rpad`, `utf8_center`, `ascii_lpad`, `ascii_rpad`, and
  * `ascii_center`.
  *
+ * #GArrowPairwiseOptions is a class to customize the pairwise
+ * functions such as `pairwise_diff` and `pairwise_diff_checked`.
+ *
  * There are many functions to compute data on an array.
  */
 
@@ -8252,6 +8255,100 @@ garrow_pad_options_new(void)
   return GARROW_PAD_OPTIONS(g_object_new(GARROW_TYPE_PAD_OPTIONS, NULL));
 }
 
+enum {
+  PROP_PAIRWISE_OPTIONS_PERIODS = 1,
+};
+
+G_DEFINE_TYPE(GArrowPairwiseOptions,
+              garrow_pairwise_options,
+              GARROW_TYPE_FUNCTION_OPTIONS)
+
+static void
+garrow_pairwise_options_set_property(GObject *object,
+                                     guint prop_id,
+                                     const GValue *value,
+                                     GParamSpec *pspec)
+{
+  auto options = 
garrow_pairwise_options_get_raw(GARROW_PAIRWISE_OPTIONS(object));
+
+  switch (prop_id) {
+  case PROP_PAIRWISE_OPTIONS_PERIODS:
+    options->periods = g_value_get_int64(value);
+    break;
+  default:
+    G_OBJECT_WARN_INVALID_PROPERTY_ID(object, prop_id, pspec);
+    break;
+  }
+}
+
+static void
+garrow_pairwise_options_get_property(GObject *object,
+                                     guint prop_id,
+                                     GValue *value,
+                                     GParamSpec *pspec)
+{
+  auto options = 
garrow_pairwise_options_get_raw(GARROW_PAIRWISE_OPTIONS(object));
+
+  switch (prop_id) {
+  case PROP_PAIRWISE_OPTIONS_PERIODS:
+    g_value_set_int64(value, options->periods);
+    break;
+  default:
+    G_OBJECT_WARN_INVALID_PROPERTY_ID(object, prop_id, pspec);
+    break;
+  }
+}
+
+static void
+garrow_pairwise_options_init(GArrowPairwiseOptions *object)
+{
+  auto priv = GARROW_FUNCTION_OPTIONS_GET_PRIVATE(object);
+  priv->options =
+    static_cast<arrow::compute::FunctionOptions *>(new 
arrow::compute::PairwiseOptions());
+}
+
+static void
+garrow_pairwise_options_class_init(GArrowPairwiseOptionsClass *klass)
+{
+  auto gobject_class = G_OBJECT_CLASS(klass);
+
+  gobject_class->set_property = garrow_pairwise_options_set_property;
+  gobject_class->get_property = garrow_pairwise_options_get_property;
+
+  arrow::compute::PairwiseOptions options;
+
+  GParamSpec *spec;
+  /**
+   * GArrowPairwiseOptions:periods:
+   *
+   * Periods to shift for applying the binary operation, accepts negative 
values.
+   *
+   * Since: 23.0.0
+   */
+  spec = g_param_spec_int64(
+    "periods",
+    "Periods",
+    "Periods to shift for applying the binary operation, accepts negative 
values",
+    G_MININT64,
+    G_MAXINT64,
+    options.periods,
+    static_cast<GParamFlags>(G_PARAM_READWRITE));
+  g_object_class_install_property(gobject_class, 
PROP_PAIRWISE_OPTIONS_PERIODS, spec);
+}
+
+/**
+ * garrow_pairwise_options_new:
+ *
+ * Returns: A newly created #GArrowPairwiseOptions.
+ *
+ * Since: 23.0.0
+ */
+GArrowPairwiseOptions *
+garrow_pairwise_options_new(void)
+{
+  return GARROW_PAIRWISE_OPTIONS(g_object_new(GARROW_TYPE_PAIRWISE_OPTIONS, 
NULL));
+}
+
 G_END_DECLS
 
 arrow::Result<arrow::FieldRef>
@@ -8451,6 +8548,11 @@ garrow_function_options_new_raw(const 
arrow::compute::FunctionOptions *arrow_opt
       static_cast<const arrow::compute::PadOptions *>(arrow_options);
     auto options = garrow_pad_options_new_raw(arrow_pad_options);
     return GARROW_FUNCTION_OPTIONS(options);
+  } else if (arrow_type_name == "PairwiseOptions") {
+    const auto arrow_pairwise_options =
+      static_cast<const arrow::compute::PairwiseOptions *>(arrow_options);
+    auto options = garrow_pairwise_options_new_raw(arrow_pairwise_options);
+    return GARROW_FUNCTION_OPTIONS(options);
   } else {
     auto options = g_object_new(GARROW_TYPE_FUNCTION_OPTIONS, NULL);
     return GARROW_FUNCTION_OPTIONS(options);
@@ -9261,3 +9363,17 @@ garrow_pad_options_get_raw(GArrowPadOptions *options)
   return static_cast<arrow::compute::PadOptions *>(
     garrow_function_options_get_raw(GARROW_FUNCTION_OPTIONS(options)));
 }
+
+GArrowPairwiseOptions *
+garrow_pairwise_options_new_raw(const arrow::compute::PairwiseOptions 
*arrow_options)
+{
+  return GARROW_PAIRWISE_OPTIONS(
+    g_object_new(GARROW_TYPE_PAIRWISE_OPTIONS, "periods", 
arrow_options->periods, NULL));
+}
+
+arrow::compute::PairwiseOptions *
+garrow_pairwise_options_get_raw(GArrowPairwiseOptions *options)
+{
+  return static_cast<arrow::compute::PairwiseOptions *>(
+    garrow_function_options_get_raw(GARROW_FUNCTION_OPTIONS(options)));
+}
diff --git a/c_glib/arrow-glib/compute.h b/c_glib/arrow-glib/compute.h
index 14e7e4a7b9..becdaf3a67 100644
--- a/c_glib/arrow-glib/compute.h
+++ b/c_glib/arrow-glib/compute.h
@@ -1459,4 +1459,20 @@ GARROW_AVAILABLE_IN_23_0
 GArrowPadOptions *
 garrow_pad_options_new(void);
 
+#define GARROW_TYPE_PAIRWISE_OPTIONS (garrow_pairwise_options_get_type())
+GARROW_AVAILABLE_IN_23_0
+G_DECLARE_DERIVABLE_TYPE(GArrowPairwiseOptions,
+                         garrow_pairwise_options,
+                         GARROW,
+                         PAIRWISE_OPTIONS,
+                         GArrowFunctionOptions)
+struct _GArrowPairwiseOptionsClass
+{
+  GArrowFunctionOptionsClass parent_class;
+};
+
+GARROW_AVAILABLE_IN_23_0
+GArrowPairwiseOptions *
+garrow_pairwise_options_new(void);
+
 G_END_DECLS
diff --git a/c_glib/arrow-glib/compute.hpp b/c_glib/arrow-glib/compute.hpp
index 6f9ae39037..1a9da1c00c 100644
--- a/c_glib/arrow-glib/compute.hpp
+++ b/c_glib/arrow-glib/compute.hpp
@@ -251,3 +251,8 @@ GArrowPadOptions *
 garrow_pad_options_new_raw(const arrow::compute::PadOptions *arrow_options);
 arrow::compute::PadOptions *
 garrow_pad_options_get_raw(GArrowPadOptions *options);
+
+GArrowPairwiseOptions *
+garrow_pairwise_options_new_raw(const arrow::compute::PairwiseOptions 
*arrow_options);
+arrow::compute::PairwiseOptions *
+garrow_pairwise_options_get_raw(GArrowPairwiseOptions *options);
diff --git a/c_glib/test/test-pairwise-options.rb 
b/c_glib/test/test-pairwise-options.rb
new file mode 100644
index 0000000000..98cbdf7cb8
--- /dev/null
+++ b/c_glib/test/test-pairwise-options.rb
@@ -0,0 +1,42 @@
+# 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 TestPairwiseOptions < Test::Unit::TestCase
+  include Helper::Buildable
+
+  def setup
+    @options = Arrow::PairwiseOptions.new
+  end
+
+  def test_periods_property
+    assert_equal(1, @options.periods)
+    @options.periods = 2
+    assert_equal(2, @options.periods)
+    @options.periods = -1
+    assert_equal(-1, @options.periods)
+  end
+
+  def test_pairwise_diff_function
+    args = [
+      Arrow::ArrayDatum.new(build_int32_array([1, 2, 4, 7, 11])),
+    ]
+    pairwise_diff_function = Arrow::Function.find("pairwise_diff")
+    @options.periods = 2
+    result = pairwise_diff_function.execute(args, @options).value
+    assert_equal(build_int32_array([nil, nil, 3, 5, 7]), result)
+  end
+end

Reply via email to