Skip to content

Commit a725352

Browse files
committed
Add GArrowNullOptions
1 parent 4127ca2 commit a725352

File tree

4 files changed

+174
-0
lines changed

4 files changed

+174
-0
lines changed

c_glib/arrow-glib/compute.cpp

Lines changed: 112 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -269,6 +269,8 @@ G_BEGIN_DECLS
269269
* #GArrowExtractRegexOptions is a class to customize the `extract_regex`
270270
* function.
271271
*
272+
* #GArrowNullOptions is a class to customize the `is_null` function.
273+
*
272274
* There are many functions to compute data on an array.
273275
*/
274276

@@ -7091,6 +7093,95 @@ garrow_extract_regex_options_new(void)
70917093
return GARROW_EXTRACT_REGEX_OPTIONS(options);
70927094
}
70937095

7096+
enum {
7097+
PROP_NULL_OPTIONS_NAN_IS_NULL = 1,
7098+
};
7099+
7100+
G_DEFINE_TYPE(GArrowNullOptions, garrow_null_options, GARROW_TYPE_FUNCTION_OPTIONS)
7101+
7102+
static void
7103+
garrow_null_options_set_property(GObject *object,
7104+
guint prop_id,
7105+
const GValue *value,
7106+
GParamSpec *pspec)
7107+
{
7108+
auto options = garrow_null_options_get_raw(GARROW_NULL_OPTIONS(object));
7109+
7110+
switch (prop_id) {
7111+
case PROP_NULL_OPTIONS_NAN_IS_NULL:
7112+
options->nan_is_null = g_value_get_boolean(value);
7113+
break;
7114+
default:
7115+
G_OBJECT_WARN_INVALID_PROPERTY_ID(object, prop_id, pspec);
7116+
break;
7117+
}
7118+
}
7119+
7120+
static void
7121+
garrow_null_options_get_property(GObject *object,
7122+
guint prop_id,
7123+
GValue *value,
7124+
GParamSpec *pspec)
7125+
{
7126+
auto options = garrow_null_options_get_raw(GARROW_NULL_OPTIONS(object));
7127+
7128+
switch (prop_id) {
7129+
case PROP_NULL_OPTIONS_NAN_IS_NULL:
7130+
g_value_set_boolean(value, options->nan_is_null);
7131+
break;
7132+
default:
7133+
G_OBJECT_WARN_INVALID_PROPERTY_ID(object, prop_id, pspec);
7134+
break;
7135+
}
7136+
}
7137+
7138+
static void
7139+
garrow_null_options_init(GArrowNullOptions *object)
7140+
{
7141+
auto priv = GARROW_FUNCTION_OPTIONS_GET_PRIVATE(object);
7142+
priv->options =
7143+
static_cast<arrow::compute::FunctionOptions *>(new arrow::compute::NullOptions());
7144+
}
7145+
7146+
static void
7147+
garrow_null_options_class_init(GArrowNullOptionsClass *klass)
7148+
{
7149+
auto gobject_class = G_OBJECT_CLASS(klass);
7150+
7151+
gobject_class->set_property = garrow_null_options_set_property;
7152+
gobject_class->get_property = garrow_null_options_get_property;
7153+
7154+
arrow::compute::NullOptions options;
7155+
7156+
GParamSpec *spec;
7157+
/**
7158+
* GArrowNullOptions:nan-is-null:
7159+
*
7160+
* Whether floating-point NaN values are considered null.
7161+
*
7162+
* Since: 23.0.0
7163+
*/
7164+
spec = g_param_spec_boolean("nan-is-null",
7165+
"NaN is null",
7166+
"Whether floating-point NaN values are considered null",
7167+
options.nan_is_null,
7168+
static_cast<GParamFlags>(G_PARAM_READWRITE));
7169+
g_object_class_install_property(gobject_class, PROP_NULL_OPTIONS_NAN_IS_NULL, spec);
7170+
}
7171+
7172+
/**
7173+
* garrow_null_options_new:
7174+
*
7175+
* Returns: A newly created #GArrowNullOptions.
7176+
*
7177+
* Since: 23.0.0
7178+
*/
7179+
GArrowNullOptions *
7180+
garrow_null_options_new(void)
7181+
{
7182+
return GARROW_NULL_OPTIONS(g_object_new(GARROW_TYPE_NULL_OPTIONS, NULL));
7183+
}
7184+
70947185
G_END_DECLS
70957186

