Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ARROW-15273: [GLib] add garrow_function_get_options_type() #12093

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
23 changes: 23 additions & 0 deletions c_glib/arrow-glib/compute.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -677,6 +677,29 @@ garrow_function_get_default_options(GArrowFunction *function)
return garrow_function_options_new_raw(arrow_function_options);
}

/**
* garrow_function_get_options_type:
* @function: A #GArrowFunction.
*
* Returns: %G_TYPE_NONE if this function doesn't have options, the
* #GType of options of this function if it exists and Apache Arrow
* GLib bindings of it also exist, %G_TYPE_INVALID if options of this
* function exists but Apache Arrow GLib bindings of it don't exist.
*
* Since: 7.0.0
*/
GType
garrow_function_get_options_type(GArrowFunction *function)
{
auto arrow_function = garrow_function_get_raw(function);
const auto &arrow_doc = arrow_function->doc();
if (arrow_doc.options_class.empty()) {
return G_TYPE_NONE;
}
auto options_type_name = std::string("GArrow") + arrow_doc.options_class;
return g_type_from_name(options_type_name.c_str());
}

/**
* garrow_function_equal:
* @function: A #GArrowFunction.
Expand Down
3 changes: 3 additions & 0 deletions c_glib/arrow-glib/compute.h
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,9 @@ garrow_function_get_doc(GArrowFunction *function);
GARROW_AVAILABLE_IN_7_0
GArrowFunctionOptions *
garrow_function_get_default_options(GArrowFunction *function);
GARROW_AVAILABLE_IN_7_0
GType
garrow_function_get_options_type(GArrowFunction *function);

GARROW_AVAILABLE_IN_7_0
gboolean
Expand Down
74 changes: 74 additions & 0 deletions c_glib/test/test-function.rb
Original file line number Diff line number Diff line change
Expand Up @@ -159,4 +159,78 @@ def test_round_to_multiple_options
round_to_multiple_function.default_options)
end
end

sub_test_case("#options_type") do
def test_nonexistent
or_function = Arrow::Function.find("or")
assert_equal(GLib::Type::NONE,
or_function.options_type)
end

def test_cast_options
cast_function = Arrow::Function.find("cast")
assert_equal(Arrow::CastOptions.gtype,
cast_function.options_type)
end

def test_scalar_aggregate_options
sum_function = Arrow::Function.find("sum")
assert_equal(Arrow::ScalarAggregateOptions.gtype,
sum_function.options_type)
end

def test_count_options
count_function = Arrow::Function.find("count")
assert_equal(Arrow::CountOptions.gtype,
count_function.options_type)
end

def test_filter_options
filter_function = Arrow::Function.find("filter")
assert_equal(Arrow::FilterOptions.gtype,
filter_function.options_type)
end

def test_take_options
take_function = Arrow::Function.find("take")
assert_equal(Arrow::TakeOptions.gtype,
take_function.options_type)
end

def test_array_sort_options
array_sort_indices_function = Arrow::Function.find("array_sort_indices")
assert_equal(Arrow::ArraySortOptions.gtype,
array_sort_indices_function.options_type)
end

def test_sort_options
sort_indices_function = Arrow::Function.find("sort_indices")
assert_equal(Arrow::SortOptions.gtype,
sort_indices_function.options_type)
end

def test_set_lookup_options
is_in_function = Arrow::Function.find("is_in")
assert_equal(Arrow::SetLookupOptions.gtype,
is_in_function.options_type)
end

def test_variance_options
stddev_function = Arrow::Function.find("stddev")
assert_equal(Arrow::VarianceOptions.gtype,
stddev_function.options_type)
end

def test_round_options
round_function = Arrow::Function.find("round")
assert_equal(Arrow::RoundOptions.gtype,
round_function.options_type)
end

def test_round_to_multiple_options
round_to_multiple_function = Arrow::Function.find("round_to_multiple")
assert_equal(Arrow::RoundToMultipleOptions.gtype,
round_to_multiple_function.options_type)
end
end
end