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
116 changes: 116 additions & 0 deletions c_glib/arrow-glib/compute.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*/

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