From 5f173d646bb1afaaa788cb8dceb6ce179d524628 Mon Sep 17 00:00:00 2001 From: Sutou Kouhei Date: Sat, 13 Jul 2019 10:31:03 +0900 Subject: [PATCH 1/2] [GLib][Gandiva] Add support for function aliases This is follow-up for ARROW-5892: https://github.com/apache/arrow/pull/4835 --- c_glib/gandiva-glib/native-function.cpp | 58 ++++++++----------- c_glib/gandiva-glib/native-function.h | 3 +- c_glib/test/gandiva/test-function-registry.rb | 2 +- c_glib/test/gandiva/test-native-function.rb | 15 +++-- c_glib/test/helper/data-type.rb | 4 ++ 5 files changed, 39 insertions(+), 43 deletions(-) diff --git a/c_glib/gandiva-glib/native-function.cpp b/c_glib/gandiva-glib/native-function.cpp index f2f15ac785d..5ff265f1232 100644 --- a/c_glib/gandiva-glib/native-function.cpp +++ b/c_glib/gandiva-glib/native-function.cpp @@ -93,46 +93,25 @@ ggandiva_native_function_class_init(GGandivaNativeFunctionClass *klass) } /** - * ggandiva_native_function_get_signature: + * ggandiva_native_function_get_signatures: * @native_function: A #GGandivaNativeFunction. * - * Returns: (transfer full): A #GGandivaFunctionSignature that represents - * the signature of the native function. + * Returns: (element-type GGandivaFunctionSignature) (transfer full): + * A list of #GGandivaFunctionSignature supported by the native function. * - * Since: 0.14.0 - */ -GGandivaFunctionSignature * -ggandiva_native_function_get_signature(GGandivaNativeFunction *native_function) -{ - auto gandiva_native_function = - ggandiva_native_function_get_raw(native_function); - auto &gandiva_function_signature = gandiva_native_function->signatures().front(); - return ggandiva_function_signature_new_raw(&gandiva_function_signature); -} - -/** - * ggandiva_native_function_get_all_signatures: - * @native_function: A #GGandivaNativeFunction. - * - * Returns: (transfer full): A List of #GGandivaFunctionSignature supported by - * the native function. - * - * Since: ?? + * Since: 1.0.0 */ GList * -ggandiva_native_function_get_all_signatures(GGandivaNativeFunction *native_function) +ggandiva_native_function_get_signatures(GGandivaNativeFunction *native_function) { auto gandiva_native_function = - ggandiva_native_function_get_raw(native_function); - - GList *function_signatures = nullptr; - for (auto& function_sig_raw : gandiva_native_function->signatures()) { - auto function_sig = ggandiva_function_signature_new_raw(&function_sig_raw); - function_signatures = g_list_prepend(function_signatures, function_sig); + ggandiva_native_function_get_raw(native_function); + GList *signatures = nullptr; + for (auto &gandiva_signature : gandiva_native_function->signatures()) { + auto signature = ggandiva_function_signature_new_raw(&gandiva_signature); + signatures = g_list_prepend(signatures, signature); } - function_signatures = g_list_reverse(function_signatures); - - return function_signatures; + return g_list_reverse(signatures); } /** @@ -160,7 +139,7 @@ ggandiva_native_function_equal(GGandivaNativeFunction *native_function, * @native_function: A #GGandivaNativeFunction. * * Returns: (transfer full): - * The string representation of the signature of the native function. + * The string representation of the signatures of the native function. * It should be freed with g_free() when no longer needed. * * Since: 0.14.0 @@ -170,8 +149,17 @@ ggandiva_native_function_to_string(GGandivaNativeFunction *native_function) { auto gandiva_native_function = ggandiva_native_function_get_raw(native_function); - auto gandiva_function_signature = gandiva_native_function->signatures().front(); - return g_strdup(gandiva_function_signature.ToString().c_str()); + auto string = g_string_new(NULL); + for (auto &gandiva_signature : gandiva_native_function->signatures()) { + if (string->len > 0) { + g_string_append(string, ", "); + } + const auto &signature_string = gandiva_signature.ToString(); + g_string_append_len(string, + signature_string.data(), + signature_string.length()); + } + return g_string_free(string, FALSE); } /** diff --git a/c_glib/gandiva-glib/native-function.h b/c_glib/gandiva-glib/native-function.h index a7ffb60a4ce..8b4d6a44c80 100644 --- a/c_glib/gandiva-glib/native-function.h +++ b/c_glib/gandiva-glib/native-function.h @@ -51,7 +51,8 @@ struct _GGandivaNativeFunctionClass GObjectClass parent_class; }; -GGandivaFunctionSignature *ggandiva_native_function_get_signature(GGandivaNativeFunction *native_function); +GList * +ggandiva_native_function_get_signatures(GGandivaNativeFunction *native_function); gboolean ggandiva_native_function_equal(GGandivaNativeFunction *native_function, GGandivaNativeFunction *other_native_function); diff --git a/c_glib/test/gandiva/test-function-registry.rb b/c_glib/test/gandiva/test-function-registry.rb index 85b03071813..25bac667310 100644 --- a/c_glib/test/gandiva/test-function-registry.rb +++ b/c_glib/test/gandiva/test-function-registry.rb @@ -27,7 +27,7 @@ def setup def test_found native_function = @registry.native_functions[0] assert_equal(native_function, - @registry.lookup(native_function.signature)) + @registry.lookup(native_function.signatures[0])) end def test_not_found diff --git a/c_glib/test/gandiva/test-native-function.rb b/c_glib/test/gandiva/test-native-function.rb index f2546daf4a0..7888f96b678 100644 --- a/c_glib/test/gandiva/test-native-function.rb +++ b/c_glib/test/gandiva/test-native-function.rb @@ -32,15 +32,15 @@ def lookup(name, param_types, return_type) @registry.lookup(signature) end - def test_get_signature - assert_kind_of(Gandiva::FunctionSignature, - @not.signature) + def test_signatures + assert_equal([Gandiva::FunctionSignature], + @not.signatures.collect(&:class).uniq) end sub_test_case("equal") do def test_true assert do - @not == @registry.lookup(@not.signature) + @not == @registry.lookup(@not.signatures[0]) end end @@ -52,8 +52,11 @@ def test_false end def test_to_string - assert_equal(@not.signature.to_s, - @not.to_s) + modulo = lookup("modulo", + [int64_data_type, int64_data_type], + int64_data_type) + assert_equal(modulo.signatures.collect(&:to_s).join(", "), + modulo.to_s) end sub_test_case("get_result_nullbale_type") do diff --git a/c_glib/test/helper/data-type.rb b/c_glib/test/helper/data-type.rb index 5716f7eef5a..b8224409873 100644 --- a/c_glib/test/helper/data-type.rb +++ b/c_glib/test/helper/data-type.rb @@ -48,6 +48,10 @@ def int32_data_type Arrow::Int32DataType.new end + def int64_data_type + Arrow::Int64DataType.new + end + def string_data_type Arrow::StringDataType.new end From 306d0645001cd5f507fcd94fd10bfef8fec774ba Mon Sep 17 00:00:00 2001 From: Sutou Kouhei Date: Sun, 14 Jul 2019 06:35:25 +0900 Subject: [PATCH 2/2] Add symbol list for 1.0.0 --- c_glib/doc/gandiva-glib/gandiva-glib-docs.xml | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/c_glib/doc/gandiva-glib/gandiva-glib-docs.xml b/c_glib/doc/gandiva-glib/gandiva-glib-docs.xml index 81bbb08c3e9..ac9f686ac27 100644 --- a/c_glib/doc/gandiva-glib/gandiva-glib-docs.xml +++ b/c_glib/doc/gandiva-glib/gandiva-glib-docs.xml @@ -84,6 +84,10 @@ Index of deprecated API + + Index of new symbols in 1.0.0 + + Index of new symbols in 0.14.0