Tarantool development patches archive
 help / color / mirror / Atom feed
From: Kirill Shcherbatov <kshcherbatov@tarantool.org>
To: tarantool-patches@freelists.org, korablev@tarantool.org
Cc: kostja@tarantool.org, Kirill Shcherbatov <kshcherbatov@tarantool.org>
Subject: [tarantool-patches] [PATCH v2 01/12] sql: get rid of SOUNDEX, MATCH
Date: Wed, 10 Jul 2019 14:00:57 +0300	[thread overview]
Message-ID: <d5d2cf861267cbe03e30acb51d81ce87461486fb.1562756438.git.kshcherbatov@tarantool.org> (raw)
In-Reply-To: <cover.1562756438.git.kshcherbatov@tarantool.org>

In relation with FuncDef cache rework we need to clean-up
builtins list. The SOUNDEX function is not in use while MATCH
fucntion is a stub that raises an error, so they could be
dropped.

Needed for #4182
---
 src/box/sql/func.c           | 92 ------------------------------------
 src/box/sql/main.c           |  6 ---
 src/box/sql/sqlInt.h         |  2 -
 src/box/sql/vdbeapi.c        | 20 --------
 test/sql-tap/e_expr.test.lua | 26 +---------
 test/sql-tap/func.test.lua   | 75 +----------------------------
 6 files changed, 2 insertions(+), 219 deletions(-)

diff --git a/src/box/sql/func.c b/src/box/sql/func.c
index 761a3abae..f0e1b1f0c 100644
--- a/src/box/sql/func.c
+++ b/src/box/sql/func.c
@@ -1468,67 +1468,6 @@ trim_func_three_args(struct sql_context *context, int argc, sql_value **argv)
 	sql_free(char_len);
 }
 
-/* IMP: R-25361-16150 This function is omitted from sql by default. It
- * is only available if the SQL_SOUNDEX compile-time option is used
- * when sql is built.
- */
-#ifdef SQL_SOUNDEX
-/*
- * Compute the soundex encoding of a word.
- *
- * IMP: R-59782-00072 The soundex(X) function returns a string that is the
- * soundex encoding of the string X.
- */
-static void
-soundexFunc(sql_context * context, int argc, sql_value ** argv)
-{
-	char zResult[8];
-	const u8 *zIn;
-	int i, j;
-	static const unsigned char iCode[] = {
-		0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
-		0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
-		0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
-		0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
-		0, 0, 1, 2, 3, 0, 1, 2, 0, 0, 2, 2, 4, 5, 5, 0,
-		1, 2, 6, 2, 3, 0, 1, 0, 2, 0, 2, 0, 0, 0, 0, 0,
-		0, 0, 1, 2, 3, 0, 1, 2, 0, 0, 2, 2, 4, 5, 5, 0,
-		1, 2, 6, 2, 3, 0, 1, 0, 2, 0, 2, 0, 0, 0, 0, 0,
-	};
-	assert(argc == 1);
-	zIn = (u8 *) sql_value_text(argv[0]);
-	if (zIn == 0)
-		zIn = (u8 *) "";
-	for (i = 0; zIn[i] && !sqlIsalpha(zIn[i]); i++) {
-	}
-	if (zIn[i]) {
-		u8 prevcode = iCode[zIn[i] & 0x7f];
-		zResult[0] = sqlToupper(zIn[i]);
-		for (j = 1; j < 4 && zIn[i]; i++) {
-			int code = iCode[zIn[i] & 0x7f];
-			if (code > 0) {
-				if (code != prevcode) {
-					prevcode = code;
-					zResult[j++] = code + '0';
-				}
-			} else {
-				prevcode = 0;
-			}
-		}
-		while (j < 4) {
-			zResult[j++] = '0';
-		}
-		zResult[j] = 0;
-		sql_result_text(context, zResult, 4, SQL_TRANSIENT);
-	} else {
-		/* IMP: R-64894-50321 The string "?000" is returned if the argument
-		 * is NULL or contains no ASCII alphabetic characters.
-		 */
-		sql_result_text(context, "?000", 4, SQL_STATIC);
-	}
-}
-#endif				/* SQL_SOUNDEX */
-
 /*
  * An instance of the following structure holds the context of a
  * sum() or avg() aggregate computation.
@@ -1763,34 +1702,6 @@ groupConcatFinalize(sql_context * context)
 	}
 }
 
-/*
- * If the function already exists as a regular global function, then
- * this routine is a no-op.  If the function does not exist, then create
- * a new one that always throws a run-time error.
- */
-static inline int
-sql_overload_function(sql * db, const char *zName,
-			  enum field_type type, int nArg)
-{
-	if (sqlFindFunction(db, zName, nArg, 0) == 0) {
-		return sqlCreateFunc(db, zName, type, nArg, 0, 0,
-				     sqlInvalidFunction, 0, 0, 0);
-	}
-	return 0;
-}
-
-/*
- * This routine does per-connection function registration.  Most
- * of the built-in functions above are part of the global function set.
- * This routine only deals with those that are not global.
- */
-void
-sqlRegisterPerConnectionBuiltinFunctions(sql * db)
-{
-	if (sql_overload_function(db, "MATCH", FIELD_TYPE_SCALAR, 2) != 0)
-		sqlOomFault(db);
-}
-
 /*
  * Set the LIKEOPT flag on the 2-argument function with the given name.
  */
