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

Expand Down Expand Up @@ -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<arrow::compute::FunctionOptions *>(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<GParamFlags>(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<arrow::FieldRef>
Expand Down Expand Up @@ -8205,6 +8296,11 @@ garrow_function_options_new_raw(const arrow::compute::FunctionOptions *arrow_opt
static_cast<const arrow::compute::ModeOptions *>(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<const arrow::compute::NullOptions *>(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);
Expand Down Expand Up @@ -8979,3 +9075,19 @@ garrow_mode_options_get_raw(GArrowModeOptions *options)
return static_cast<arrow::compute::ModeOptions *>(
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<arrow::compute::NullOptions *>(
garrow_function_options_get_raw(GARROW_FUNCTION_OPTIONS(options)));
}
13 changes: 13 additions & 0 deletions c_glib/arrow-glib/compute.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
5 changes: 5 additions & 0 deletions c_glib/arrow-glib/compute.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
44 changes: 44 additions & 0 deletions c_glib/test/test-null-options.rb
Original file line number Diff line number Diff line change
@@ -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
Loading