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
123 changes: 121 additions & 2 deletions c_glib/arrow-glib/compute.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -270,8 +270,8 @@ G_BEGIN_DECLS
* #GArrowExtractRegexOptions is a class to customize the `extract_regex`
* function.
*
* #GArrowExtractRegexSpanOptions is a class to customize the `extract_regex_span`
* function.
* #GArrowExtractRegexSpanOptions is a class to customize the
* `extract_regex_span` function.
*
* #GArrowJoinOptions is a class to customize the `binary_join_element_wise`
* function.
Expand Down Expand Up @@ -312,6 +312,9 @@ G_BEGIN_DECLS
* #GArrowReplaceSubstringOptions is a class to customize the
* `replace_substring` and `replace_substring_regex` functions.
*
* #GArrowRoundBinaryOptions is a class to customize the
* `round_binary` function.
*
* There are many functions to compute data on an array.
*/

Expand Down Expand Up @@ -9062,6 +9065,99 @@ garrow_replace_substring_options_new(void)
g_object_new(GARROW_TYPE_REPLACE_SUBSTRING_OPTIONS, nullptr));
}

enum {
PROP_ROUND_BINARY_OPTIONS_MODE = 1,
};

G_DEFINE_TYPE(GArrowRoundBinaryOptions,
garrow_round_binary_options,
GARROW_TYPE_FUNCTION_OPTIONS)

static void
garrow_round_binary_options_set_property(GObject *object,
guint prop_id,
const GValue *value,
GParamSpec *pspec)
{
auto options = garrow_round_binary_options_get_raw(GARROW_ROUND_BINARY_OPTIONS(object));

switch (prop_id) {
case PROP_ROUND_BINARY_OPTIONS_MODE:
options->round_mode = static_cast<arrow::compute::RoundMode>(g_value_get_enum(value));
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID(object, prop_id, pspec);
break;
}
}

static void
garrow_round_binary_options_get_property(GObject *object,
guint prop_id,
GValue *value,
GParamSpec *pspec)
{
auto options = garrow_round_binary_options_get_raw(GARROW_ROUND_BINARY_OPTIONS(object));

switch (prop_id) {
case PROP_ROUND_BINARY_OPTIONS_MODE:
g_value_set_enum(value, static_cast<GArrowRoundMode>(options->round_mode));
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID(object, prop_id, pspec);
break;
}
}

static void
garrow_round_binary_options_init(GArrowRoundBinaryOptions *object)
{
auto arrow_priv = GARROW_FUNCTION_OPTIONS_GET_PRIVATE(object);
arrow_priv->options = static_cast<arrow::compute::FunctionOptions *>(
new arrow::compute::RoundBinaryOptions());
}

static void
garrow_round_binary_options_class_init(GArrowRoundBinaryOptionsClass *klass)
{
auto gobject_class = G_OBJECT_CLASS(klass);

gobject_class->set_property = garrow_round_binary_options_set_property;
gobject_class->get_property = garrow_round_binary_options_get_property;

arrow::compute::RoundBinaryOptions options;

GParamSpec *spec;
/**
* GArrowRoundBinaryOptions:mode:
*
* The rounding and tie-breaking mode.
*
* Since: 23.0.0
*/
spec = g_param_spec_enum("mode",
"Mode",
"The rounding and tie-breaking mode",
GARROW_TYPE_ROUND_MODE,
static_cast<GArrowRoundMode>(options.round_mode),
static_cast<GParamFlags>(G_PARAM_READWRITE));
g_object_class_install_property(gobject_class, PROP_ROUND_BINARY_OPTIONS_MODE, spec);
}

/**
* garrow_round_binary_options_new:
*
* Returns: A newly created #GArrowRoundBinaryOptions.
*
* Since: 23.0.0
*/
GArrowRoundBinaryOptions *
garrow_round_binary_options_new(void)
{
return GARROW_ROUND_BINARY_OPTIONS(
g_object_new(GARROW_TYPE_ROUND_BINARY_OPTIONS, nullptr));
}

