From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from smtpng2.m.smailru.net (smtpng2.m.smailru.net [94.100.179.3]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dev.tarantool.org (Postfix) with ESMTPS id F2E7143040E for ; Fri, 14 Aug 2020 18:04:59 +0300 (MSK) From: imeevma@tarantool.org Date: Fri, 14 Aug 2020 18:04:59 +0300 Message-Id: <65c71dc224b0365954c396486c87738fb9ca5baf.1597417321.git.imeevma@gmail.com> In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Subject: [Tarantool-patches] [PATCH v2 04/10] box: add new options for functions List-Id: Tarantool development patches List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: v.shpilevoy@tarantool.org, tsafin@tarantool.org Cc: tarantool-patches@dev.tarantool.org The has_vararg option allows us to work with functions with a variable number of arguments. This is required for built-in SQL functions. Suppose this option is TRUE for a built-in SQL function. Then: 1) If param_list is empty, all arguments can be of any type. 2) If the length of param_list is not less than the number of the given arguments, the types of the given arguments must be compatible with the corresponding types described in param_list. 3) If the length of param_list is less than the number of given arguments, the rest of the arguments must be compatible with the last type in param_list. The is_overloaded option allows us to deal with functions that can take STRING or VARBINARY arguments. In case the first of these arguments is of type VARBINARY, we use the overloaded version of the function. By default, we use the STRING version of the function. The has_overload option indicates that the function has an overloaded version that accepts VARBINARY. See an explanation of the is_overloaded option. Part of #4159 --- src/box/func_def.c | 13 +++++++++++++ src/box/func_def.h | 18 ++++++++++++++++++ 2 files changed, 31 insertions(+) diff --git a/src/box/func_def.c b/src/box/func_def.c index 11d2bdb84..29929aea3 100644 --- a/src/box/func_def.c +++ b/src/box/func_def.c @@ -40,10 +40,17 @@ const char *func_aggregate_strs[] = {"none", "group"}; const struct func_opts func_opts_default = { /* .is_multikey = */ false, + /* .is_overloaded = */ false, + /* .has_overload = */ false, + /* .has_vararg = */ false, }; const struct opt_def func_opts_reg[] = { OPT_DEF("is_multikey", OPT_BOOL, struct func_opts, is_multikey), + OPT_DEF("is_overloaded", OPT_BOOL, struct func_opts, is_overloaded), + OPT_DEF("has_overload", OPT_BOOL, struct func_opts, has_overload), + OPT_DEF("has_vararg", OPT_BOOL, struct func_opts, has_vararg), + OPT_END, }; int @@ -51,6 +58,12 @@ func_opts_cmp(struct func_opts *o1, struct func_opts *o2) { if (o1->is_multikey != o2->is_multikey) return o1->is_multikey - o2->is_multikey; + if (o1->is_overloaded != o2->is_overloaded) + return o1->is_overloaded - o2->is_overloaded; + if (o1->has_overload != o2->has_overload) + return o1->has_overload - o2->has_overload; + if (o1->has_vararg != o2->has_vararg) + return o1->has_vararg - o2->has_vararg; return 0; } diff --git a/src/box/func_def.h b/src/box/func_def.h index d99d89190..bab2186da 100644 --- a/src/box/func_def.h +++ b/src/box/func_def.h @@ -68,6 +68,24 @@ struct func_opts { * packed in array. */ bool is_multikey; + /** + * True if this function is overloaded version of another function. + * + * Currently only used in built-in SQL functions. + */ + bool is_overloaded; + /** + * True if this function has overloaded version. + * + * Currently only used in built-in SQL functions. + */ + bool has_overload; + /** + * True if the function can have a variable number of arguments. + * + * Currently only used in built-in SQL functions. + */ + bool has_vararg; }; extern const struct func_opts func_opts_default; -- 2.25.1