Skip to content

Commit

Permalink
apacheGH-15285: [GLib] Add GArrowMatchSubstringOptions
Browse files Browse the repository at this point in the history
  • Loading branch information
kou committed Mar 24, 2023
1 parent 0977cd2 commit b0c77aa
Show file tree
Hide file tree
Showing 5 changed files with 280 additions and 12 deletions.
197 changes: 186 additions & 11 deletions c_glib/arrow-glib/compute.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3781,6 +3781,131 @@ garrow_round_to_multiple_options_new(void)
}


enum {
PROP_MATCH_SUBSTRING_OPTIONS_PATTERN = 1,
PROP_MATCH_SUBSTRING_OPTIONS_IGNORE_CASE,
};

G_DEFINE_TYPE(GArrowMatchSubstringOptions,
garrow_match_substring_options,
GARROW_TYPE_FUNCTION_OPTIONS)

static void
garrow_match_substring_options_set_property(GObject *object,
guint prop_id,
const GValue *value,
GParamSpec *pspec)
{
auto options =
garrow_match_substring_options_get_raw(
GARROW_MATCH_SUBSTRING_OPTIONS(object));

switch (prop_id) {
case PROP_MATCH_SUBSTRING_OPTIONS_PATTERN:
options->pattern = g_value_get_string(value);
break;
case PROP_MATCH_SUBSTRING_OPTIONS_IGNORE_CASE:
options->ignore_case = g_value_get_boolean(value);
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID(object, prop_id, pspec);
break;
}
}

static void
garrow_match_substring_options_get_property(GObject *object,
guint prop_id,
GValue *value,
GParamSpec *pspec)
{
auto options =
garrow_match_substring_options_get_raw(
GARROW_MATCH_SUBSTRING_OPTIONS(object));

switch (prop_id) {
case PROP_MATCH_SUBSTRING_OPTIONS_PATTERN:
g_value_set_string(value, options->pattern.c_str());
break;
case PROP_MATCH_SUBSTRING_OPTIONS_IGNORE_CASE:
g_value_set_boolean(value, options->ignore_case);
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID(object, prop_id, pspec);
break;
}
}

static void
garrow_match_substring_options_init(GArrowMatchSubstringOptions *object)
{
auto function_options_priv = GARROW_FUNCTION_OPTIONS_GET_PRIVATE(object);
function_options_priv->options =
static_cast<arrow::compute::FunctionOptions *>(
new arrow::compute::MatchSubstringOptions());
}

static void
garrow_match_substring_options_class_init(
GArrowMatchSubstringOptionsClass *klass)
{
auto gobject_class = G_OBJECT_CLASS(klass);
gobject_class->set_property = garrow_match_substring_options_set_property;
gobject_class->get_property = garrow_match_substring_options_get_property;


arrow::compute::MatchSubstringOptions options;

GParamSpec *spec;
/**
* GArrowMatchSubstringOptions:pattern:
*
* The exact substring (or regex, depending on kernel) to look for
* inside input values.
*
* Since: 12.0.0
*/
spec = g_param_spec_string("pattern",
"Pattern",
"The pattern to be looked for",
NULL,
static_cast<GParamFlags>(G_PARAM_READWRITE));
g_object_class_install_property(gobject_class,
PROP_MATCH_SUBSTRING_OPTIONS_PATTERN,
spec);

/**
* GArrowMatchSubstringOptions:ignore-case:
*
* Whether to perform a case-insensitive match.
*
* Since: 12.0.0
*/
spec = g_param_spec_boolean("ignore-case",
"Ignore case",
"Whether to perform a case-insensitive match",
options.ignore_case,
static_cast<GParamFlags>(G_PARAM_READWRITE));
g_object_class_install_property(gobject_class,
PROP_MATCH_SUBSTRING_OPTIONS_IGNORE_CASE,
spec);
}

/**
* garrow_match_substring_options_new:
*
* Returns: A newly created #GArrowMatchSubstringOptions.
*
* Since: 12.0.0
*/
GArrowMatchSubstringOptions *
garrow_match_substring_options_new(void)
{
return GARROW_MATCH_SUBSTRING_OPTIONS(
g_object_new(GARROW_TYPE_MATCH_SUBSTRING_OPTIONS, NULL));
}


