Tarantool development patches archive
 help / color / mirror / Atom feed
From: Nikita Pettik <korablev@tarantool.org>
To: tarantool-patches@dev.tarantool.org
Cc: v.shpilevoy@tarantool.org
Subject: [Tarantool-patches] [PATCH] sql: fix return value type of ifnull built-in
Date: Wed, 23 Dec 2020 13:58:22 +0300	[thread overview]
Message-ID: <20201223105822.4748-1-korablev@tarantool.org> (raw)

Accidentally, in built-in declaration list it was specified that
ifnull() can return only integer values, meanwhile it should return
SCALAR: ifnull() returns first non-null argument so type of return value
depends on type of arguments. Let's fix this and set return type of
ifnull() SCALAR.
---
Branch: https://github.com/tarantool/tarantool/tree/np/fix-ifnull-retval
Bug was reported by Mike Siomkin

@Changelog
 * Fixed wrong type of return value of ifnull() built-in function.
 
 src/box/sql/func.c          |  2 +-
 test/sql-tap/func5.test.lua | 23 ++++++++++++++++++++++-
 2 files changed, 23 insertions(+), 2 deletions(-)

diff --git a/src/box/sql/func.c b/src/box/sql/func.c
index 0aedb2d3d..f15d27051 100644
--- a/src/box/sql/func.c
+++ b/src/box/sql/func.c
@@ -2466,7 +2466,7 @@ static struct {
 	}, {
 	 .name = "IFNULL",
 	 .param_count = 2,
-	 .returns = FIELD_TYPE_INTEGER,
+	 .returns = FIELD_TYPE_SCALAR,
 	 .aggregate = FUNC_AGGREGATE_NONE,
 	 .is_deterministic = true,
 	 .flags = SQL_FUNC_COALESCE,
diff --git a/test/sql-tap/func5.test.lua b/test/sql-tap/func5.test.lua
index c991e9163..b1e246ccc 100755
--- a/test/sql-tap/func5.test.lua
+++ b/test/sql-tap/func5.test.lua
@@ -1,6 +1,6 @@
 #!/usr/bin/env tarantool
 local test = require("sqltester")
-test:plan(22)
+test:plan(25)
 
 --!./tcltestrunner.lua
 -- 2010 August 27
@@ -290,6 +290,27 @@ test:do_catchsql_test(
         SELECT LEAST();
     ]], { 1, "Wrong number of arguments is passed to LEAST(): expected at least two, got 0" } )
 
+-- Make sure that ifnull() returns type of corresponding (i.e. first
+-- non-null) argument.
+--
+test:do_execsql_test(
+    "func-6.1-ifnull",
+    [[
+        SELECT ifnull('qqq1', 'qqq2') = 'qqq2';
+    ]], { false } )
+
+test:do_execsql_test(
+    "func-6.2-ifnull",
+    [[
+        SELECT ifnull(null, 'qqq2') = 'qqq2';
+    ]], { true } )
+
+test:do_execsql_test(
+    "func-6.3-ifnull",
+    [[
+        SELECT ifnull(null, 1) = 'qqq2';
+    ]], { false } )
+
 box.func.COUNTER1:drop()
 box.func.COUNTER2:drop()
 
-- 
2.17.1

             reply	other threads:[~2020-12-23 10:58 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-12-23 10:58 Nikita Pettik [this message]
2020-12-23 15:02 ` Vladislav Shpilevoy
2020-12-23 17:07   ` Nikita 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=20201223105822.4748-1-korablev@tarantool.org \
    --to=korablev@tarantool.org \
    --cc=tarantool-patches@dev.tarantool.org \
    --cc=v.shpilevoy@tarantool.org \
    --subject='Re: [Tarantool-patches] [PATCH] sql: fix return value type of ifnull built-in' \
    /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