diff --git a/c_glib/arrow-glib/compute.cpp b/c_glib/arrow-glib/compute.cpp index d733bceb530..7a216745fc6 100644 --- a/c_glib/arrow-glib/compute.cpp +++ b/c_glib/arrow-glib/compute.cpp @@ -287,6 +287,8 @@ G_BEGIN_DECLS * * #GArrowModeOptions is a class to customize the `mode` function. * + * #GArrowNullOptions is a class to customize the `is_null` function. + * * There are many functions to compute data on an array. */ @@ -8016,6 +8018,95 @@ garrow_mode_options_new(void) return GARROW_MODE_OPTIONS(g_object_new(GARROW_TYPE_MODE_OPTIONS, NULL)); } +enum { + PROP_NULL_OPTIONS_NAN_IS_NULL = 1, +}; + +G_DEFINE_TYPE(GArrowNullOptions, garrow_null_options, GARROW_TYPE_FUNCTION_OPTIONS) + +static void +garrow_null_options_set_property(GObject *object, + guint prop_id, + const GValue *value, + GParamSpec *pspec) +{ + auto options = garrow_null_options_get_raw(GARROW_NULL_OPTIONS(object)); + + switch (prop_id) { + case PROP_NULL_OPTIONS_NAN_IS_NULL: + options->nan_is_null = g_value_get_boolean(value); + break; + default: + G_OBJECT_WARN_INVALID_PROPERTY_ID(object, prop_id, pspec); + break; + } +} + +static void +garrow_null_options_get_property(GObject *object, + guint prop_id, + GValue *value, + GParamSpec *pspec) +{ + auto options = garrow_null_options_get_raw(GARROW_NULL_OPTIONS(object)); + + switch (prop_id) { + case PROP_NULL_OPTIONS_NAN_IS_NULL: + g_value_set_boolean(value, options->nan_is_null); + break; + default: + G_OBJECT_WARN_INVALID_PROPERTY_ID(object, prop_id, pspec); + break; + } +} + +static void +garrow_null_options_init(GArrowNullOptions *object) +{ + auto priv = GARROW_FUNCTION_OPTIONS_GET_PRIVATE(object); + priv->options = + static_cast(new arrow::compute::NullOptions()); +} + +static void +garrow_null_options_class_init(GArrowNullOptionsClass *klass) +{ + auto gobject_class = G_OBJECT_CLASS(klass); + + gobject_class->set_property = garrow_null_options_set_property; + gobject_class->get_property = garrow_null_options_get_property; + + arrow::compute::NullOptions options; + + GParamSpec *spec; + /** + * GArrowNullOptions:nan-is-null: + * + * Whether floating-point NaN values are considered null. + * + * Since: 23.0.0 + */ + spec = g_param_spec_boolean("nan-is-null", + "NaN is null", + "Whether floating-point NaN values are considered null", + options.nan_is_null, + static_cast(G_PARAM_READWRITE)); + g_object_class_install_property(gobject_class, PROP_NULL_OPTIONS_NAN_IS_NULL, spec); +} + +/** + * garrow_null_options_new: + * + * Returns: A newly created #GArrowNullOptions. + * + * Since: 23.0.0 + */ +GArrowNullOptions * +garrow_null_options_new(void) +{ + return GARROW_NULL_OPTIONS(g_object_new(GARROW_TYPE_NULL_OPTIONS, NULL)); +} + G_END_DECLS arrow::Result @@ -8205,6 +8296,11 @@ garrow_function_options_new_raw(const arrow::compute::FunctionOptions *arrow_opt static_cast(arrow_options); auto options = garrow_mode_options_new_raw(arrow_mode_options); return GARROW_FUNCTION_OPTIONS(options); + } else if (arrow_type_name == "NullOptions") { + const auto arrow_null_options = + static_cast(arrow_options); + auto options = garrow_null_options_new_raw(arrow_null_options); + return GARROW_FUNCTION_OPTIONS(options); } else { auto options = g_object_new(GARROW_TYPE_FUNCTION_OPTIONS, NULL); return GARROW_FUNCTION_OPTIONS(options); @@ -8979,3 +9075,19 @@ garrow_mode_options_get_raw(GArrowModeOptions *options) return static_cast( garrow_function_options_get_raw(GARROW_FUNCTION_OPTIONS(options))); } + +GArrowNullOptions * +garrow_null_options_new_raw(const arrow::compute::NullOptions *arrow_options) +{ + return GARROW_NULL_OPTIONS(g_object_new(GARROW_TYPE_NULL_OPTIONS, + "nan-is-null", + arrow_options->nan_is_null, + NULL)); +} + +arrow::compute::NullOptions * +garrow_null_options_get_raw(GArrowNullOptions *options) +{ + return static_cast( + garrow_function_options_get_raw(GARROW_FUNCTION_OPTIONS(options))); +} diff --git a/c_glib/arrow-glib/compute.h b/c_glib/arrow-glib/compute.h index 290a91ca0e0..1cd4b55242e 100644 --- a/c_glib/arrow-glib/compute.h +++ b/c_glib/arrow-glib/compute.h @@ -1433,4 +1433,17 @@ GARROW_AVAILABLE_IN_23_0 GArrowModeOptions * garrow_mode_options_new(void); +#define GARROW_TYPE_NULL_OPTIONS (garrow_null_options_get_type()) +GARROW_AVAILABLE_IN_23_0 +G_DECLARE_DERIVABLE_TYPE( + GArrowNullOptions, garrow_null_options, GARROW, NULL_OPTIONS, GArrowFunctionOptions) +struct _GArrowNullOptionsClass +{ + GArrowFunctionOptionsClass parent_class; +}; + +GARROW_AVAILABLE_IN_23_0 +GArrowNullOptions * +garrow_null_options_new(void); + G_END_DECLS diff --git a/c_glib/arrow-glib/compute.hpp b/c_glib/arrow-glib/compute.hpp index 7bb93bcee99..47172e38d89 100644 --- a/c_glib/arrow-glib/compute.hpp +++ b/c_glib/arrow-glib/compute.hpp @@ -241,3 +241,8 @@ GArrowModeOptions * garrow_mode_options_new_raw(const arrow::compute::ModeOptions *arrow_options); arrow::compute::ModeOptions * garrow_mode_options_get_raw(GArrowModeOptions *options); + +GArrowNullOptions * +garrow_null_options_new_raw(const arrow::compute::NullOptions *arrow_options); +arrow::compute::NullOptions * +garrow_null_options_get_raw(GArrowNullOptions *options); diff --git a/c_glib/test/test-null-options.rb b/c_glib/test/test-null-options.rb new file mode 100644 index 00000000000..61ed2cd3f02 --- /dev/null +++ b/c_glib/test/test-null-options.rb @@ -0,0 +1,44 @@ +# 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 TestNullOptions < Test::Unit::TestCase + include Helper::Buildable + + def setup + @options = Arrow::NullOptions.new + end + + def test_nan_is_null_property + assert do + !@options.nan_is_null? + end + @options.nan_is_null = true + assert do + @options.nan_is_null? + end + end + + def test_is_null_function + args = [ + Arrow::ArrayDatum.new(build_float_array([1.0, Float::NAN, 2.0, nil, 4.0])), + ] + is_null_function = Arrow::Function.find("is_null") + @options.nan_is_null = true + result = is_null_function.execute(args, @options).value + assert_equal(build_boolean_array([false, true, false, true, false]), result) + end +end