Skip to content
Open
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
113 changes: 113 additions & 0 deletions c_glib/arrow-glib/compute.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -306,6 +306,9 @@ G_BEGIN_DECLS
* #GArrowPivotWiderOptions is a class to customize the `pivot_wider` and
* `hash_pivot_wider` functions.
*
* #GArrowTrimOptions is a class to customize the `utf8_trim`, `utf8_ltrim`,
* `utf8_rtrim`, `ascii_trim`, `ascii_ltrim`, and `ascii_rtrim` functions.
*
* There are many functions to compute data on an array.
*/

Expand Down Expand Up @@ -8762,6 +8765,95 @@ garrow_pivot_wider_options_new(void)
g_object_new(GARROW_TYPE_PIVOT_WIDER_OPTIONS, nullptr));
}

enum {
PROP_TRIM_OPTIONS_CHARACTERS = 1,
};

G_DEFINE_TYPE(GArrowTrimOptions, garrow_trim_options, GARROW_TYPE_FUNCTION_OPTIONS)

static void
garrow_trim_options_set_property(GObject *object,
guint prop_id,
const GValue *value,
GParamSpec *pspec)
{
auto options = garrow_trim_options_get_raw(GARROW_TRIM_OPTIONS(object));

switch (prop_id) {
case PROP_TRIM_OPTIONS_CHARACTERS:
options->characters = g_value_get_string(value);
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID(object, prop_id, pspec);
break;
}
}

static void
garrow_trim_options_get_property(GObject *object,
guint prop_id,
GValue *value,
GParamSpec *pspec)
{
auto options = garrow_trim_options_get_raw(GARROW_TRIM_OPTIONS(object));

switch (prop_id) {
case PROP_TRIM_OPTIONS_CHARACTERS:
g_value_set_string(value, options->characters.c_str());
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID(object, prop_id, pspec);
break;
}
}

static void
garrow_trim_options_init(GArrowTrimOptions *object)
{
auto arrow_priv = GARROW_FUNCTION_OPTIONS_GET_PRIVATE(object);
arrow_priv->options =
static_cast<arrow::compute::FunctionOptions *>(new arrow::compute::TrimOptions());
}

static void
garrow_trim_options_class_init(GArrowTrimOptionsClass *klass)
{
auto gobject_class = G_OBJECT_CLASS(klass);

gobject_class->set_property = garrow_trim_options_set_property;
gobject_class->get_property = garrow_trim_options_get_property;

arrow::compute::TrimOptions options;

GParamSpec *spec;
/**
* GArrowTrimOptions:characters:
*
* The individual characters to be trimmed from the string.
*
* Since: 23.0.0
*/
spec = g_param_spec_string("characters",
"Characters",
"The individual characters to be trimmed from the string",
options.characters.c_str(),
static_cast<GParamFlags>(G_PARAM_READWRITE));
g_object_class_install_property(gobject_class, PROP_TRIM_OPTIONS_CHARACTERS, spec);
}

/**
* garrow_trim_options_new:
*
* Returns: A newly created #GArrowTrimOptions.
*
* Since: 23.0.0
*/
GArrowTrimOptions *
garrow_trim_options_new(void)
{
return GARROW_TRIM_OPTIONS(g_object_new(GARROW_TYPE_TRIM_OPTIONS, NULL));
}

G_END_DECLS

arrow::Result<arrow::FieldRef>
Expand Down Expand Up @@ -8981,6 +9073,11 @@ garrow_function_options_new_raw(const arrow::compute::FunctionOptions *arrow_opt
static_cast<const arrow::compute::PivotWiderOptions *>(arrow_options);
auto options = garrow_pivot_wider_options_new_raw(arrow_pivot_wider_options);
return GARROW_FUNCTION_OPTIONS(options);
} else if (arrow_type_name == "TrimOptions") {
const auto arrow_trim_options =
static_cast<const arrow::compute::TrimOptions *>(arrow_options);
auto options = garrow_trim_options_new_raw(arrow_trim_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 @@ -9870,3 +9967,19 @@ garrow_pivot_wider_options_get_raw(GArrowPivotWiderOptions *options)
return static_cast<arrow::compute::PivotWiderOptions *>(
garrow_function_options_get_raw(GARROW_FUNCTION_OPTIONS(options)));
}

GArrowTrimOptions *
garrow_trim_options_new_raw(const arrow::compute::TrimOptions *arrow_options)
{
return GARROW_TRIM_OPTIONS(g_object_new(GARROW_TYPE_TRIM_OPTIONS,
"characters",
arrow_options->characters.c_str(),
NULL));
}

arrow::compute::TrimOptions *
garrow_trim_options_get_raw(GArrowTrimOptions *options)
{
return static_cast<arrow::compute::TrimOptions *>(
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 @@ -1540,4 +1540,17 @@ GARROW_AVAILABLE_IN_23_0
GArrowPivotWiderOptions *
garrow_pivot_wider_options_new(void);

#define GARROW_TYPE_TRIM_OPTIONS (garrow_trim_options_get_type())
GARROW_AVAILABLE_IN_23_0
G_DECLARE_DERIVABLE_TYPE(
GArrowTrimOptions, garrow_trim_options, GARROW, TRIM_OPTIONS, GArrowFunctionOptions)
struct _GArrowTrimOptionsClass
{
GArrowFunctionOptionsClass parent_class;
};

GARROW_AVAILABLE_IN_23_0
GArrowTrimOptions *
garrow_trim_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 @@ -274,3 +274,8 @@ garrow_pivot_wider_options_new_raw(
const arrow::compute::PivotWiderOptions *arrow_options);
arrow::compute::PivotWiderOptions *
garrow_pivot_wider_options_get_raw(GArrowPivotWiderOptions *options);

GArrowTrimOptions *
garrow_trim_options_new_raw(const arrow::compute::TrimOptions *arrow_options);
arrow::compute::TrimOptions *
garrow_trim_options_get_raw(GArrowTrimOptions *options);
41 changes: 41 additions & 0 deletions c_glib/test/test-trim-options.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
# 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 TestTrimOptions < Test::Unit::TestCase
include Helper::Buildable

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

def test_characters_property
assert_equal("", @options.characters)
@options.characters = " \t"
assert_equal(" \t", @options.characters)
end

def test_utf8_trim_function
args = [
Arrow::ArrayDatum.new(build_string_array([" hello ", " world "])),
]
@options.characters = " "
utf8_trim_function = Arrow::Function.find("utf8_trim")
result = utf8_trim_function.execute(args, @options).value
expected = build_string_array(["hello", "world"])
assert_equal(expected, result)
end
end
Loading