Skip to content

Commit 8e708d8

Browse files
committed
Add GArrowElementWiseAggregateOptions
1 parent 5499afa commit 8e708d8

File tree

4 files changed

+195
-0
lines changed

4 files changed

+195
-0
lines changed

c_glib/arrow-glib/compute.cpp

Lines changed: 126 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -251,6 +251,9 @@ G_BEGIN_DECLS
251251
* #GArrowStructFieldOptions is a class to customize the `struct_field`
252252
* function.
253253
*
254+
* #GArrowElementWiseAggregateOptions is a class to customize element-wise
255+
* aggregate functions such as `min_element_wise` and `max_element_wise`.
256+
*
254257
* There are many functions to compute data on an array.
255258
*/
256259

@@ -6338,6 +6341,105 @@ garrow_struct_field_options_new(void)
63386341
return GARROW_STRUCT_FIELD_OPTIONS(options);
63396342
}
63406343

6344+
enum {
6345+
PROP_ELEMENT_WISE_AGGREGATE_OPTIONS_SKIP_NULLS = 1,
6346+
};
6347+
6348+
G_DEFINE_TYPE(GArrowElementWiseAggregateOptions,
6349+
garrow_element_wise_aggregate_options,
6350+
GARROW_TYPE_FUNCTION_OPTIONS)
6351+
6352+
static void
6353+
garrow_element_wise_aggregate_options_set_property(GObject *object,
6354+
guint prop_id,
6355+
const GValue *value,
6356+
GParamSpec *pspec)
6357+
{
6358+
auto options = garrow_element_wise_aggregate_options_get_raw(
6359+
GARROW_ELEMENT_WISE_AGGREGATE_OPTIONS(object));
6360+
6361+
switch (prop_id) {
6362+
case PROP_ELEMENT_WISE_AGGREGATE_OPTIONS_SKIP_NULLS:
6363+
options->skip_nulls = g_value_get_boolean(value);
6364+
break;
6365+
default:
6366+
G_OBJECT_WARN_INVALID_PROPERTY_ID(object, prop_id, pspec);
6367+
break;
6368+
}
6369+
}
6370+
6371+
static void
6372+
garrow_element_wise_aggregate_options_get_property(GObject *object,
6373+
guint prop_id,
6374+
GValue *value,
6375+
GParamSpec *pspec)
6376+
{
6377+
auto options = garrow_element_wise_aggregate_options_get_raw(
6378+
GARROW_ELEMENT_WISE_AGGREGATE_OPTIONS(object));
6379+
6380+
switch (prop_id) {
6381+
case PROP_ELEMENT_WISE_AGGREGATE_OPTIONS_SKIP_NULLS:
6382+
g_value_set_boolean(value, options->skip_nulls);
6383+
break;
6384+
default:
6385+
G_OBJECT_WARN_INVALID_PROPERTY_ID(object, prop_id, pspec);
6386+
break;
6387+
}
6388+
}
6389+
6390+
static void
6391+
garrow_element_wise_aggregate_options_init(GArrowElementWiseAggregateOptions *object)
6392+
{
6393+
auto priv = GARROW_FUNCTION_OPTIONS_GET_PRIVATE(object);
6394+
priv->options = static_cast<arrow::compute::FunctionOptions *>(
6395+
new arrow::compute::ElementWiseAggregateOptions());
6396+
}
6397+
6398+
static void
6399+
garrow_element_wise_aggregate_options_class_init(
6400+
GArrowElementWiseAggregateOptionsClass *klass)
6401+
{
6402+
auto gobject_class = G_OBJECT_CLASS(klass);
6403+
6404+
gobject_class->set_property = garrow_element_wise_aggregate_options_set_property;
6405+
gobject_class->get_property = garrow_element_wise_aggregate_options_get_property;
6406+
6407+
arrow::compute::ElementWiseAggregateOptions options;
6408+
6409+
GParamSpec *spec;
6410+
/**
6411+
* GArrowElementWiseAggregateOptions:skip-nulls:
6412+
*
6413+
* Whether to skip (ignore) nulls in the input.
6414+
* If false, any null in the input forces the output to null.
6415+
*
6416+
* Since: 23.0.0
6417+
*/
6418+
spec = g_param_spec_boolean("skip-nulls",
6419+
"Skip nulls",
6420+
"Whether to skip (ignore) nulls in the input. If false, "
6421+
"any null in the input forces the output to null",
6422+
options.skip_nulls,
6423+
static_cast<GParamFlags>(G_PARAM_READWRITE));
6424+
g_object_class_install_property(gobject_class,
6425+
PROP_ELEMENT_WISE_AGGREGATE_OPTIONS_SKIP_NULLS,
6426+
spec);
6427+
}
6428+
6429+
/**
6430+
* garrow_element_wise_aggregate_options_new:
6431+
*
6432+
* Returns: A newly created #GArrowElementWiseAggregateOptions.
6433+
*
6434+
* Since: 23.0.0
6435+
*/
6436+
GArrowElementWiseAggregateOptions *
6437+
garrow_element_wise_aggregate_options_new(void)
6438+
{
6439+
auto options = g_object_new(GARROW_TYPE_ELEMENT_WISE_AGGREGATE_OPTIONS, NULL);
6440+
return GARROW_ELEMENT_WISE_AGGREGATE_OPTIONS(options);
6441+
}
6442+
63416443
G_END_DECLS
63426444

