Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
166 changes: 166 additions & 0 deletions c_glib/arrow-glib/compute.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*/

Expand Down Expand Up @@ -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>
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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)));
}
13 changes: 13 additions & 0 deletions c_glib/arrow-glib/compute.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
5 changes: 5 additions & 0 deletions c_glib/arrow-glib/compute.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
55 changes: 55 additions & 0 deletions c_glib/test/test-slice-options.rb
Original file line number Diff line number Diff line change
@@ -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
Loading