From 356e3d7257376b65a65489022667b66ed6bbbf62 Mon Sep 17 00:00:00 2001 From: Sutou Kouhei Date: Fri, 7 Jan 2022 04:07:12 +0900 Subject: [PATCH] ARROW-15273: [GLib] add garrow_function_get_options_type() --- c_glib/arrow-glib/compute.cpp | 23 +++++++++++ c_glib/arrow-glib/compute.h | 3 ++ c_glib/test/test-function.rb | 74 +++++++++++++++++++++++++++++++++++ 3 files changed, 100 insertions(+) diff --git a/c_glib/arrow-glib/compute.cpp b/c_glib/arrow-glib/compute.cpp index 7d9bbe1b7b165..4ab988cb3dbc2 100644 --- a/c_glib/arrow-glib/compute.cpp +++ b/c_glib/arrow-glib/compute.cpp @@ -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. diff --git a/c_glib/arrow-glib/compute.h b/c_glib/arrow-glib/compute.h index e647f2da1f463..88a7d401a0c4f 100644 --- a/c_glib/arrow-glib/compute.h +++ b/c_glib/arrow-glib/compute.h @@ -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 diff --git a/c_glib/test/test-function.rb b/c_glib/test/test-function.rb index a51689114a1e6..cffaacba03192 100644 --- a/c_glib/test/test-function.rb +++ b/c_glib/test/test-function.rb @@ -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