[Tarantool-patches] [PATCH v2 1/6] sql: introduce sql_func_flags()
Mergen Imeev
imeevma at tarantool.org
Fri Aug 6 22:41:00 MSK 2021
Hi! Thank you for the review! My answer, diff and new patch below.
On Fri, Aug 06, 2021 at 12:14:45AM +0200, Vladislav Shpilevoy wrote:
> Hi! Thanks for the patch!
>
> > diff --git a/src/box/sql/sqlInt.h b/src/box/sql/sqlInt.h
> > index 115c52f96..97b7a2401 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
>
> The value is misaligned with the values below. They are using
> whitespaces, so this new line probably also should use them.
>
Fixed.
> > #define SQL_FUNC_LIKE 0x0004 /* Candidate for the LIKE optimization */
> > #define SQL_FUNC_NEEDCOLL 0x0020 /* sqlGetFuncCollSeq() might be called.
Diff:
diff --git a/src/box/sql/sqlInt.h b/src/box/sql/sqlInt.h
index 97b7a2401..a92de0a2f 100644
--- a/src/box/sql/sqlInt.h
+++ b/src/box/sql/sqlInt.h
@@ -1187,7 +1187,7 @@ struct type_def {
* SQL_FUNC_TYPEOF == OPFLAG_TYPEOFARG
*/
/** Function is one of aggregate functions. */
-#define SQL_FUNC_AGG 0x0001
+#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
New patch:
commit 9f04ffb91f7347af0fe7ce83f80e6e62d7d4a64f
Author: Mergen Imeev <imeevma at gmail.com>
Date: Tue Aug 3 11:35:33 2021 +0300
sql: introduce sql_func_flags()
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
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
More information about the Tarantool-patches
mailing list