@@ -1869,9 +1780,6 @@ sqlRegisterBuiltinFunctions(void)
 	 * For peak efficiency, put the most frequently used function last.
 	 */
 	static FuncDef aBuiltinFunc[] = {
-#ifdef SQL_SOUNDEX
-		FUNCTION(soundex, 1, 0, 0, soundexFunc),
-#endif
 		FUNCTION2(unlikely, 1, 0, 0, noopFunc, SQL_FUNC_UNLIKELY,
 			  FIELD_TYPE_BOOLEAN),
 		FUNCTION2(likelihood, 2, 0, 0, noopFunc, SQL_FUNC_UNLIKELY,
diff --git a/src/box/sql/main.c b/src/box/sql/main.c
index bfe3d7186..89d83d242 100644
--- a/src/box/sql/main.c
+++ b/src/box/sql/main.c
@@ -460,12 +460,6 @@ sql_init_db(sql **out_db)
 		return -1;
 	}
 
-	/* Register all built-in functions, but do not attempt to read the
-	 * database schema yet. This is delayed until the first time the database
-	 * is accessed.
-	 */
-	sqlRegisterPerConnectionBuiltinFunctions(db);
-
 	*out_db = db;
 	return 0;
 }
diff --git a/src/box/sql/sqlInt.h b/src/box/sql/sqlInt.h
index 73dc6e4d7..9305f7d5c 100644
--- a/src/box/sql/sqlInt.h
+++ b/src/box/sql/sqlInt.h
@@ -3524,7 +3524,6 @@ void sqlInsertBuiltinFuncs(FuncDef *, int);
 FuncDef *sqlFindFunction(sql *, const char *, int, u8);
 void sqlRegisterBuiltinFunctions(void);
 void sqlRegisterDateTimeFunctions(void);