63436445
arrow::Result<arrow::FieldRef>
@@ -6469,6 +6571,12 @@ garrow_function_options_new_raw(const arrow::compute::FunctionOptions *arrow_opt
64696571
static_cast<const arrow::compute::StructFieldOptions *>(arrow_options);
64706572
auto options = garrow_struct_field_options_new_raw(arrow_struct_field_options);
64716573
return GARROW_FUNCTION_OPTIONS(options);
6574+
} else if (arrow_type_name == "ElementWiseAggregateOptions") {
6575+
const auto arrow_element_wise_aggregate_options =
6576+
static_cast<const arrow::compute::ElementWiseAggregateOptions *>(arrow_options);
6577+
auto options =
6578+
garrow_element_wise_aggregate_options_new_raw(arrow_element_wise_aggregate_options);
6579+
return GARROW_FUNCTION_OPTIONS(options);
64726580
} else {
64736581
auto options = g_object_new(GARROW_TYPE_FUNCTION_OPTIONS, NULL);
64746582
return GARROW_FUNCTION_OPTIONS(options);
@@ -6987,3 +7095,21 @@ garrow_struct_field_options_get_raw(GArrowStructFieldOptions *options)
69877095
return static_cast<arrow::compute::StructFieldOptions *>(
69887096
garrow_function_options_get_raw(GARROW_FUNCTION_OPTIONS(options)));
69897097
}
7098+
7099+
GArrowElementWiseAggregateOptions *
7100+
garrow_element_wise_aggregate_options_new_raw(
7101+
const arrow::compute::ElementWiseAggregateOptions *arrow_options)
7102+
{
7103+
return GARROW_ELEMENT_WISE_AGGREGATE_OPTIONS(
7104+
g_object_new(GARROW_TYPE_ELEMENT_WISE_AGGREGATE_OPTIONS,
7105+
"skip-nulls",
7106+
arrow_options->skip_nulls,
7107+
NULL));
7108+
}
7109+
7110+
arrow::compute::ElementWiseAggregateOptions *
7111+
garrow_element_wise_aggregate_options_get_raw(GArrowElementWiseAggregateOptions *options)
7112+
{
7113+
return static_cast<arrow::compute::ElementWiseAggregateOptions *>(
7114+
garrow_function_options_get_raw(GARROW_FUNCTION_OPTIONS(options)));
7115+
}

c_glib/arrow-glib/compute.h

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1122,4 +1122,21 @@ GARROW_AVAILABLE_IN_16_0
11221122
GArrowStructFieldOptions *
11231123
garrow_struct_field_options_new(void);
11241124

1125+
#define GARROW_TYPE_ELEMENT_WISE_AGGREGATE_OPTIONS \
1126+
(garrow_element_wise_aggregate_options_get_type())
1127+
GARROW_AVAILABLE_IN_23_0
1128+
G_DECLARE_DERIVABLE_TYPE(GArrowElementWiseAggregateOptions,
1129+
garrow_element_wise_aggregate_options,
1130+
GARROW,
1131+
ELEMENT_WISE_AGGREGATE_OPTIONS,
1132+
GArrowFunctionOptions)
1133+
struct _GArrowElementWiseAggregateOptionsClass
1134+
{
1135+
GArrowFunctionOptionsClass parent_class;
1136+
};
1137+
1138+
GARROW_AVAILABLE_IN_23_0
1139+
GArrowElementWiseAggregateOptions *
1140+
garrow_element_wise_aggregate_options_new(void);
1141+
11251142
G_END_DECLS

c_glib/arrow-glib/compute.hpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -175,3 +175,9 @@ garrow_struct_field_options_new_raw(
175175
const arrow::compute::StructFieldOptions *arrow_options);
176176
arrow::compute::StructFieldOptions *
177177
garrow_struct_field_options_get_raw(GArrowStructFieldOptions *options);
178+
179+
GArrowElementWiseAggregateOptions *
180+
garrow_element_wise_aggregate_options_new_raw(
181+
const arrow::compute::ElementWiseAggregateOptions *arrow_options);
182+
arrow::compute::ElementWiseAggregateOptions *
183+
garrow_element_wise_aggregate_options_get_raw(GArrowElementWiseAggregateOptions *options);
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
# Licensed to the Apache Software Foundation (ASF) under one
2+
# or more contributor license agreements. See the NOTICE file
3+
# distributed with this work for additional information
4+
# regarding copyright ownership. The ASF licenses this file
5+
# to you under the Apache License, Version 2.0 (the
6+
# "License"); you may not use this file except in compliance
7+
# with the License. You may obtain a copy of the License at
8+
#
9+
# http://www.apache.org/licenses/LICENSE-2.0
10+
#
11+
# Unless required by applicable law or agreed to in writing,
12+
# software distributed under the License is distributed on an
13+
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14+
# KIND, either express or implied. See the License for the
15+
# specific language governing permissions and limitations
16+
# under the License.
17+
18+
class TestElementWiseAggregateOptions < Test::Unit::TestCase
19+
include Helper::Buildable
20+
21+
def setup
22+
@options = Arrow::ElementWiseAggregateOptions.new
23+
end
24+
25+
def test_skip_nulls_property
26+
assert do
27+
@options.skip_nulls?
28+
end
29+
@options.skip_nulls = false
30+
assert do
31+
!@options.skip_nulls?
32+
end
33+
end
34+
35+
def test_min_element_wise_function_with_skip_nulls_false
36+
args = [
37+
Arrow::ArrayDatum.new(build_int64_array([1, nil, 3])),
38+
Arrow::ArrayDatum.new(build_int64_array([4, 1, 5])),
39+
]
40+
@options.skip_nulls = false
41+
min_element_wise_function = Arrow::Function.find("min_element_wise")
42+
assert_equal(build_int64_array([1, nil, 3]),
43+
min_element_wise_function.execute(args, @options).value)
44+
end
45+
end
46+

0 commit comments

Comments
 (0)