Tarantool development patches archive
 help / color / mirror / Atom feed
From: Kirill Shcherbatov <kshcherbatov@tarantool.org>
To: tarantool-patches@freelists.org, korablev@tarantool.org
Cc: Kirill Shcherbatov <kshcherbatov@tarantool.org>
Subject: [tarantool-patches] [PATCH v2 3/8] sql: wrap all trim functions in dispatcher
Date: Thu,  8 Aug 2019 17:50:47 +0300	[thread overview]
Message-ID: <74a116ac889583f76d8617d644f6277073f9fbdd.1565275469.git.kshcherbatov@tarantool.org> (raw)
In-Reply-To: <cover.1565275469.git.kshcherbatov@tarantool.org>

A new dispatcher function trim_func calls corresponding trim_
function implementation in relation with number of argc - a count
of arguments.

This is an important stem to get rid of function's name
overloading required for replace FuncDef cache with Tarantool's
function cache.

Needed for #2200, #4113, #2233
---
 src/box/sql/func.c | 32 +++++++++++++++++++++++++++++---
 1 file changed, 29 insertions(+), 3 deletions(-)

diff --git a/src/box/sql/func.c b/src/box/sql/func.c
index e00764c3f..f9c0a819e 100644
--- a/src/box/sql/func.c
+++ b/src/box/sql/func.c
@@ -1496,6 +1496,32 @@ trim_func_three_args(struct sql_context *context, int argc, sql_value **argv)
 		       char_cnt, input_str, input_str_sz);
 	sql_free(char_len);
 }
+
+/**
+ * Normalize args from @a argv input array when it has one,
+ * two or three args.
+ *
+ * This is a dispatcher function that call corresponding
+ * implementation depending on the number of arguments.
+*/
+static void
+trim_func(struct sql_context *context, int argc, sql_value **argv)
+{
+	switch (argc) {
+	case 1:
+		trim_func_one_arg(context, argc, argv);
+		break;
+	case 2:
+		trim_func_two_args(context, argc, argv);
+		break;
+	case 3:
+		trim_func_three_args(context, argc, argv);
+		break;
+	default:
+		unreachable();
+	}
+}
+
 /*
  * Compute the soundex encoding of a word.
  *
@@ -1840,9 +1866,9 @@ sqlRegisterBuiltinFunctions(void)
 			  FIELD_TYPE_BOOLEAN),
 		FUNCTION2(likely, 1, 0, 0, noopFunc, SQL_FUNC_UNLIKELY,
 			  FIELD_TYPE_BOOLEAN),
-		FUNCTION_COLL(trim, 1, 3, 0, trim_func_one_arg),
-		FUNCTION_COLL(trim, 2, 3, 0, trim_func_two_args),
-		FUNCTION_COLL(trim, 3, 3, 0, trim_func_three_args),
+		FUNCTION_COLL(trim, 1, 3, 0, trim_func),
+		FUNCTION_COLL(trim, 2, 3, 0, trim_func),
+		FUNCTION_COLL(trim, 3, 3, 0, trim_func),
 		FUNCTION(least, -1, 0, 1, minmaxFunc, FIELD_TYPE_SCALAR),
 		AGGREGATE2(min, 1, 0, 1, minmaxStep, minMaxFinalize,
 			   SQL_FUNC_MINMAX, FIELD_TYPE_SCALAR),
-- 
2.22.0

  parent reply	other threads:[~2019-08-08 14:50 UTC|newest]

Thread overview: 38+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-08-08 14:50 [tarantool-patches] [PATCH v2 0/8] sql: uniform SQL and Lua functions subsystem Kirill Shcherbatov
2019-08-08 14:50 ` [tarantool-patches] [PATCH v2 1/8] sql: remove SQL_PreferBuiltin flag Kirill Shcherbatov
2019-08-09 16:07   ` [tarantool-patches] " n.pettik
2019-08-12 21:58   ` Konstantin Osipov
2019-08-08 14:50 ` [tarantool-patches] [PATCH v2 2/8] sql: GREATEST, LEAST instead of MIN/MAX overload Kirill Shcherbatov
2019-08-09 17:37   ` [tarantool-patches] " n.pettik
2019-08-13  8:26     ` Kirill Shcherbatov
2019-08-12 21:59   ` Konstantin Osipov
2019-08-08 14:50 ` Kirill Shcherbatov [this message]
2019-08-09 18:05   ` [tarantool-patches] Re: [PATCH v2 3/8] sql: wrap all trim functions in dispatcher n.pettik
2019-08-13  8:28     ` Kirill Shcherbatov
2019-08-13 22:19       ` n.pettik
2019-08-12 22:00   ` Konstantin Osipov
2019-08-08 14:50 ` [tarantool-patches] [PATCH v2 4/8] sql: get rid of SQL_FUNC_COUNT flag Kirill Shcherbatov
2019-08-12 22:01   ` [tarantool-patches] " Konstantin Osipov
2019-08-13 20:35   ` n.pettik
2019-08-14  7:25     ` Kirill Shcherbatov
2019-08-08 14:50 ` [tarantool-patches] [PATCH v2 5/8] sql: introduce a signature_mask for functions Kirill Shcherbatov
2019-08-12 22:04   ` [tarantool-patches] " Konstantin Osipov
2019-08-13  8:32     ` Kirill Shcherbatov
2019-08-13  8:44       ` Konstantin Osipov
2019-08-13 20:38   ` n.pettik
2019-08-14  7:21     ` Kirill Shcherbatov
2019-08-08 14:50 ` [tarantool-patches] [PATCH v2 6/8] sql: rename OP_Function to OP_BuiltinFunction Kirill Shcherbatov
2019-08-12 22:04   ` [tarantool-patches] " Konstantin Osipov
2019-08-13 20:36   ` n.pettik
2019-08-08 14:50 ` [tarantool-patches] [PATCH v2 7/8] sql: get rid of FuncDef function hash Kirill Shcherbatov
2019-08-12 22:11   ` [tarantool-patches] " Konstantin Osipov
2019-08-13  7:29     ` Kirill Shcherbatov
2019-08-13  8:42       ` Konstantin Osipov
2019-08-13  9:45         ` Kirill Shcherbatov
2019-08-13 20:40   ` n.pettik
2019-08-16 12:57     ` Kirill Shcherbatov
2019-08-20 16:06       ` n.pettik
2019-08-08 14:50 ` [tarantool-patches] [PATCH v2 8/8] box: get rid of box.internal.sql_function_create Kirill Shcherbatov
2019-08-13 20:43   ` [tarantool-patches] " n.pettik
2019-08-16 12:57     ` Kirill Shcherbatov
2019-08-20 19:36       ` n.pettik

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=74a116ac889583f76d8617d644f6277073f9fbdd.1565275469.git.kshcherbatov@tarantool.org \
    --to=kshcherbatov@tarantool.org \
    --cc=korablev@tarantool.org \
    --cc=tarantool-patches@freelists.org \
    --subject='Re: [tarantool-patches] [PATCH v2 3/8] sql: wrap all trim functions in dispatcher' \
    /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