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 3dc982183d GH-48488: [GLib][Ruby] Add GArrowListSliceOptions (#48489)
3dc982183d is described below
commit 3dc982183db45ced57ef1565e022dcb647a00745
Author: Sten Larsson <[email protected]>
AuthorDate: Wed Dec 24 00:57:35 2025 +0100
GH-48488: [GLib][Ruby] Add GArrowListSliceOptions (#48489)
### Rationale for this change
The `ListSliceOptions` class is not available in GLib/Ruby, and it is used
together with the `list_slice` compute function.
### What changes are included in this PR?
This adds the `ListSliceOptions` class to GLib.
### Are these changes tested?
Yes, with Ruby unit tests.
### Are there any user-facing changes?
Yes, a new class.
* GitHub Issue: #48488
Authored-by: Sten Larsson <[email protected]>
Signed-off-by: Sutou Kouhei <[email protected]>
---
c_glib/arrow-glib/compute.cpp | 249 +++++++++++++++++++++++++
c_glib/arrow-glib/compute.h | 48 +++++
c_glib/arrow-glib/compute.hpp | 5 +
c_glib/test/test-list-slice-options.rb | 122 ++++++++++++
ruby/red-arrow/lib/arrow/libraries.rb | 1 +
ruby/red-arrow/lib/arrow/list-slice-options.rb | 76 ++++++++
ruby/red-arrow/test/test-list-slice-options.rb | 90 +++++++++
7 files changed, 591 insertions(+)
diff --git a/c_glib/arrow-glib/compute.cpp b/c_glib/arrow-glib/compute.cpp
index c620b0eb51..3ddaae2532 100644
--- a/c_glib/arrow-glib/compute.cpp
+++ b/c_glib/arrow-glib/compute.cpp
@@ -282,6 +282,9 @@ G_BEGIN_DECLS
* #GArrowMapLookupOptions is a class to customize the `map_lookup`
* function.
*
+ * #GArrowListSliceOptions is a class to customize the `list_slice`
+ * function.
+ *
* There are many functions to compute data on an array.
*/
@@ -7664,6 +7667,217 @@ garrow_map_lookup_options_new(GArrowScalar *query_key,
NULL));
}
+enum {
+ PROP_LIST_SLICE_OPTIONS_START = 1,
+ PROP_LIST_SLICE_OPTIONS_STOP,
+ PROP_LIST_SLICE_OPTIONS_STEP,
+ PROP_LIST_SLICE_OPTIONS_RETURN_FIXED_SIZE_LIST,
+};
+
+G_DEFINE_TYPE(GArrowListSliceOptions,
+ garrow_list_slice_options,
+ GARROW_TYPE_FUNCTION_OPTIONS)
+
+static void
+garrow_list_slice_options_set_property(GObject *object,
+ guint prop_id,
+ const GValue *value,
+ GParamSpec *pspec)
+{
+ auto options =
garrow_list_slice_options_get_raw(GARROW_LIST_SLICE_OPTIONS(object));
+
+ switch (prop_id) {
+ case PROP_LIST_SLICE_OPTIONS_START:
+ options->start = g_value_get_int64(value);
+ break;
+ case PROP_LIST_SLICE_OPTIONS_STOP:
+ {
+ auto stop_value = g_value_get_int64(value);
+ if (stop_value == GARROW_LIST_SLICE_OPTIONS_STOP_UNSPECIFIED) {
+ options->stop = std::nullopt;
+ } else {
+ options->stop = stop_value;
+ }
+ }
+ break;
+ case PROP_LIST_SLICE_OPTIONS_STEP:
+ options->step = g_value_get_int64(value);
+ break;
+ case PROP_LIST_SLICE_OPTIONS_RETURN_FIXED_SIZE_LIST:
+ {
+ auto return_fixed_size_list_value =
+
static_cast<GArrowListSliceReturnFixedSizeList>(g_value_get_enum(value));
+ switch (return_fixed_size_list_value) {
+ case GARROW_LIST_SLICE_RETURN_FIXED_SIZE_LIST_AUTO:
+ options->return_fixed_size_list = std::nullopt;
+ break;
+ case GARROW_LIST_SLICE_RETURN_FIXED_SIZE_LIST_FALSE:
+ options->return_fixed_size_list = false;
+ break;
+ case GARROW_LIST_SLICE_RETURN_FIXED_SIZE_LIST_TRUE:
+ options->return_fixed_size_list = true;
+ break;
+ default:
+ options->return_fixed_size_list = std::nullopt;
+ break;
+ }
+ }
+ break;
+ default:
+ G_OBJECT_WARN_INVALID_PROPERTY_ID(object, prop_id, pspec);
+ break;
+ }
+}
+
+static void
+garrow_list_slice_options_get_property(GObject *object,
+ guint prop_id,
+ GValue *value,
+ GParamSpec *pspec)
+{
+ auto options =
garrow_list_slice_options_get_raw(GARROW_LIST_SLICE_OPTIONS(object));
+
+ switch (prop_id) {
+ case PROP_LIST_SLICE_OPTIONS_START:
+ g_value_set_int64(value, options->start);
+ break;
+ case PROP_LIST_SLICE_OPTIONS_STOP:
+ if (options->stop.has_value()) {
+ g_value_set_int64(value, options->stop.value());
+ } else {
+ g_value_set_int64(value, GARROW_LIST_SLICE_OPTIONS_STOP_UNSPECIFIED);
+ }
+ break;
+ case PROP_LIST_SLICE_OPTIONS_STEP:
+ g_value_set_int64(value, options->step);
+ break;
+ case PROP_LIST_SLICE_OPTIONS_RETURN_FIXED_SIZE_LIST:
+ if (options->return_fixed_size_list.has_value()) {
+ if (options->return_fixed_size_list.value()) {
+ g_value_set_enum(value, GARROW_LIST_SLICE_RETURN_FIXED_SIZE_LIST_TRUE);
+ } else {
+ g_value_set_enum(value,
GARROW_LIST_SLICE_RETURN_FIXED_SIZE_LIST_FALSE);
+ }
+ } else {
+ // When not set (nullopt), return AUTO (default)
+ g_value_set_enum(value, GARROW_LIST_SLICE_RETURN_FIXED_SIZE_LIST_AUTO);
+ }
+ break;
+ default:
+ G_OBJECT_WARN_INVALID_PROPERTY_ID(object, prop_id, pspec);
+ break;
+ }
+}
+
+static void
+garrow_list_slice_options_init(GArrowListSliceOptions *object)
+{
+ auto priv = GARROW_FUNCTION_OPTIONS_GET_PRIVATE(object);
+ priv->options = static_cast<arrow::compute::FunctionOptions *>(
+ new arrow::compute::ListSliceOptions());
+}
+
+static void
+garrow_list_slice_options_class_init(GArrowListSliceOptionsClass *klass)
+{
+ auto gobject_class = G_OBJECT_CLASS(klass);
+
+ gobject_class->set_property = garrow_list_slice_options_set_property;
+ gobject_class->get_property = garrow_list_slice_options_get_property;
+
+ arrow::compute::ListSliceOptions options;
+
+ GParamSpec *spec;
+ /**
+ * GArrowListSliceOptions:start:
+ *
+ * The start of list slicing.
+ *
+ * Since: 23.0.0
+ */
+ spec = g_param_spec_int64("start",
+ "Start",
+ "The start of list slicing",
+ G_MININT64,
+ G_MAXINT64,
+ options.start,
+ static_cast<GParamFlags>(G_PARAM_READWRITE));
+ g_object_class_install_property(gobject_class,
PROP_LIST_SLICE_OPTIONS_START, spec);
+
+ /**
+ * GArrowListSliceOptions:stop:
+ *
+ * Optional stop of list slicing. If not set (value is
+ * %GARROW_LIST_SLICE_OPTIONS_STOP_UNSPECIFIED), then slice to end.
+ *
+ * Since: 23.0.0
+ */
+ spec =
+ g_param_spec_int64("stop",
+ "Stop",
+ "Optional stop of list slicing. If not set (value is "
+ "GARROW_LIST_SLICE_OPTIONS_STOP_UNSPECIFIED), then
slice to end",
+ GARROW_LIST_SLICE_OPTIONS_STOP_UNSPECIFIED,
+ G_MAXINT64,
+ GARROW_LIST_SLICE_OPTIONS_STOP_UNSPECIFIED,
+ static_cast<GParamFlags>(G_PARAM_READWRITE));
+ g_object_class_install_property(gobject_class, PROP_LIST_SLICE_OPTIONS_STOP,
spec);
+
+ /**
+ * GArrowListSliceOptions:step:
+ *
+ * Slicing step.
+ *
+ * Since: 23.0.0
+ */
+ spec = g_param_spec_int64("step",
+ "Step",
+ "Slicing step",
+ G_MININT64,
+ G_MAXINT64,
+ options.step,
+ static_cast<GParamFlags>(G_PARAM_READWRITE));
+ g_object_class_install_property(gobject_class, PROP_LIST_SLICE_OPTIONS_STEP,
spec);
+
+ /**
+ * GArrowListSliceOptions:return-fixed-size-list:
+ *
+ * Whether to return a FixedSizeListArray. If
+ * #GARROW_LIST_SLICE_RETURN_FIXED_SIZE_LIST_TRUE and stop is after a list
element's
+ * length, nulls will be appended to create the requested slice size. If
+ * #GARROW_LIST_SLICE_RETURN_FIXED_SIZE_LIST_AUTO (default), will return
whatever type
+ * it got in.
+ *
+ * Since: 23.0.0
+ */
+ spec = g_param_spec_enum(
+ "return-fixed-size-list",
+ "Return fixed size list",
+ "Whether to return a FixedSizeListArray. If TRUE and stop is after a list
element's "
+ "length, nulls will be appended to create the requested slice size. If
AUTO "
+ "(default), will return whatever type it got in",
+ GARROW_TYPE_LIST_SLICE_RETURN_FIXED_SIZE_LIST,
+ GARROW_LIST_SLICE_RETURN_FIXED_SIZE_LIST_AUTO,
+ static_cast<GParamFlags>(G_PARAM_READWRITE));
+ g_object_class_install_property(gobject_class,
+
PROP_LIST_SLICE_OPTIONS_RETURN_FIXED_SIZE_LIST,
+ spec);
+}
+
+/**
+ * garrow_list_slice_options_new:
+ *
+ * Returns: A newly created #GArrowListSliceOptions.
+ *
+ * Since: 23.0.0
+ */
+GArrowListSliceOptions *
+garrow_list_slice_options_new(void)
+{
+ auto options = g_object_new(GARROW_TYPE_LIST_SLICE_OPTIONS, nullptr);
+ return GARROW_LIST_SLICE_OPTIONS(options);
+}
+
G_END_DECLS
arrow::Result<arrow::FieldRef>
@@ -8566,3 +8780,38 @@ garrow_map_lookup_options_get_raw(GArrowMapLookupOptions
*options)
return static_cast<arrow::compute::MapLookupOptions *>(
garrow_function_options_get_raw(GARROW_FUNCTION_OPTIONS(options)));
}
+
+GArrowListSliceOptions *
+garrow_list_slice_options_new_raw(const arrow::compute::ListSliceOptions
*arrow_options)
+{
+ gint64 stop_value = GARROW_LIST_SLICE_OPTIONS_STOP_UNSPECIFIED;
+ if (arrow_options->stop.has_value()) {
+ stop_value = arrow_options->stop.value();
+ }
+ GArrowListSliceReturnFixedSizeList return_fixed_size_list_value =
+ GARROW_LIST_SLICE_RETURN_FIXED_SIZE_LIST_AUTO;
+ if (arrow_options->return_fixed_size_list.has_value()) {
+ if (arrow_options->return_fixed_size_list.value()) {
+ return_fixed_size_list_value =
GARROW_LIST_SLICE_RETURN_FIXED_SIZE_LIST_TRUE;
+ } else {
+ return_fixed_size_list_value =
GARROW_LIST_SLICE_RETURN_FIXED_SIZE_LIST_FALSE;
+ }
+ }
+ return GARROW_LIST_SLICE_OPTIONS(g_object_new(GARROW_TYPE_LIST_SLICE_OPTIONS,
+ "start",
+ arrow_options->start,
+ "stop",
+ stop_value,
+ "step",
+ arrow_options->step,
+ "return-fixed-size-list",
+ return_fixed_size_list_value,
+ NULL));
+}
+
+arrow::compute::ListSliceOptions *
+garrow_list_slice_options_get_raw(GArrowListSliceOptions *options)
+{
+ return static_cast<arrow::compute::ListSliceOptions *>(
+ 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 c5166a663e..065cf11451 100644
--- a/c_glib/arrow-glib/compute.h
+++ b/c_glib/arrow-glib/compute.h
@@ -1372,4 +1372,52 @@ GArrowMapLookupOptions *
garrow_map_lookup_options_new(GArrowScalar *query_key,
GArrowMapLookupOccurrence occurrence);
+/**
+ * GArrowListSliceReturnFixedSizeList:
+ * @GARROW_LIST_SLICE_RETURN_FIXED_SIZE_LIST_AUTO: Return the same type which
was passed
+ * in (default).
+ * @GARROW_LIST_SLICE_RETURN_FIXED_SIZE_LIST_FALSE: Explicitly return the same
type which
+ * was passed in.
+ * @GARROW_LIST_SLICE_RETURN_FIXED_SIZE_LIST_TRUE: Return a
FixedSizeListArray. If stop is
+ * after a list element's length, nulls will be appended to create the
requested slice
+ * size.
+ *
+ * They correspond to the values of
+ * `std::optional<bool>` for
`arrow::compute::ListSliceOptions::return_fixed_size_list`.
+ *
+ * Since: 23.0.0
+ */
+typedef enum {
+ GARROW_LIST_SLICE_RETURN_FIXED_SIZE_LIST_AUTO,
+ GARROW_LIST_SLICE_RETURN_FIXED_SIZE_LIST_FALSE,
+ GARROW_LIST_SLICE_RETURN_FIXED_SIZE_LIST_TRUE,
+} GArrowListSliceReturnFixedSizeList;
+
+/**
+ * GARROW_LIST_SLICE_OPTIONS_STOP_UNSPECIFIED:
+ *
+ * Sentinel value for the stop property in #GArrowListSliceOptions indicating
+ * that the stop value is not set. When this value is used, the slice will
+ * continue to the end of the list.
+ *
+ * Since: 23.0.0
+ */
+#define GARROW_LIST_SLICE_OPTIONS_STOP_UNSPECIFIED -1
+
+#define GARROW_TYPE_LIST_SLICE_OPTIONS
(garrow_list_slice_options_get_type())
+GARROW_AVAILABLE_IN_23_0
+G_DECLARE_DERIVABLE_TYPE(GArrowListSliceOptions,
+ garrow_list_slice_options,
+ GARROW,
+ LIST_SLICE_OPTIONS,
+ GArrowFunctionOptions)
+struct _GArrowListSliceOptionsClass
+{
+ GArrowFunctionOptionsClass parent_class;
+};
+
+GARROW_AVAILABLE_IN_23_0
+GArrowListSliceOptions *
+garrow_list_slice_options_new(void);
+
G_END_DECLS
diff --git a/c_glib/arrow-glib/compute.hpp b/c_glib/arrow-glib/compute.hpp
index fb5907a17b..15b365af33 100644
--- a/c_glib/arrow-glib/compute.hpp
+++ b/c_glib/arrow-glib/compute.hpp
@@ -231,3 +231,8 @@ GArrowMapLookupOptions *
garrow_map_lookup_options_new_raw(const arrow::compute::MapLookupOptions
*arrow_options);
arrow::compute::MapLookupOptions *
garrow_map_lookup_options_get_raw(GArrowMapLookupOptions *options);
+
+GArrowListSliceOptions *
+garrow_list_slice_options_new_raw(const arrow::compute::ListSliceOptions
*arrow_options);
+arrow::compute::ListSliceOptions *
+garrow_list_slice_options_get_raw(GArrowListSliceOptions *options);
diff --git a/c_glib/test/test-list-slice-options.rb
b/c_glib/test/test-list-slice-options.rb
new file mode 100644
index 0000000000..d41322c431
--- /dev/null
+++ b/c_glib/test/test-list-slice-options.rb
@@ -0,0 +1,122 @@
+# 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 TestListSliceOptions < Test::Unit::TestCase
+ include Helper::Buildable
+
+ def setup
+ @options = Arrow::ListSliceOptions.new
+ end
+
+ def test_start_property
+ assert_equal(0, @options.start)
+ @options.start = 2
+ assert_equal(2, @options.start)
+ end
+
+ def test_stop_property
+ assert_equal(Arrow::LIST_SLICE_OPTIONS_STOP_UNSPECIFIED, @options.stop)
+ @options.stop = 5
+ assert_equal(5, @options.stop)
+ @options.stop = Arrow::LIST_SLICE_OPTIONS_STOP_UNSPECIFIED
+ assert_equal(Arrow::LIST_SLICE_OPTIONS_STOP_UNSPECIFIED, @options.stop)
+ end
+
+ def test_step_property
+ assert_equal(1, @options.step)
+ @options.step = 2
+ assert_equal(2, @options.step)
+ end
+
+ def test_return_fixed_size_list_property
+ assert_equal(Arrow::ListSliceReturnFixedSizeList::AUTO,
+ @options.return_fixed_size_list)
+ @options.return_fixed_size_list = :true
+ assert_equal(Arrow::ListSliceReturnFixedSizeList::TRUE,
+ @options.return_fixed_size_list)
+ @options.return_fixed_size_list = :false
+ assert_equal(Arrow::ListSliceReturnFixedSizeList::FALSE,
+ @options.return_fixed_size_list)
+ @options.return_fixed_size_list = :auto
+ assert_equal(Arrow::ListSliceReturnFixedSizeList::AUTO,
+ @options.return_fixed_size_list)
+ end
+
+ def test_list_slice_function_with_step
+ args = [
+ Arrow::ArrayDatum.new(build_list_array(Arrow::Int8DataType.new,
+ [[1, 2, 3, 4, 5], [6, 7, 8, 9]])),
+ ]
+ @options.step = 2
+ list_slice_function = Arrow::Function.find("list_slice")
+ result = list_slice_function.execute(args, @options).value
+ assert_equal(build_list_array(Arrow::Int8DataType.new, [[1, 3, 5], [6,
8]]),
+ result)
+ end
+
+ def test_list_slice_function_without_stop
+ args = [
+ Arrow::ArrayDatum.new(build_list_array(Arrow::Int8DataType.new,
+ [[1, 2, 3], [4, 5]])),
+ ]
+ @options.start = 1
+ @options.stop = Arrow::LIST_SLICE_OPTIONS_STOP_UNSPECIFIED
+ list_slice_function = Arrow::Function.find("list_slice")
+ result = list_slice_function.execute(args, @options).value
+ assert_equal(build_list_array(Arrow::Int8DataType.new, [[2, 3], [5]]),
+ result)
+ end
+
+ def test_list_slice_function_with_return_fixed_size_list_auto
+ args = [
+
Arrow::ArrayDatum.new(build_fixed_size_list_array(Arrow::Int8DataType.new, 2,
+ [[1, 2], [3, 4]])),
+ ]
+ @options.start = 1
+ list_slice_function = Arrow::Function.find("list_slice")
+ result = list_slice_function.execute(args, @options).value
+ assert_equal(build_fixed_size_list_array(Arrow::Int8DataType.new, 1, [[2],
[4]]),
+ result)
+ end
+
+ def test_list_slice_function_with_return_fixed_size_list_true
+ args = [
+ Arrow::ArrayDatum.new(build_list_array(Arrow::Int8DataType.new,
+ [[1, 2, 3], [4, 5]])),
+ ]
+ @options.start = 1
+ @options.stop = 3
+ @options.return_fixed_size_list = :true
+ list_slice_function = Arrow::Function.find("list_slice")
+ result = list_slice_function.execute(args, @options).value
+ assert_equal(build_fixed_size_list_array(Arrow::Int8DataType.new, 2, [[2,
3], [5, nil]]),
+ result)
+ end
+
+ def test_list_slice_function_with_return_fixed_size_list_false
+ args = [
+
Arrow::ArrayDatum.new(build_fixed_size_list_array(Arrow::Int8DataType.new, 2,
+ [[1, 2], [3, 4]])),
+ ]
+ @options.start = 1
+ @options.return_fixed_size_list = :false
+ list_slice_function = Arrow::Function.find("list_slice")
+ result = list_slice_function.execute(args, @options).value
+ assert_equal(build_list_array(Arrow::Int8DataType.new, [[2], [4]]),
+ result)
+ end
+end
diff --git a/ruby/red-arrow/lib/arrow/libraries.rb
b/ruby/red-arrow/lib/arrow/libraries.rb
index 3e1b4eb3f8..8135a2d4e7 100644
--- a/ruby/red-arrow/lib/arrow/libraries.rb
+++ b/ruby/red-arrow/lib/arrow/libraries.rb
@@ -79,6 +79,7 @@ require_relative "large-list-array-builder"
require_relative "large-list-data-type"
require_relative "list-array-builder"
require_relative "list-data-type"
+require_relative "list-slice-options"
require_relative "map-array"
require_relative "map-array-builder"
require_relative "map-data-type"
diff --git a/ruby/red-arrow/lib/arrow/list-slice-options.rb
b/ruby/red-arrow/lib/arrow/list-slice-options.rb
new file mode 100644
index 0000000000..563b7c0e92
--- /dev/null
+++ b/ruby/red-arrow/lib/arrow/list-slice-options.rb
@@ -0,0 +1,76 @@
+# 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.
+
+module Arrow
+ class ListSliceOptions
+ alias_method :return_fixed_size_list_raw, :return_fixed_size_list
+ private :return_fixed_size_list_raw
+
+ RETURN_FIXED_SIZE_GLIB_TO_RUBY = {
+ ListSliceReturnFixedSizeList::AUTO => nil,
+ ListSliceReturnFixedSizeList::TRUE => true,
+ ListSliceReturnFixedSizeList::FALSE => false,
+ }.freeze
+
+ RETURN_FIXED_SIZE_RUBY_TO_GLIB =
RETURN_FIXED_SIZE_GLIB_TO_RUBY.invert.freeze
+
+ # Whether to return a FixedSizeListArray. If true _and_ stop is after a
+ # list element’s length, nil values will be appended to create the
requested
+ # slice size. The default of nil will return the same type which was
passed in.
+ #
+ # @since 23.0.0
+ def return_fixed_size_list
+ RETURN_FIXED_SIZE_GLIB_TO_RUBY.fetch(
+ return_fixed_size_list_raw,
+ return_fixed_size_list_raw)
+ end
+
+ alias_method :return_fixed_size_list_raw=, :return_fixed_size_list=
+ private :return_fixed_size_list_raw=
+
+ # Whether to return a FixedSizeListArray. If true _and_ stop is after a
+ # list element’s length, nil values will be appended to create the
requested
+ # slice size. The default of nil will return the same type which was
passed in.
+ #
+ # @since 23.0.0
+ def return_fixed_size_list=(return_fixed_size_list)
+ self.return_fixed_size_list_raw = RETURN_FIXED_SIZE_RUBY_TO_GLIB.fetch(
+ return_fixed_size_list,
+ return_fixed_size_list)
+ end
+
+ alias_method :stop_raw, :stop
+ private :stop_raw
+
+ # Optional stop of list slicing. If set to nil, then slice to end.
+ #
+ # @since 23.0.0
+ def stop
+ stop_raw == LIST_SLICE_OPTIONS_STOP_UNSPECIFIED ? nil : stop_raw
+ end
+
+ alias_method :stop_raw=, :stop=
+ private :stop_raw=
+
+ # Optional stop of list slicing. If set to nil, then slice to end.
+ #
+ # @since 23.0.0
+ def stop=(stop)
+ self.stop_raw = stop.nil? ? LIST_SLICE_OPTIONS_STOP_UNSPECIFIED : stop
+ end
+ end
+end
diff --git a/ruby/red-arrow/test/test-list-slice-options.rb
b/ruby/red-arrow/test/test-list-slice-options.rb
new file mode 100644
index 0000000000..68ad5ee354
--- /dev/null
+++ b/ruby/red-arrow/test/test-list-slice-options.rb
@@ -0,0 +1,90 @@
+# 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 TestListSliceOptions < Test::Unit::TestCase
+ def setup
+ @options = Arrow::ListSliceOptions.new
+ end
+
+ def test_stop_property
+ assert_equal(nil, @options.stop)
+ @options.stop = 5
+ assert_equal(5, @options.stop)
+ @options.stop = nil
+ assert_equal(nil, @options.stop)
+ end
+
+ def test_return_fixed_size_list_property
+ assert_equal(nil, @options.return_fixed_size_list)
+ @options.return_fixed_size_list = true
+ assert_equal(true, @options.return_fixed_size_list)
+ @options.return_fixed_size_list = false
+ assert_equal(false, @options.return_fixed_size_list)
+ @options.return_fixed_size_list = nil
+ assert_equal(nil, @options.return_fixed_size_list)
+ end
+
+ def test_list_slice_function_without_stop
+ args = [
+ Arrow::ArrayDatum.new(Arrow::ListArray.new([:list, :int8], [[1, 2, 3],
[4, 5]])),
+ ]
+ @options.start = 1
+ @options.stop = nil
+ list_slice_function = Arrow::Function.find("list_slice")
+ result = list_slice_function.execute(args, @options).value
+ assert_equal(Arrow::ListArray.new([:list, :int8], [[2, 3], [5]]),
+ result)
+ end
+
+ def test_list_slice_function_with_return_fixed_size_list_auto
+ args = [
+ Arrow::ArrayDatum.new(Arrow::FixedSizeListArray.new([:fixed_size_list,
:int8, 2],
+ [[1, 2], [3, 4]])),
+ ]
+ @options.start = 1
+ list_slice_function = Arrow::Function.find("list_slice")
+ result = list_slice_function.execute(args, @options).value
+ assert_equal(Arrow::FixedSizeListArray.new([:fixed_size_list, :int8, 1],
[[2], [4]]),
+ result)
+ end
+
+ def test_list_slice_function_with_return_fixed_size_list_true
+ args = [
+ Arrow::ArrayDatum.new(Arrow::ListArray.new([:list, :int8], [[1, 2, 3],
[4, 5]])),
+ ]
+ @options.start = 1
+ @options.stop = 3
+ @options.return_fixed_size_list = true
+ list_slice_function = Arrow::Function.find("list_slice")
+ result = list_slice_function.execute(args, @options).value
+ assert_equal(Arrow::FixedSizeListArray.new([:fixed_size_list, :int8, 2],
[[2, 3], [5, nil]]),
+ result)
+ end
+
+ def test_list_slice_function_with_return_fixed_size_list_false
+ args = [
+ Arrow::ArrayDatum.new(Arrow::FixedSizeListArray.new([:fixed_size_list,
:int8, 2],
+ [[1, 2], [3, 4]])),
+ ]
+ @options.start = 1
+ @options.return_fixed_size_list = false
+ list_slice_function = Arrow::Function.find("list_slice")
+ result = list_slice_function.execute(args, @options).value
+ assert_equal(Arrow::ListArray.new([:list, :int8], [[2], [4]]),
+ result)
+ end
+end