70967187
arrow::Result<arrow::FieldRef>
@@ -7254,6 +7345,11 @@ garrow_function_options_new_raw(const arrow::compute::FunctionOptions *arrow_opt
72547345
static_cast<const arrow::compute::ExtractRegexOptions *>(arrow_options);
72557346
auto options = garrow_extract_regex_options_new_raw(arrow_extract_regex_options);
72567347
return GARROW_FUNCTION_OPTIONS(options);
7348+
} else if (arrow_type_name == "NullOptions") {
7349+
const auto arrow_null_options =
7350+
static_cast<const arrow::compute::NullOptions *>(arrow_options);
7351+
auto options = garrow_null_options_new_raw(arrow_null_options);
7352+
return GARROW_FUNCTION_OPTIONS(options);
72577353
} else {
72587354
auto options = g_object_new(GARROW_TYPE_FUNCTION_OPTIONS, NULL);
72597355
return GARROW_FUNCTION_OPTIONS(options);
@@ -7893,3 +7989,19 @@ garrow_extract_regex_options_get_raw(GArrowExtractRegexOptions *options)
78937989
return static_cast<arrow::compute::ExtractRegexOptions *>(
78947990
garrow_function_options_get_raw(GARROW_FUNCTION_OPTIONS(options)));
78957991
}
7992+
7993+
GArrowNullOptions *
7994+
garrow_null_options_new_raw(const arrow::compute::NullOptions *arrow_options)
7995+
{
7996+
return GARROW_NULL_OPTIONS(g_object_new(GARROW_TYPE_NULL_OPTIONS,
7997+
"nan-is-null",
7998+
arrow_options->nan_is_null,
7999+
NULL));
8000+
}
8001+
8002+
arrow::compute::NullOptions *
8003+
garrow_null_options_get_raw(GArrowNullOptions *options)
8004+
{
8005+
return static_cast<arrow::compute::NullOptions *>(
8006+
garrow_function_options_get_raw(GARROW_FUNCTION_OPTIONS(options)));
8007+
}

c_glib/arrow-glib/compute.h

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1272,4 +1272,17 @@ GARROW_AVAILABLE_IN_23_0
12721272
GArrowExtractRegexOptions *
12731273
garrow_extract_regex_options_new(void);
12741274

1275+
#define GARROW_TYPE_NULL_OPTIONS (garrow_null_options_get_type())
1276+
GARROW_AVAILABLE_IN_23_0
1277+
G_DECLARE_DERIVABLE_TYPE(
1278+
GArrowNullOptions, garrow_null_options, GARROW, NULL_OPTIONS, GArrowFunctionOptions)
1279+
struct _GArrowNullOptionsClass
1280+
{
1281+
GArrowFunctionOptionsClass parent_class;
1282+
};
1283+
1284+
GARROW_AVAILABLE_IN_23_0
1285+
GArrowNullOptions *
1286+
garrow_null_options_new(void);
1287+
12751288
G_END_DECLS

c_glib/arrow-glib/compute.hpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -209,3 +209,8 @@ garrow_extract_regex_options_new_raw(
209209
const arrow::compute::ExtractRegexOptions *arrow_options);
210210
arrow::compute::ExtractRegexOptions *
211211
garrow_extract_regex_options_get_raw(GArrowExtractRegexOptions *options);
212+
213+
GArrowNullOptions *
214+
garrow_null_options_new_raw(const arrow::compute::NullOptions *arrow_options);
215+
arrow::compute::NullOptions *
216+
garrow_null_options_get_raw(GArrowNullOptions *options);

c_glib/test/test-null-options.rb

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
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 TestNullOptions < Test::Unit::TestCase
19+
include Helper::Buildable
20+
21+
def setup
22+
@options = Arrow::NullOptions.new
23+
end
24+
25+
def test_nan_is_null_property
26+
assert do
27+
!@options.nan_is_null?
28+
end
29+
@options.nan_is_null = true
30+
assert do
31+
@options.nan_is_null?
32+
end
33+
end
34+
35+
def test_is_null_function
36+
args = [
37+
Arrow::ArrayDatum.new(build_float_array([1.0, Float::NAN, 2.0, nil, 4.0])),
38+
]
39+
is_null_function = Arrow::Function.find("is_null")
40+
@options.nan_is_null = true
41+
result = is_null_function.execute(args, @options).value
42+
assert_equal(build_boolean_array([false, true, false, true, false]), result)
43+
end
44+
end

0 commit comments

Comments
 (0)