[Tarantool-patches] [PATCH v1 1/7] box: add has_vararg option for functions

imeevma at tarantool.org imeevma at tarantool.org
Wed Aug 12 18:15:45 MSK 2020


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.

Part of #4159
---
 src/box/func_def.c | 5 +++++
 src/box/func_def.h | 6 ++++++
 2 files changed, 11 insertions(+)

diff --git a/src/box/func_def.c b/src/box/func_def.c
index 11d2bdb84..be12ce970 100644
--- a/src/box/func_def.c
+++ b/src/box/func_def.c
@@ -40,10 +40,13 @@ const char *func_aggregate_strs[] = {"none", "group"};
 
 const struct func_opts func_opts_default = {
 	/* .is_multikey = */ false,
+	/* .has_vararg = */ false,
 };
 
 const struct opt_def func_opts_reg[] = {
 	OPT_DEF("is_multikey", OPT_BOOL, struct func_opts, is_multikey),
+	OPT_DEF("has_vararg", OPT_BOOL, struct func_opts, has_vararg),
+	OPT_END,
 };
 
 int
@@ -51,6 +54,8 @@ 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->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..89d5a404a 100644
--- a/src/box/func_def.h
+++ b/src/box/func_def.h
@@ -68,6 +68,12 @@ struct func_opts {
 	 * packed in array.
 	 */
 	bool is_multikey;
+	/**
+	 * 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



More information about the Tarantool-patches mailing list