G_END_DECLS

arrow::Result<arrow::FieldRef>
Expand Down Expand Up @@ -9292,6 +9388,11 @@ garrow_function_options_new_raw(const arrow::compute::FunctionOptions *arrow_opt
auto options =
garrow_replace_substring_options_new_raw(arrow_replace_substring_options);
return GARROW_FUNCTION_OPTIONS(options);
} else if (arrow_type_name == "RoundBinaryOptions") {
const auto arrow_round_binary_options =
static_cast<const arrow::compute::RoundBinaryOptions *>(arrow_options);
auto options = garrow_round_binary_options_new_raw(arrow_round_binary_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 @@ -10224,3 +10325,21 @@ garrow_replace_substring_options_get_raw(GArrowReplaceSubstringOptions *options)
return static_cast<arrow::compute::ReplaceSubstringOptions *>(
garrow_function_options_get_raw(GARROW_FUNCTION_OPTIONS(options)));
}

GArrowRoundBinaryOptions *
garrow_round_binary_options_new_raw(
const arrow::compute::RoundBinaryOptions *arrow_options)
{
return GARROW_ROUND_BINARY_OPTIONS(
g_object_new(GARROW_TYPE_ROUND_BINARY_OPTIONS,
"mode",
static_cast<GArrowRoundMode>(arrow_options->round_mode),
nullptr));
}

arrow::compute::RoundBinaryOptions *
garrow_round_binary_options_get_raw(GArrowRoundBinaryOptions *options)
{
return static_cast<arrow::compute::RoundBinaryOptions *>(
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 @@ -1583,4 +1583,20 @@ GARROW_AVAILABLE_IN_23_0
GArrowReplaceSubstringOptions *
garrow_replace_substring_options_new(void);

#define GARROW_TYPE_ROUND_BINARY_OPTIONS (garrow_round_binary_options_get_type())
GARROW_AVAILABLE_IN_23_0
G_DECLARE_DERIVABLE_TYPE(GArrowRoundBinaryOptions,
garrow_round_binary_options,
GARROW,
ROUND_BINARY_OPTIONS,
GArrowFunctionOptions)
struct _GArrowRoundBinaryOptionsClass
{
GArrowFunctionOptionsClass parent_class;
};

GARROW_AVAILABLE_IN_23_0
GArrowRoundBinaryOptions *
garrow_round_binary_options_new(void);

G_END_DECLS
6 changes: 6 additions & 0 deletions c_glib/arrow-glib/compute.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -286,3 +286,9 @@ garrow_replace_substring_options_new_raw(
const arrow::compute::ReplaceSubstringOptions *arrow_options);
arrow::compute::ReplaceSubstringOptions *
garrow_replace_substring_options_get_raw(GArrowReplaceSubstringOptions *options);

GArrowRoundBinaryOptions *
garrow_round_binary_options_new_raw(
const arrow::compute::RoundBinaryOptions *arrow_options);
arrow::compute::RoundBinaryOptions *
garrow_round_binary_options_get_raw(GArrowRoundBinaryOptions *options);
42 changes: 42 additions & 0 deletions c_glib/test/test-round-binary-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 TestRoundBinaryOptions < Test::Unit::TestCase
include Helper::Buildable

def setup
@options = Arrow::RoundBinaryOptions.new
end

def test_mode
assert_equal(Arrow::RoundMode::HALF_TO_EVEN, @options.mode)
@options.mode = :down
assert_equal(Arrow::RoundMode::DOWN, @options.mode)
end

def test_round_binary_function
args = [
Arrow::ArrayDatum.new(build_double_array([5.0])),
Arrow::ArrayDatum.new(build_int32_array([-1])),
]
@options.mode = :half_towards_zero
round_binary_function = Arrow::Function.find("round_binary")
result = round_binary_function.execute(args, @options).value
expected = build_double_array([0.0])
assert_equal(expected, result)
end
end
Loading