[Tarantool-patches] [PATCH v2 1/6] sql: introduce sql_func_flags()

imeevma at tarantool.org imeevma at tarantool.org
Mon Aug 9 10:18:54 MSK 2021


This function returns a set of parameters for the function with the
given name. This function is used when we do not need to call a
function, but we need its parameters.

In addition, this function will allow us to split the parameters
between those that are the same for all implementations, and the
parameters, the value of which is implementation-dependent.

Needed for #6105
Part of #6106
---
 src/box/sql/expr.c   |  9 +++------
 src/box/sql/func.c   | 12 ++++++++++++
 src/box/sql/sqlInt.h | 10 ++++++++++
 3 files changed, 25 insertions(+), 6 deletions(-)

diff --git a/src/box/sql/expr.c b/src/box/sql/expr.c
index d2624516c..80f2d349a 100644
--- a/src/box/sql/expr.c
+++ b/src/box/sql/expr.c
@@ -328,11 +328,8 @@ sql_expr_coll(Parse *parse, Expr *p, bool *is_explicit_coll, uint32_t *coll_id,
 		if (op == TK_FUNCTION) {
 			uint32_t arg_count = p->x.pList == NULL ? 0 :
 					     p->x.pList->nExpr;
-			struct func *func =
-				sql_func_by_signature(p->u.zToken, arg_count);
-			if (func == NULL)
-				break;
-			if (sql_func_flag_is_set(func, SQL_FUNC_DERIVEDCOLL) &&
+			uint32_t flags = sql_func_flags(p->u.zToken);
+			if (((flags & SQL_FUNC_DERIVEDCOLL) != 0) &&
 			    arg_count > 0) {
 				/*
 				 * Now we use quite straightforward
@@ -342,7 +339,7 @@ sql_expr_coll(Parse *parse, Expr *p, bool *is_explicit_coll, uint32_t *coll_id,
 				 * built-in functions: trim, upper,
 				 * lower, replace, substr.
 				 */
-				assert(func->def->returns == FIELD_TYPE_STRING);
+				assert(p->type == FIELD_TYPE_STRING);
 				p = p->x.pList->a->pExpr;
 				continue;
 			}
diff --git a/src/box/sql/func.c b/src/box/sql/func.c
index 6ca852dec..28d383293 100644
--- a/src/box/sql/func.c
+++ b/src/box/sql/func.c
@@ -2655,6 +2655,18 @@ static struct {
 	},
 };
 
+uint32_t
+sql_func_flags(const char *name)
+{
+	struct func *func = func_by_name(name, strlen(name));
+	if (func == NULL || func->def->language != FUNC_LANGUAGE_SQL_BUILTIN)
+		return 0;
+	uint32_t flags = ((struct func_sql_builtin *)func)->flags;
+	if (func->def->aggregate == FUNC_AGGREGATE_GROUP)
+		flags |= SQL_FUNC_AGG;
+	return flags;
+}
+
 static struct func_vtab func_sql_builtin_vtab;
 
 struct func *
diff --git a/src/box/sql/sqlInt.h b/src/box/sql/sqlInt.h
index 115c52f96..a92de0a2f 100644
--- a/src/box/sql/sqlInt.h
+++ b/src/box/sql/sqlInt.h
@@ -1186,6 +1186,8 @@ struct type_def {
  *     SQL_FUNC_LENGTH    ==  OPFLAG_LENGTHARG
  *     SQL_FUNC_TYPEOF    ==  OPFLAG_TYPEOFARG
  */
+/** Function is one of aggregate functions. */
+#define SQL_FUNC_AGG      0x0001
 #define SQL_FUNC_LIKE     0x0004	/* Candidate for the LIKE optimization */
 #define SQL_FUNC_NEEDCOLL 0x0020	/* sqlGetFuncCollSeq() might be called.
 					 * The flag is set when the collation
@@ -4372,6 +4374,14 @@ sql_func_flag_is_set(struct func *func, uint16_t flag)
 struct func *
 sql_func_by_signature(const char *name, int argc);
 
+/**
+ * Return the parameters of the function with the given name. If the function
+ * with the given name does not exist, or the function is not a built-in SQL
+ * function, 0 is returned, which means no parameters have been set.
+ */
+uint32_t
+sql_func_flags(const char *name);
+
 /**
  * Generate VDBE code to halt execution with correct error if
  * the object with specified key is already present (or doesn't
-- 
2.25.1



More information about the Tarantool-patches mailing list