-void sqlRegisterPerConnectionBuiltinFunctions(sql *);
 
 /**
  * Evaluate a view and store its result in an ephemeral table.
@@ -4359,7 +4358,6 @@ void sqlParser(void *, int, Token, Parse *);
 int sqlParserStackPeak(void *);
 #endif
 
-void sqlInvalidFunction(sql_context *, int, sql_value **);
 sql_int64 sqlStmtCurrentTime(sql_context *);
 int sqlVdbeParameterIndex(Vdbe *, const char *, int);
 int sqlTransferBindings(sql_stmt *, sql_stmt *);
diff --git a/src/box/sql/vdbeapi.c b/src/box/sql/vdbeapi.c
index f470ac6b1..ef0ab79d2 100644
--- a/src/box/sql/vdbeapi.c
+++ b/src/box/sql/vdbeapi.c
@@ -519,26 +519,6 @@ sqlStmtCurrentTime(sql_context * p)
 	return *piTime;
 }
 
-/*
- * The following is the implementation of an SQL function that always
- * fails with an error message stating that the function is used in the
- * wrong context.  The sql_overload_function() API might construct
- * SQL function that use this routine so that the functions will exist
- * for name resolution.
- */
-void
-sqlInvalidFunction(sql_context * context,	/* The function calling context */
-		       int NotUsed,	/* Number of arguments to the function */
-		       sql_value ** NotUsed2	/* Value of each argument */
-    )
-{
-	const char *zName = context->pFunc->zName;
-	UNUSED_PARAMETER2(NotUsed, NotUsed2);
-	const char *err = "unable to use function %s in the requested context";
-	diag_set(ClientError, ER_SQL_EXECUTE, tt_sprintf(err, zName));
-	context->is_aborted = true;
-}
-
 /*
  * Create a new aggregate context for p and return a pointer to
  * its pMem->z element.
diff --git a/test/sql-tap/e_expr.test.lua b/test/sql-tap/e_expr.test.lua
index 7b80651a8..6d56bf58b 100755
--- a/test/sql-tap/e_expr.test.lua
+++ b/test/sql-tap/e_expr.test.lua
@@ -1,6 +1,6 @@
 #!/usr/bin/env tarantool
 test = require("sqltester")
-test:plan(10641)
+test:plan(10639)
 
 --!./tcltestrunner.lua
 -- 2010 July 16
@@ -2405,30 +2405,6 @@ test:do_test(
         -- </e_expr-18.2.4>
     })
 
---sql("db", "test.db")
--- EVIDENCE-OF: R-42037-37826 The default match() function implementation
--- raises an exception and is not really useful for anything.
---
-test:do_catchsql_test(
-    "e_expr-19.1.1",
-    [[
-        SELECT 'abc' MATCH 'def'
-    ]], {
-        -- <e_expr-19.1.1>
-        1, "unable to use function MATCH in the requested context"
-        -- </e_expr-19.1.1>
-    })
-
-test:do_catchsql_test(
-    "e_expr-19.1.2",
-    [[
-        SELECT match('abc', 'def')
-    ]], {
-        -- <e_expr-19.1.2>
-        1, "unable to use function MATCH in the requested context"
-        -- </e_expr-19.1.2>
-    })
-
 -- EVIDENCE-OF: R-37916-47407 The MATCH operator is a special syntax for
 -- the match() application-defined function.
 --
diff --git a/test/sql-tap/func.test.lua b/test/sql-tap/func.test.lua
index f9044ad01..64d53bac8 100755
--- a/test/sql-tap/func.test.lua
+++ b/test/sql-tap/func.test.lua
@@ -1,6 +1,6 @@
 #!/usr/bin/env tarantool
 test = require("sqltester")
-test:plan(14590)
+test:plan(14586)
 
 --!./tcltestrunner.lua
 -- 2001 September 15
@@ -1734,79 +1734,6 @@ test:do_catchsql_test(
         -- </func-18.32>
     })
 
--- The MATCH function exists but is only a stub and always throws an error.
---
-test:do_execsql_test(
-    "func-19.1",
-    [[
-        SELECT match(a,b) FROM t1 WHERE false;
-    ]], {
-        -- <func-19.1>
-        
-        -- </func-19.1>
-    })
-
-test:do_catchsql_test(
-    "func-19.2",
-    [[
-        SELECT 'abc' MATCH 'xyz';
-    ]], {
-        -- <func-19.2>
-        1, "Failed to execute SQL statement: unable to use function MATCH in the requested context"
-        -- </func-19.2>
-    })
-
-test:do_catchsql_test(
-    "func-19.3",
-    [[
-        SELECT 'abc' NOT MATCH 'xyz';
-    ]], {
-        -- <func-19.3>
-        1, "Failed to execute SQL statement: unable to use function MATCH in the requested context"
-        -- </func-19.3>
-    })
-
-test:do_catchsql_test(
-    "func-19.4",
-    [[
-        SELECT match(1,2,3);
-    ]], {
-        -- <func-19.4>
-        1, "wrong number of arguments to function MATCH()"
-        -- </func-19.4>
-    })
-
--- Soundex tests.
---
--- false condition for current tarantool version
-if pcall( function() test:execsql("SELECT soundex('hello')") end ) then
-    for i, val in ipairs({
-        {"euler", "E460"},
-        {"EULER", "E460"},    
-        {"Euler", "E460"},    
-        {"ellery", "E460"},    
-        {"gauss", "G200"},    
-        {"ghosh", "G200"},    
-        {"hilbert", "H416"},    
-        {"Heilbronn", "H416"},    
-        {"knuth", "K530"},    
-        {"kant", "K530"},    
-        {"Lloyd", "L300"},    
-        {"LADD", "L300"},    
-        {"Lukasiewicz", "L222"},    
-        {"Lissajous", "L222"},    
-        {"A", "A000"},    
-        {"12345", "?000"} }) do
-        local name = val[1]
-        local sdx = val[2]
-        test:do_execsql_test(
-            "func-20."..i,
-            string.format("SELECT soundex('%s')", name), {
-                sdx
-            })
-
-    end
-end
 -- Tests of the REPLACE function.
 --
 test:do_catchsql_test(
-- 
2.21.0

  reply	other threads:[~2019-07-10 11:01 UTC|newest]

Thread overview: 35+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-07-10 11:00 [tarantool-patches] [PATCH v2 00/12] sql: uniform SQL and Lua functions subsystem Kirill Shcherbatov
2019-07-10 11:00 ` Kirill Shcherbatov [this message]
2019-07-10 18:45   ` [tarantool-patches] Re: [PATCH v2 01/12] sql: get rid of SOUNDEX, MATCH Konstantin Osipov
2019-07-12  8:44   ` Kirill Yukhin
2019-07-10 11:00 ` [tarantool-patches] [PATCH v2 10/12] sql: refactor builtins signatures with port Kirill Shcherbatov
2019-07-10 18:47   ` [tarantool-patches] " Konstantin Osipov
2019-07-11  7:33     ` Kirill Shcherbatov
2019-07-10 11:00 ` [tarantool-patches] [PATCH v2 11/12] box: use own vtab per each function object Kirill Shcherbatov
2019-07-10 11:01 ` [tarantool-patches] [PATCH v2 12/12] sql: use schema's func hash instead of FuncDef hash Kirill Shcherbatov
2019-07-10 20:22   ` [tarantool-patches] " Konstantin Osipov
2019-07-10 11:01 ` [tarantool-patches] [PATCH v2 02/12] sql: get rid of LIKELY, UNLIKELY and LIKEHOOD Kirill Shcherbatov
2019-07-10 19:02   ` [tarantool-patches] " Konstantin Osipov
2019-07-11  7:38     ` Kirill Shcherbatov
2019-07-10 11:01 ` [tarantool-patches] [PATCH v2 03/12] sql: put analyze helpers to FuncDef cache Kirill Shcherbatov
2019-07-10 19:04   ` [tarantool-patches] " Konstantin Osipov
2019-07-12  8:47   ` Kirill Yukhin
2019-07-10 11:01 ` [tarantool-patches] [PATCH v2 04/12] sql: rework LIKE case-insensitive mode Kirill Shcherbatov
2019-07-10 19:09   ` [tarantool-patches] " Konstantin Osipov
2019-07-10 11:01 ` [tarantool-patches] [PATCH v2 05/12] sql: replace bool is_derived_coll marker with flag Kirill Shcherbatov
2019-07-10 19:10   ` [tarantool-patches] " Konstantin Osipov
2019-07-12  8:48   ` Kirill Yukhin
2019-07-10 11:01 ` [tarantool-patches] [PATCH v2 06/12] sql: remove SQL_PreferBuiltin flag Kirill Shcherbatov
2019-07-10 19:11   ` [tarantool-patches] " Konstantin Osipov
2019-07-10 11:01 ` [tarantool-patches] [PATCH v2 07/12] sql: move LIKE UConverter object to collation library Kirill Shcherbatov
2019-07-12  8:49   ` [tarantool-patches] " Kirill Yukhin
2019-07-10 11:01 ` [tarantool-patches] [PATCH v2 08/12] sql: rfc for SQL and Lua functions Kirill Shcherbatov
2019-07-10 19:17   ` [tarantool-patches] " Konstantin Osipov
2019-07-10 19:18     ` Konstantin Osipov
2019-07-11  7:40       ` Kirill Shcherbatov
2019-07-11 13:59   ` Kirill Yukhin
2019-07-10 11:01 ` [tarantool-patches] [PATCH v2 09/12] box: introduce Lua persistent functions Kirill Shcherbatov
2019-07-10 19:26   ` [tarantool-patches] " Konstantin Osipov
2019-07-12 21:49   ` Konstantin Osipov
2019-07-13 13:55     ` Kirill Yukhin
2019-07-13 14:17       ` 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=d5d2cf861267cbe03e30acb51d81ce87461486fb.1562756438.git.kshcherbatov@tarantool.org \
    --to=kshcherbatov@tarantool.org \
    --cc=korablev@tarantool.org \
    --cc=kostja@tarantool.org \
    --cc=tarantool-patches@freelists.org \
    --subject='Re: [tarantool-patches] [PATCH v2 01/12] sql: get rid of SOUNDEX, MATCH' \
    /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