enum {
PROP_UTF8_NORMALIZE_OPTIONS_FORM = 1,
};
Expand Down Expand Up @@ -4119,6 +4244,19 @@ G_DEFINE_TYPE_WITH_PRIVATE(GArrowIndexOptions,
garrow_index_options_get_instance_private( \
GARROW_INDEX_OPTIONS(object)))

static void
garrow_index_options_dispose(GObject *object)
{
auto priv = GARROW_INDEX_OPTIONS_GET_PRIVATE(object);

if (priv->value) {
g_object_unref(priv->value);
priv->value = nullptr;
}

G_OBJECT_CLASS(garrow_index_options_parent_class)->dispose(object);
}

static void
garrow_index_options_set_property(GObject *object,
guint prop_id,
Expand Down Expand Up @@ -4174,16 +4312,20 @@ garrow_index_options_get_property(GObject *object,
static void
garrow_index_options_init(GArrowIndexOptions *object)
{
auto priv = GARROW_FUNCTION_OPTIONS_GET_PRIVATE(object);
priv->options = static_cast<arrow::compute::FunctionOptions *>(
new arrow::compute::IndexOptions());
auto function_options_priv = GARROW_FUNCTION_OPTIONS_GET_PRIVATE(object);
auto options = new arrow::compute::IndexOptions();
function_options_priv->options =
static_cast<arrow::compute::FunctionOptions *>(options);
auto priv = GARROW_INDEX_OPTIONS_GET_PRIVATE(object);
priv->value = nullptr;
}

static void
garrow_index_options_class_init(GArrowIndexOptionsClass *klass)
{
auto gobject_class = G_OBJECT_CLASS(klass);

gobject_class->dispose = garrow_index_options_dispose;
gobject_class->set_property = garrow_index_options_set_property;
gobject_class->get_property = garrow_index_options_get_property;

Expand All @@ -4206,19 +4348,16 @@ garrow_index_options_class_init(GArrowIndexOptionsClass *klass)

/**
* garrow_index_options_new:
* @value: (nullable): A #GArrowScalar to be compared.
*
* Returns: A newly created #GArrowIndexOptions.
*
* Since: 12.0.0
*/
GArrowIndexOptions *
garrow_index_options_new(GArrowScalar *value)
garrow_index_options_new(void)
{
return GARROW_INDEX_OPTIONS(
g_object_new(GARROW_TYPE_INDEX_OPTIONS,
"value", value,
NULL));
return GARROW_INDEX_OPTIONS(g_object_new(GARROW_TYPE_INDEX_OPTIONS,
NULL));
}


Expand Down Expand Up @@ -5698,6 +5837,12 @@ garrow_function_options_new_raw(
auto options =
garrow_round_to_multiple_options_new_raw(arrow_round_to_multiple_options);
return GARROW_FUNCTION_OPTIONS(options);
} else if (arrow_type_name == "MatchSubstringOptions") {
const auto arrow_match_substring_options =
static_cast<const arrow::compute::MatchSubstringOptions *>(arrow_options);
auto options =
garrow_match_substring_options_new_raw(arrow_match_substring_options);
return GARROW_FUNCTION_OPTIONS(options);
} else if (arrow_type_name == "UTF8NormalizedOptions") {
const auto arrow_utf8_normalize_options =
static_cast<const arrow::compute::Utf8NormalizeOptions *>(arrow_options);
Expand Down Expand Up @@ -6064,6 +6209,25 @@ garrow_round_to_multiple_options_get_raw(GArrowRoundToMultipleOptions *options)
}


GArrowMatchSubstringOptions *
garrow_match_substring_options_new_raw(
const arrow::compute::MatchSubstringOptions *arrow_options)
{
return GARROW_MATCH_SUBSTRING_OPTIONS(
g_object_new(GARROW_TYPE_MATCH_SUBSTRING_OPTIONS,
"pattern", arrow_options->pattern.c_str(),
"ignore-case", arrow_options->ignore_case,
NULL));
}

arrow::compute::MatchSubstringOptions *
garrow_match_substring_options_get_raw(GArrowMatchSubstringOptions *options)
{
return static_cast<arrow::compute::MatchSubstringOptions *>(
garrow_function_options_get_raw(GARROW_FUNCTION_OPTIONS(options)));
}


GArrowUTF8NormalizeOptions *
garrow_utf8_normalize_options_new_raw(
const arrow::compute::Utf8NormalizeOptions *arrow_options)
Expand Down Expand Up @@ -6111,8 +6275,19 @@ GArrowIndexOptions *
garrow_index_options_new_raw(const arrow::compute::IndexOptions *arrow_options)
{
auto arrow_value = arrow_options->value->GetSharedPtr();
auto value = garrow_scalar_new_raw(&arrow_value);
return garrow_index_options_new(value);
GArrowScalar *value = nullptr;
if (arrow_value) {
value = garrow_scalar_new_raw(&arrow_value);
}
auto options =
GARROW_INDEX_OPTIONS(
g_object_new(GARROW_TYPE_INDEX_OPTIONS,
"value", value,
NULL));
if (value) {
g_object_unref(value);
}
return options;
}

arrow::compute::IndexOptions *
Expand Down
19 changes: 18 additions & 1 deletion c_glib/arrow-glib/compute.h
Original file line number Diff line number Diff line change
Expand Up @@ -718,6 +718,23 @@ GArrowRoundToMultipleOptions *
garrow_round_to_multiple_options_new(void);


#define GARROW_TYPE_MATCH_SUBSTRING_OPTIONS \
(garrow_match_substring_options_get_type())
G_DECLARE_DERIVABLE_TYPE(GArrowMatchSubstringOptions,
garrow_match_substring_options,
GARROW,
MATCH_SUBSTRING_OPTIONS,
GArrowFunctionOptions)
struct _GArrowMatchSubstringOptionsClass
{
GArrowFunctionOptionsClass parent_class;
};

GARROW_AVAILABLE_IN_12_0
GArrowMatchSubstringOptions *
garrow_match_substring_options_new(void);


/**
* GArrowUTF8NormalizeForm:
* @GARROW_UTF8_NORMALIZE_FORM_NFC: Normalization Form Canonical Composition.
Expand Down Expand Up @@ -819,7 +836,7 @@ struct _GArrowIndexOptionsClass

GARROW_AVAILABLE_IN_12_0
GArrowIndexOptions *
garrow_index_options_new(GArrowScalar *value);
garrow_index_options_new(void);


/**
Expand Down
7 changes: 7 additions & 0 deletions c_glib/arrow-glib/compute.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,13 @@ arrow::compute::RoundToMultipleOptions *
garrow_round_to_multiple_options_get_raw(GArrowRoundToMultipleOptions *options);


GArrowMatchSubstringOptions *
garrow_match_substring_options_new_raw(
const arrow::compute::MatchSubstringOptions *arrow_options);
arrow::compute::MatchSubstringOptions *
garrow_match_substring_options_get_raw(GArrowMatchSubstringOptions *options);


GArrowUTF8NormalizeOptions *
garrow_utf8_normalize_options_new_raw(
const arrow::compute::Utf8NormalizeOptions *arrow_options);
Expand Down
31 changes: 31 additions & 0 deletions c_glib/test/test-index-options.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
# 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 TestIndexOptions < Test::Unit::TestCase
def setup
@value = Arrow::Int32Scalar.new(29)
@options = Arrow::IndexOptions.new
@options.value = @value
end

def test_value
assert_equal(@value, @options.value)
new_value = Arrow::UInt8Scalar.new(1)
@options.value = new_value
assert_equal(new_value, @options.value)
end
end
38 changes: 38 additions & 0 deletions c_glib/test/test-match-substring-options.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
# 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 TestMatchSubstringOptions < Test::Unit::TestCase
def setup
@options = Arrow::MatchSubstringOptions.new
end

def test_pattern
assert_equal("", @options.pattern)
@options.pattern = "substring"
assert_equal("substring", @options.pattern)
end

def test_ignore_case
assert do
not @options.ignore_case?
end
@options.ignore_case = true
assert do
@options.ignore_case?
end
end
end

0 comments on commit b0c77aa

Please sign in to comment.