From: Mergen Imeev via Tarantool-patches <tarantool-patches@dev.tarantool.org>
To: kyukhin@tarantool.org
Cc: tarantool-patches@dev.tarantool.org
Subject: [Tarantool-patches] [PATCH v1 4/8] sql: refactor NULLIF() function
Date: Thu, 11 Nov 2021 13:45:30 +0300 [thread overview]
Message-ID: <c5e52288ea1d208f5b400ee4dc833160766c567a.1636627366.git.imeevma@gmail.com> (raw)
In-Reply-To: <cover.1636627365.git.imeevma@gmail.com>
Part of #4145
---
src/box/sql/func.c | 28 +++++++++++++---------------
1 file changed, 13 insertions(+), 15 deletions(-)
diff --git a/src/box/sql/func.c b/src/box/sql/func.c
index 88830fd78..7d54a39cd 100644
--- a/src/box/sql/func.c
+++ b/src/box/sql/func.c
@@ -331,6 +331,18 @@ func_lower_upper(struct sql_context *ctx, int argc, struct Mem *argv)
mem_set_str_allocated(ctx->pOut, res, new_len);
}
+/** Implementation of the NULLIF() function. */
+static void
+func_nullif(struct sql_context *ctx, int argc, struct Mem *argv)
+{
+ assert(argc == 2);
+ (void)argc;
+ if (mem_cmp_scalar(&argv[0], &argv[1], ctx->coll) == 0)
+ return;
+ if (mem_copy(ctx->pOut, &argv[0]) != 0)
+ ctx->is_aborted = true;
+}
+
static const unsigned char *
mem_as_ustr(struct Mem *mem)
{
@@ -1193,20 +1205,6 @@ likeFunc(sql_context *context, int argc, struct Mem *argv)
sql_result_bool(context, res == MATCH);
}
-/*
- * Implementation of the NULLIF(x,y) function. The result is the first
- * argument if the arguments are different. The result is NULL if the
- * arguments are equal to each other.
- */
-static void
-nullifFunc(struct sql_context *context, int argc, struct Mem *argv)
-{
- (void)argc;
- struct coll *pColl = context->coll;
- if (mem_cmp_scalar(&argv[0], &argv[1], pColl) != 0)
- sql_result_value(context, &argv[0]);
-}
-
/**
* Implementation of the version() function. The result is the
* version of the Tarantool that is running.
@@ -2003,7 +2001,7 @@ static struct sql_func_definition definitions[] = {
{"MIN", 1, {FIELD_TYPE_SCALAR}, FIELD_TYPE_SCALAR, step_minmax, NULL},
{"NULLIF", 2, {FIELD_TYPE_ANY, FIELD_TYPE_ANY}, FIELD_TYPE_SCALAR,
- nullifFunc, NULL},
+ func_nullif, NULL},
{"POSITION", 2, {FIELD_TYPE_STRING, FIELD_TYPE_STRING},
FIELD_TYPE_INTEGER, position_func, NULL},
{"PRINTF", -1, {FIELD_TYPE_ANY}, FIELD_TYPE_STRING, printfFunc,
--
2.25.1
next prev parent reply other threads:[~2021-11-11 10:47 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-11-11 10:45 [Tarantool-patches] [PATCH v1 0/8] Rework standard function Mergen Imeev via Tarantool-patches
2021-11-11 10:45 ` [Tarantool-patches] [PATCH v1 1/8] sql: refactor ABS() funcion Mergen Imeev via Tarantool-patches
2021-11-11 10:45 ` [Tarantool-patches] [PATCH v1 2/8] sql: rework CHAR_LENGTH() function Mergen Imeev via Tarantool-patches
2021-11-11 10:45 ` [Tarantool-patches] [PATCH v1 3/8] sql: refactor UPPER() and LOWER() functions Mergen Imeev via Tarantool-patches
2021-11-11 10:45 ` Mergen Imeev via Tarantool-patches [this message]
2021-11-11 10:45 ` [Tarantool-patches] [PATCH v1 5/8] sql: rework TRIM() function Mergen Imeev via Tarantool-patches
2021-11-11 10:45 ` [Tarantool-patches] [PATCH v1 6/8] sql: rework POSITION() function Mergen Imeev via Tarantool-patches
2021-11-11 10:45 ` [Tarantool-patches] [PATCH v1 7/8] sql: rework SUBSTR() function Mergen Imeev via Tarantool-patches
2021-11-11 10:45 ` [Tarantool-patches] [PATCH v1 8/8] sql: refactor LIKE() function Mergen Imeev via Tarantool-patches
2021-11-11 10:59 ` [Tarantool-patches] [PATCH v1 0/8] Rework standard function Kirill Yukhin via Tarantool-patches
-- strict thread matches above, loose matches on Subject: below --
2021-10-01 16:29 Mergen Imeev via Tarantool-patches
2021-10-01 16:29 ` [Tarantool-patches] [PATCH v1 4/8] sql: refactor NULLIF() function Mergen Imeev via Tarantool-patches
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=c5e52288ea1d208f5b400ee4dc833160766c567a.1636627366.git.imeevma@gmail.com \
--to=tarantool-patches@dev.tarantool.org \
--cc=imeevma@tarantool.org \
--cc=kyukhin@tarantool.org \
--subject='Re: [Tarantool-patches] [PATCH v1 4/8] sql: refactor NULLIF() function' \
/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