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 743e0af7ef GH-48506: [GLib][Ruby] Add SliceOptions (#48527)
743e0af7ef is described below
commit 743e0af7ef95b32f0650e7f0f1eba15f20905ca4
Author: Sten Larsson <[email protected]>
AuthorDate: Thu Jan 1 06:18:57 2026 +0100
GH-48506: [GLib][Ruby] Add SliceOptions (#48527)
### Rationale for this change
The `SliceOptions` class is not available in GLib/Ruby, and it is used
together with the `utf8_slice_codeunits` compute function.
### What changes are included in this PR?
This adds the `SliceOptions` class to GLib.
### Are these changes tested?
Yes, with Ruby unit tests.
### Are there any user-facing changes?
Yes, a new class.
* GitHub Issue: #48506
Authored-by: Sten Larsson <[email protected]>
Signed-off-by: Sutou Kouhei <[email protected]>
---
c_glib/arrow-glib/compute.cpp | 166 ++++++++++++++++++++++++++++++++++++++
c_glib/arrow-glib/compute.h | 13 +++
c_glib/arrow-glib/compute.hpp | 5 ++
c_glib/test/test-slice-options.rb | 55 +++++++++++++
4 files changed, 239 insertions(+)
diff --git a/c_glib/arrow-glib/compute.cpp b/c_glib/arrow-glib/compute.cpp
index 83c873c886..db35b9a89e 100644
--- a/c_glib/arrow-glib/compute.cpp
+++ b/c_glib/arrow-glib/compute.cpp
@@ -324,6 +324,9 @@ G_BEGIN_DECLS
* #GArrowSkewOptions is a class to customize the `skew` and
* `kurtosis` functions.
*
+ * #GArrowSliceOptions is a class to customize the `utf8_slice_codeunits` and
+ * `binary_slice` functions.
+ *
* There are many functions to compute data on an array.
*/
@@ -9641,6 +9644,143 @@ garrow_skew_options_new(void)
return GARROW_SKEW_OPTIONS(g_object_new(GARROW_TYPE_SKEW_OPTIONS, nullptr));
}
+enum {
+ PROP_SLICE_OPTIONS_START = 1,
+ PROP_SLICE_OPTIONS_STOP,
+ PROP_SLICE_OPTIONS_STEP,
+};
+
+G_DEFINE_TYPE(GArrowSliceOptions, garrow_slice_options,
GARROW_TYPE_FUNCTION_OPTIONS)
+
+static void
+garrow_slice_options_set_property(GObject *object,
+ guint prop_id,
+ const GValue *value,
+ GParamSpec *pspec)
+{
+ auto options = garrow_slice_options_get_raw(GARROW_SLICE_OPTIONS(object));
+
+ switch (prop_id) {
+ case PROP_SLICE_OPTIONS_START:
+ options->start = g_value_get_int64(value);
+ break;
+ case PROP_SLICE_OPTIONS_STOP:
+ options->stop = g_value_get_int64(value);
+ break;
+ case PROP_SLICE_OPTIONS_STEP:
+ options->step = g_value_get_int64(value);
+ break;
+ default:
+ G_OBJECT_WARN_INVALID_PROPERTY_ID(object, prop_id, pspec);
+ break;
+ }
+}
+
+static void
+garrow_slice_options_get_property(GObject *object,
+ guint prop_id,
+ GValue *value,
+ GParamSpec *pspec)
+{
+ auto options = garrow_slice_options_get_raw(GARROW_SLICE_OPTIONS(object));
+
+ switch (prop_id) {
+ case PROP_SLICE_OPTIONS_START:
+ g_value_set_int64(value, options->start);
+ break;
+ case PROP_SLICE_OPTIONS_STOP:
+ g_value_set_int64(value, options->stop);
+ break;
+ case PROP_SLICE_OPTIONS_STEP:
+ g_value_set_int64(value, options->step);
+ break;
+ default:
+ G_OBJECT_WARN_INVALID_PROPERTY_ID(object, prop_id, pspec);
+ break;
+ }
+}
+
+static void
+garrow_slice_options_init(GArrowSliceOptions *object)
+{
+ auto arrow_priv = GARROW_FUNCTION_OPTIONS_GET_PRIVATE(object);
+ arrow_priv->options =
+ static_cast<arrow::compute::FunctionOptions *>(new
arrow::compute::SliceOptions());
+}
+
+static void
+garrow_slice_options_class_init(GArrowSliceOptionsClass *klass)
+{
+ auto gobject_class = G_OBJECT_CLASS(klass);
+
+ gobject_class->set_property = garrow_slice_options_set_property;
+ gobject_class->get_property = garrow_slice_options_get_property;
+
+ arrow::compute::SliceOptions options;
+
+ GParamSpec *spec;
+ /**
+ * GArrowSliceOptions:start:
+ *
+ * Index to start slicing at (inclusive).
+ *
+ * Since: 23.0.0
+ */
+ spec = g_param_spec_int64("start",
+ "Start",
+ "Index to start slicing at (inclusive)",
+ G_MININT64,
+ G_MAXINT64,
+ options.start,
+ static_cast<GParamFlags>(G_PARAM_READWRITE));
+ g_object_class_install_property(gobject_class, PROP_SLICE_OPTIONS_START,
spec);
+
+ /**
+ * GArrowSliceOptions:stop:
+ *
+ * Index to stop slicing at (exclusive).
+ *
+ * Since: 23.0.0
+ */
+ spec = g_param_spec_int64("stop",
+ "Stop",
+ "Index to stop slicing at (exclusive)",
+ G_MININT64,
+ G_MAXINT64,
+ options.stop,
+ static_cast<GParamFlags>(G_PARAM_READWRITE));
+ g_object_class_install_property(gobject_class, PROP_SLICE_OPTIONS_STOP,
spec);
+
+ /**
+ * GArrowSliceOptions:step:
+ *
+ * Slice step.
+ *
+ * Since: 23.0.0
+ */
+ spec = g_param_spec_int64("step",
+ "Step",
+ "Slice step",
+ G_MININT64,
+ G_MAXINT64,
+ options.step,
+ static_cast<GParamFlags>(G_PARAM_READWRITE));
+ g_object_class_install_property(gobject_class, PROP_SLICE_OPTIONS_STEP,
spec);
+}
+
+/**
+ * garrow_slice_options_new:
+ *
+ * Returns: A newly created #GArrowSliceOptions.
+ *
+ * Since: 23.0.0
+ */
+GArrowSliceOptions *
+garrow_slice_options_new(void)
+{
+ return GARROW_SLICE_OPTIONS(g_object_new(GARROW_TYPE_SLICE_OPTIONS,
nullptr));
+}
+
G_END_DECLS
arrow::Result<arrow::FieldRef>
@@ -9891,6 +10031,11 @@ garrow_function_options_new_raw(const
arrow::compute::FunctionOptions *arrow_opt
static_cast<const arrow::compute::SkewOptions *>(arrow_options);
auto options = garrow_skew_options_new_raw(arrow_skew_options);
return GARROW_FUNCTION_OPTIONS(options);
+ } else if (arrow_type_name == "SliceOptions") {
+ const auto arrow_slice_options =
+ static_cast<const arrow::compute::SliceOptions *>(arrow_options);
+ auto options = garrow_slice_options_new_raw(arrow_slice_options);
+ return GARROW_FUNCTION_OPTIONS(options);
} else {
auto options = g_object_new(GARROW_TYPE_FUNCTION_OPTIONS, NULL);
return GARROW_FUNCTION_OPTIONS(options);
@@ -10905,3 +11050,24 @@ garrow_skew_options_get_raw(GArrowSkewOptions *options)
return static_cast<arrow::compute::SkewOptions *>(
garrow_function_options_get_raw(GARROW_FUNCTION_OPTIONS(options)));
}
+
+GArrowSliceOptions *
+garrow_slice_options_new_raw(const arrow::compute::SliceOptions *arrow_options)
+{
+ auto options = g_object_new(GARROW_TYPE_SLICE_OPTIONS,
+ "start",
+ arrow_options->start,
+ "stop",
+ arrow_options->stop,
+ "step",
+ arrow_options->step,
+ nullptr);
+ return GARROW_SLICE_OPTIONS(options);
+}
+
+arrow::compute::SliceOptions *
+garrow_slice_options_get_raw(GArrowSliceOptions *options)
+{
+ return static_cast<arrow::compute::SliceOptions *>(
+ 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 f2a6c2d45e..37c2fee644 100644
--- a/c_glib/arrow-glib/compute.h
+++ b/c_glib/arrow-glib/compute.h
@@ -1691,4 +1691,17 @@ GARROW_AVAILABLE_IN_23_0
GArrowSkewOptions *
garrow_skew_options_new(void);
+#define GARROW_TYPE_SLICE_OPTIONS (garrow_slice_options_get_type())
+GARROW_AVAILABLE_IN_23_0
+G_DECLARE_DERIVABLE_TYPE(
+ GArrowSliceOptions, garrow_slice_options, GARROW, SLICE_OPTIONS,
GArrowFunctionOptions)
+struct _GArrowSliceOptionsClass
+{
+ GArrowFunctionOptionsClass parent_class;
+};
+
+GARROW_AVAILABLE_IN_23_0
+GArrowSliceOptions *
+garrow_slice_options_new(void);
+
G_END_DECLS
diff --git a/c_glib/arrow-glib/compute.hpp b/c_glib/arrow-glib/compute.hpp
index 4990902992..1b32022092 100644
--- a/c_glib/arrow-glib/compute.hpp
+++ b/c_glib/arrow-glib/compute.hpp
@@ -308,3 +308,8 @@ GArrowSkewOptions *
garrow_skew_options_new_raw(const arrow::compute::SkewOptions *arrow_options);
arrow::compute::SkewOptions *
garrow_skew_options_get_raw(GArrowSkewOptions *options);
+
+GArrowSliceOptions *
+garrow_slice_options_new_raw(const arrow::compute::SliceOptions
*arrow_options);
+arrow::compute::SliceOptions *
+garrow_slice_options_get_raw(GArrowSliceOptions *options);
diff --git a/c_glib/test/test-slice-options.rb
b/c_glib/test/test-slice-options.rb
new file mode 100644
index 0000000000..27459c9182
--- /dev/null
+++ b/c_glib/test/test-slice-options.rb
@@ -0,0 +1,55 @@
+# 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 TestSliceOptions < Test::Unit::TestCase
+ include Helper::Buildable
+
+ def setup
+ @options = Arrow::SliceOptions.new
+ end
+
+ def test_start_property
+ assert_equal(0, @options.start)
+ @options.start = 1
+ assert_equal(1, @options.start)
+ end
+
+ def test_stop_property
+ assert_equal(0, @options.stop)
+ @options.stop = 5
+ assert_equal(5, @options.stop)
+ end
+
+ def test_step_property
+ assert_equal(1, @options.step)
+ @options.step = 2
+ assert_equal(2, @options.step)
+ end
+
+ def test_utf8_slice_codeunits_function
+ args = [
+ Arrow::ArrayDatum.new(build_string_array(["hello", "world", "test"])),
+ ]
+ @options.start = 1
+ @options.stop = 4
+ @options.step = 1
+ utf8_slice_codeunits_function =
Arrow::Function.find("utf8_slice_codeunits")
+ result = utf8_slice_codeunits_function.execute(args, @options).value
+ expected = build_string_array(["ell", "orl", "est"])
+ assert_equal(expected, result)
+ end
+end