From: Nikita Pettik <korablev@tarantool.org> To: tarantool-patches@freelists.org Cc: v.shpilevoy@tarantool.org, Nikita Pettik <korablev@tarantool.org> Subject: [tarantool-patches] [PATCH 4/8] sql: replace affinity with field type for func Date: Fri, 28 Dec 2018 11:34:48 +0200 [thread overview] Message-ID: <c213190ad8a8183796bb2e066891aaf5789e3991.1545987214.git.korablev@tarantool.org> (raw) In-Reply-To: <cover.1545987214.git.korablev@tarantool.org> In-Reply-To: <cover.1545987214.git.korablev@tarantool.org> Lets use field_type instead of affinity as a type of return value of user function registered in SQL. Part of #3698 --- src/box/lua/lua_sql.c | 12 +++---- src/box/sql/date.c | 17 ++++----- src/box/sql/expr.c | 7 ++-- src/box/sql/func.c | 91 +++++++++++++++++++++++-------------------------- src/box/sql/main.c | 4 +-- src/box/sql/sqliteInt.h | 6 ++-- 6 files changed, 67 insertions(+), 70 deletions(-) diff --git a/src/box/lua/lua_sql.c b/src/box/lua/lua_sql.c index ab0b7f37c..386da43df 100644 --- a/src/box/lua/lua_sql.c +++ b/src/box/lua/lua_sql.c @@ -149,18 +149,18 @@ lbox_sql_create_function(struct lua_State *L) lua_isfunction(L, 3) && lua_isnumber(L, 4) && lua_isboolean(L, 5))) return luaL_error(L, "Invalid arguments"); - enum affinity_type type = AFFINITY_UNDEFINED; + enum field_type type; const char *type_arg = lua_tostring(L, 2); if (strcmp(type_arg, "INT") == 0 || strcmp(type_arg, "INTEGER") == 0) - type = AFFINITY_INTEGER; + type = FIELD_TYPE_INTEGER; else if (strcmp(type_arg, "TEXT") == 0) - type = AFFINITY_TEXT; + type = FIELD_TYPE_STRING; else if (strcmp(type_arg, "FLOAT") == 0) - type = AFFINITY_REAL; + type = FIELD_TYPE_NUMBER; else if (strcmp(type_arg, "NUM") == 0) - type = AFFINITY_REAL; + type = FIELD_TYPE_NUMBER; else if (strcmp(type_arg, "BLOB") == 0) - type = AFFINITY_BLOB; + type = FIELD_TYPE_SCALAR; else return luaL_error(L, "Unknown type"); /* -1 indicates any number of arguments. */ diff --git a/src/box/sql/date.c b/src/box/sql/date.c index 8a3588355..e452aad73 100644 --- a/src/box/sql/date.c +++ b/src/box/sql/date.c @@ -1306,14 +1306,15 @@ sqlite3RegisterDateTimeFunctions(void) { static FuncDef aDateTimeFuncs[] = { #ifndef SQLITE_OMIT_DATETIME_FUNCS - DFUNCTION(julianday, -1, 0, 0, juliandayFunc, AFFINITY_REAL), - DFUNCTION(date, -1, 0, 0, dateFunc, AFFINITY_REAL), - DFUNCTION(time, -1, 0, 0, timeFunc, AFFINITY_REAL), - DFUNCTION(datetime, -1, 0, 0, datetimeFunc, AFFINITY_REAL), - DFUNCTION(strftime, -1, 0, 0, strftimeFunc, AFFINITY_REAL), - DFUNCTION(current_time, 0, 0, 0, ctimeFunc, AFFINITY_REAL), - DFUNCTION(current_timestamp, 0, 0, 0, ctimestampFunc, AFFINITY_REAL), - DFUNCTION(current_date, 0, 0, 0, cdateFunc, AFFINITY_REAL), + DFUNCTION(julianday, -1, 0, 0, juliandayFunc, FIELD_TYPE_NUMBER), + DFUNCTION(date, -1, 0, 0, dateFunc, FIELD_TYPE_NUMBER), + DFUNCTION(time, -1, 0, 0, timeFunc, FIELD_TYPE_NUMBER), + DFUNCTION(datetime, -1, 0, 0, datetimeFunc, FIELD_TYPE_NUMBER), + DFUNCTION(strftime, -1, 0, 0, strftimeFunc, FIELD_TYPE_NUMBER), + DFUNCTION(current_time, 0, 0, 0, ctimeFunc, FIELD_TYPE_NUMBER), + DFUNCTION(current_timestamp, 0, 0, 0, ctimestampFunc, + FIELD_TYPE_NUMBER), + DFUNCTION(current_date, 0, 0, 0, cdateFunc, FIELD_TYPE_NUMBER), #else STR_FUNCTION(current_time, 0, "%H:%M:%S", 0, currentTimeFunc), STR_FUNCTION(current_date, 0, "%Y-%m-%d", 0, currentTimeFunc), diff --git a/src/box/sql/expr.c b/src/box/sql/expr.c index 7a0b929a7..917e6e30b 100644 --- a/src/box/sql/expr.c +++ b/src/box/sql/expr.c @@ -3959,7 +3959,9 @@ sqlite3ExprCodeTarget(Parse * pParse, Expr * pExpr, int target) "misuse of aggregate: %s()", pExpr->u.zToken); } else { - pExpr->affinity = pInfo->aFunc->pFunc->ret_type; + enum field_type t = + pInfo->aFunc->pFunc->ret_type; + pExpr->affinity = sql_field_type_to_affinity(t); return pInfo->aFunc[pExpr->iAgg].iMem; } break; @@ -3997,7 +3999,8 @@ sqlite3ExprCodeTarget(Parse * pParse, Expr * pExpr, int target) } if (pDef->ret_type != AFFINITY_UNDEFINED) { - pExpr->affinity = pDef->ret_type; + pExpr->affinity = + sql_field_type_to_affinity(pDef->ret_type); } else { /* * Otherwise, use first arg as diff --git a/src/box/sql/func.c b/src/box/sql/func.c index 9667aead5..7a2d3a77d 100644 --- a/src/box/sql/func.c +++ b/src/box/sql/func.c @@ -1590,7 +1590,7 @@ groupConcatFinalize(sqlite3_context * context) */ static inline int sqlite3_overload_function(sqlite3 * db, const char *zName, - enum affinity_type type, int nArg) + enum field_type type, int nArg) { int rc = SQLITE_OK; @@ -1615,7 +1615,7 @@ sqlite3_overload_function(sqlite3 * db, const char *zName, void sqlite3RegisterPerConnectionBuiltinFunctions(sqlite3 * db) { - int rc = sqlite3_overload_function(db, "MATCH", AFFINITY_UNDEFINED, 2); + int rc = sqlite3_overload_function(db, "MATCH", FIELD_TYPE_ANY, 2); assert(rc == SQLITE_NOMEM || rc == SQLITE_OK); if (rc == SQLITE_NOMEM) { sqlite3OomFault(db); @@ -1647,9 +1647,9 @@ sqlite3RegisterLikeFunctions(sqlite3 *db, int is_case_insensitive) * supplied pattern and FALSE otherwise. */ int *is_like_ci = SQLITE_INT_TO_PTR(is_case_insensitive); - sqlite3CreateFunc(db, "LIKE", AFFINITY_INTEGER, 2, 0, + sqlite3CreateFunc(db, "LIKE", FIELD_TYPE_INTEGER, 2, 0, is_like_ci, likeFunc, 0, 0, 0); - sqlite3CreateFunc(db, "LIKE", AFFINITY_INTEGER, 3, 0, + sqlite3CreateFunc(db, "LIKE", FIELD_TYPE_INTEGER, 3, 0, is_like_ci, likeFunc, 0, 0, 0); setLikeOptFlag(db, "LIKE", !(is_case_insensitive) ? (SQLITE_FUNC_LIKE | @@ -1704,17 +1704,17 @@ sqlite3RegisterBuiltinFunctions(void) FUNCTION(soundex, 1, 0, 0, soundexFunc), #endif FUNCTION2(unlikely, 1, 0, 0, noopFunc, SQLITE_FUNC_UNLIKELY, - AFFINITY_INTEGER), + FIELD_TYPE_INTEGER), FUNCTION2(likelihood, 2, 0, 0, noopFunc, SQLITE_FUNC_UNLIKELY, - AFFINITY_INTEGER), + FIELD_TYPE_INTEGER), FUNCTION2(likely, 1, 0, 0, noopFunc, SQLITE_FUNC_UNLIKELY, - AFFINITY_INTEGER), - FUNCTION(ltrim, 1, 1, 0, trimFunc, AFFINITY_TEXT), - FUNCTION(ltrim, 2, 1, 0, trimFunc, AFFINITY_TEXT), - FUNCTION(rtrim, 1, 2, 0, trimFunc, AFFINITY_TEXT), - FUNCTION(rtrim, 2, 2, 0, trimFunc, AFFINITY_TEXT), - FUNCTION(trim, 1, 3, 0, trimFunc, AFFINITY_TEXT), - FUNCTION(trim, 2, 3, 0, trimFunc, AFFINITY_TEXT), + FIELD_TYPE_INTEGER), + FUNCTION(ltrim, 1, 1, 0, trimFunc, FIELD_TYPE_STRING), + FUNCTION(ltrim, 2, 1, 0, trimFunc, FIELD_TYPE_STRING), + FUNCTION(rtrim, 1, 2, 0, trimFunc, FIELD_TYPE_STRING), + FUNCTION(rtrim, 2, 2, 0, trimFunc, FIELD_TYPE_STRING), + FUNCTION(trim, 1, 3, 0, trimFunc, FIELD_TYPE_STRING), + FUNCTION(trim, 2, 3, 0, trimFunc, FIELD_TYPE_STRING), FUNCTION(min, -1, 0, 1, minmaxFunc, 0), FUNCTION(min, 0, 0, 1, 0, 0), AGGREGATE2(min, 1, 0, 1, minmaxStep, minMaxFinalize, @@ -1724,56 +1724,49 @@ sqlite3RegisterBuiltinFunctions(void) AGGREGATE2(max, 1, 1, 1, minmaxStep, minMaxFinalize, SQLITE_FUNC_MINMAX, 0), FUNCTION2(typeof, 1, 0, 0, typeofFunc, SQLITE_FUNC_TYPEOF, - AFFINITY_TEXT), + FIELD_TYPE_STRING), FUNCTION2(length, 1, 0, 0, lengthFunc, SQLITE_FUNC_LENGTH, - AFFINITY_INTEGER), - FUNCTION(instr, 2, 0, 0, instrFunc, AFFINITY_INTEGER), - FUNCTION(printf, -1, 0, 0, printfFunc, AFFINITY_TEXT), - FUNCTION(unicode, 1, 0, 0, unicodeFunc, AFFINITY_TEXT), - FUNCTION(char, -1, 0, 0, charFunc, AFFINITY_TEXT), - FUNCTION(abs, 1, 0, 0, absFunc, AFFINITY_REAL), + FIELD_TYPE_INTEGER), + FUNCTION(instr, 2, 0, 0, instrFunc, FIELD_TYPE_INTEGER), + FUNCTION(printf, -1, 0, 0, printfFunc, FIELD_TYPE_STRING), + FUNCTION(unicode, 1, 0, 0, unicodeFunc, FIELD_TYPE_STRING), + FUNCTION(char, -1, 0, 0, charFunc, FIELD_TYPE_STRING), + FUNCTION(abs, 1, 0, 0, absFunc, FIELD_TYPE_NUMBER), #ifndef SQLITE_OMIT_FLOATING_POINT - FUNCTION(round, 1, 0, 0, roundFunc, AFFINITY_INTEGER), - FUNCTION(round, 2, 0, 0, roundFunc, AFFINITY_INTEGER), + FUNCTION(round, 1, 0, 0, roundFunc, FIELD_TYPE_INTEGER), + FUNCTION(round, 2, 0, 0, roundFunc, FIELD_TYPE_INTEGER), #endif - FUNCTION(upper, 1, 0, 1, UpperICUFunc, AFFINITY_TEXT), - FUNCTION(lower, 1, 0, 1, LowerICUFunc, AFFINITY_TEXT), - FUNCTION(hex, 1, 0, 0, hexFunc, AFFINITY_TEXT), + FUNCTION(upper, 1, 0, 1, UpperICUFunc, FIELD_TYPE_STRING), + FUNCTION(lower, 1, 0, 1, LowerICUFunc, FIELD_TYPE_STRING), + FUNCTION(hex, 1, 0, 0, hexFunc, FIELD_TYPE_STRING), FUNCTION2(ifnull, 2, 0, 0, noopFunc, SQLITE_FUNC_COALESCE, - AFFINITY_INTEGER), - VFUNCTION(random, 0, 0, 0, randomFunc, AFFINITY_REAL), - VFUNCTION(randomblob, 1, 0, 0, randomBlob, AFFINITY_BLOB), + FIELD_TYPE_INTEGER), + VFUNCTION(random, 0, 0, 0, randomFunc, FIELD_TYPE_NUMBER), + VFUNCTION(randomblob, 1, 0, 0, randomBlob, FIELD_TYPE_SCALAR), FUNCTION(nullif, 2, 0, 1, nullifFunc, 0), - FUNCTION(version, 0, 0, 0, sql_func_version, AFFINITY_TEXT), - FUNCTION(quote, 1, 0, 0, quoteFunc, AFFINITY_TEXT), - VFUNCTION(row_count, 0, 0, 0, sql_row_count, AFFINITY_INTEGER), - FUNCTION(replace, 3, 0, 0, replaceFunc, AFFINITY_TEXT), - FUNCTION(zeroblob, 1, 0, 0, zeroblobFunc, AFFINITY_BLOB), - FUNCTION(substr, 2, 0, 0, substrFunc, AFFINITY_TEXT), - FUNCTION(substr, 3, 0, 0, substrFunc, AFFINITY_TEXT), + FUNCTION(version, 0, 0, 0, sql_func_version, FIELD_TYPE_STRING), + FUNCTION(quote, 1, 0, 0, quoteFunc, FIELD_TYPE_STRING), + VFUNCTION(row_count, 0, 0, 0, sql_row_count, FIELD_TYPE_INTEGER), + FUNCTION(replace, 3, 0, 0, replaceFunc, FIELD_TYPE_STRING), + FUNCTION(zeroblob, 1, 0, 0, zeroblobFunc, FIELD_TYPE_SCALAR), + FUNCTION(substr, 2, 0, 0, substrFunc, FIELD_TYPE_STRING), + FUNCTION(substr, 3, 0, 0, substrFunc, FIELD_TYPE_STRING), AGGREGATE(sum, 1, 0, 0, sumStep, sumFinalize, 0), AGGREGATE(total, 1, 0, 0, sumStep, totalFinalize, 0), AGGREGATE(avg, 1, 0, 0, sumStep, avgFinalize, 0), AGGREGATE2(count, 0, 0, 0, countStep, countFinalize, - SQLITE_FUNC_COUNT, AFFINITY_INTEGER), + SQLITE_FUNC_COUNT, FIELD_TYPE_INTEGER), AGGREGATE(count, 1, 0, 0, countStep, countFinalize, - AFFINITY_INTEGER), + FIELD_TYPE_INTEGER), AGGREGATE(group_concat, 1, 0, 0, groupConcatStep, - groupConcatFinalize, AFFINITY_TEXT), + groupConcatFinalize, FIELD_TYPE_STRING), AGGREGATE(group_concat, 2, 0, 0, groupConcatStep, - groupConcatFinalize, AFFINITY_TEXT), - -#ifdef SQLITE_CASE_SENSITIVE_LIKE - LIKEFUNC(like, 2, 0,SQLITE_FUNC_LIKE | SQLITE_FUNC_CASE, - AFFINITY_INTEGER), - LIKEFUNC(like, 3, 0,SQLITE_FUNC_LIKE | SQLITE_FUNC_CASE, - AFFINITY_INTEGER), -#else + groupConcatFinalize, FIELD_TYPE_STRING), + LIKEFUNC(like, 2, 1, SQLITE_FUNC_LIKE, - AFFINITY_INTEGER), + FIELD_TYPE_INTEGER), LIKEFUNC(like, 3, 1, SQLITE_FUNC_LIKE, - AFFINITY_INTEGER), -#endif + FIELD_TYPE_INTEGER), #ifdef SQLITE_ENABLE_UNKNOWN_SQL_FUNCTION FUNCTION(unknown, -1, 0, 0, unknownFunc, 0), #endif diff --git a/src/box/sql/main.c b/src/box/sql/main.c index 8574d6464..c009b9c63 100644 --- a/src/box/sql/main.c +++ b/src/box/sql/main.c @@ -750,7 +750,7 @@ sqlite3_interrupt(sqlite3 * db) int sqlite3CreateFunc(sqlite3 * db, const char *zFunctionName, - enum affinity_type type, + enum field_type type, int nArg, int flags, void *pUserData, @@ -820,7 +820,7 @@ sqlite3CreateFunc(sqlite3 * db, int sqlite3_create_function_v2(sqlite3 * db, const char *zFunc, - enum affinity_type type, + enum field_type type, int nArg, int flags, void *p, diff --git a/src/box/sql/sqliteInt.h b/src/box/sql/sqliteInt.h index e2d630929..2a7223fff 100644 --- a/src/box/sql/sqliteInt.h +++ b/src/box/sql/sqliteInt.h @@ -732,7 +732,7 @@ sqlite3_memory_used(void); int sqlite3_create_function_v2(sqlite3 * db, const char *zFunctionName, - enum affinity_type type, + enum field_type type, int nArg, int flags, void *pApp, @@ -1660,7 +1660,7 @@ struct FuncDef { FuncDestructor *pDestructor; /* Reference counted destructor function */ } u; /* Return type. */ - enum affinity_type ret_type; + enum field_type ret_type; }; /* @@ -4569,7 +4569,7 @@ void sqlite3RegisterLikeFunctions(sqlite3 *, int); int sql_is_like_func(struct sqlite3 *db, struct Expr *expr, int *is_like_ci); -int sqlite3CreateFunc(sqlite3 *, const char *, enum affinity_type, +int sqlite3CreateFunc(sqlite3 *, const char *, enum field_type, int, int, void *, void (*)(sqlite3_context *, int, sqlite3_value **), void (*)(sqlite3_context *, int, sqlite3_value **), -- 2.15.1
next prev parent reply other threads:[~2018-12-28 9:34 UTC|newest] Thread overview: 48+ messages / expand[flat|nested] mbox.gz Atom feed top 2018-12-28 9:34 [tarantool-patches] [PATCH 0/8] Eliminate affinity from source code Nikita Pettik 2018-12-28 9:34 ` [tarantool-patches] [PATCH 1/8] sql: remove SQLITE_ENABLE_UPDATE_DELETE_LIMIT define Nikita Pettik 2018-12-29 17:42 ` [tarantool-patches] " Vladislav Shpilevoy 2019-01-16 14:25 ` n.pettik 2018-12-28 9:34 ` [tarantool-patches] [PATCH 2/8] sql: use field type instead of affinity for type_def Nikita Pettik 2018-12-29 17:42 ` [tarantool-patches] " Vladislav Shpilevoy 2019-01-16 14:26 ` n.pettik 2018-12-28 9:34 ` [tarantool-patches] [PATCH 3/8] sql: remove numeric affinity Nikita Pettik 2018-12-29 9:01 ` [tarantool-patches] " Konstantin Osipov 2018-12-29 17:42 ` Vladislav Shpilevoy 2019-01-09 8:26 ` Konstantin Osipov 2019-01-16 14:26 ` n.pettik 2019-01-22 15:41 ` Vladislav Shpilevoy 2019-01-28 16:39 ` n.pettik 2019-01-30 13:04 ` Vladislav Shpilevoy 2019-02-01 16:39 ` n.pettik 2019-01-09 8:20 ` Konstantin Osipov 2018-12-28 9:34 ` Nikita Pettik [this message] 2018-12-28 9:34 ` [tarantool-patches] [PATCH 5/8] sql: replace field type with affinity for VDBE runtime Nikita Pettik 2018-12-29 17:42 ` [tarantool-patches] " Vladislav Shpilevoy 2019-01-16 14:26 ` n.pettik 2019-01-22 15:41 ` Vladislav Shpilevoy 2019-01-28 16:39 ` n.pettik 2019-01-30 13:04 ` Vladislav Shpilevoy 2019-02-01 16:39 ` n.pettik 2019-02-05 15:08 ` Vladislav Shpilevoy 2019-02-05 17:46 ` n.pettik 2018-12-28 9:34 ` [tarantool-patches] [PATCH 6/8] sql: replace affinity with field type in struct Expr Nikita Pettik 2018-12-29 17:42 ` [tarantool-patches] " Vladislav Shpilevoy 2019-01-16 14:26 ` n.pettik 2019-01-22 15:41 ` Vladislav Shpilevoy 2019-01-28 16:39 ` n.pettik 2019-01-30 13:04 ` Vladislav Shpilevoy 2019-02-01 16:39 ` n.pettik 2019-02-05 15:08 ` Vladislav Shpilevoy 2019-02-05 17:46 ` n.pettik 2018-12-28 9:34 ` [tarantool-patches] [PATCH 7/8] sql: clean-up affinity from SQL source code Nikita Pettik 2018-12-29 17:42 ` [tarantool-patches] " Vladislav Shpilevoy 2019-01-16 14:26 ` n.pettik 2019-01-22 15:41 ` Vladislav Shpilevoy 2019-01-28 16:40 ` n.pettik 2019-01-30 13:04 ` Vladislav Shpilevoy 2019-02-01 16:39 ` n.pettik 2019-02-05 15:08 ` Vladislav Shpilevoy 2019-02-05 17:46 ` n.pettik 2018-12-28 9:34 ` [tarantool-patches] [PATCH 8/8] Remove affinity from field definition Nikita Pettik 2019-02-05 19:41 ` [tarantool-patches] Re: [PATCH 0/8] Eliminate affinity from source code Vladislav Shpilevoy 2019-02-08 13:37 ` Kirill Yukhin
Reply instructions: You may reply publicly to this message via plain-text email using any one of the following methods: * Save the following mbox file, import it into your mail client, and reply-to-all from there: mbox Avoid top-posting and favor interleaved quoting: https://en.wikipedia.org/wiki/Posting_style#Interleaved_style * Reply using the --to, --cc, and --in-reply-to switches of git-send-email(1): git send-email \ --in-reply-to=c213190ad8a8183796bb2e066891aaf5789e3991.1545987214.git.korablev@tarantool.org \ --to=korablev@tarantool.org \ --cc=tarantool-patches@freelists.org \ --cc=v.shpilevoy@tarantool.org \ --subject='Re: [tarantool-patches] [PATCH 4/8] sql: replace affinity with field type for func' \ /path/to/YOUR_REPLY https://kernel.org/pub/software/scm/git/docs/git-send-email.html * If your mail client supports setting the In-Reply-To header via mailto: links, try the mailto: link
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox