Tarantool development patches archive
 help / color / mirror / Atom feed
* [Tarantool-patches] [PATCH] sql: fix return value type of ifnull built-in
@ 2020-12-23 10:58 Nikita Pettik
  2020-12-23 15:02 ` Vladislav Shpilevoy
  0 siblings, 1 reply; 3+ messages in thread
From: Nikita Pettik @ 2020-12-23 10:58 UTC (permalink / raw)
  To: tarantool-patches; +Cc: v.shpilevoy

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

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [Tarantool-patches] [PATCH] sql: fix return value type of ifnull built-in
  2020-12-23 10:58 [Tarantool-patches] [PATCH] sql: fix return value type of ifnull built-in Nikita Pettik
@ 2020-12-23 15:02 ` Vladislav Shpilevoy
  2020-12-23 17:07   ` Nikita Pettik
  0 siblings, 1 reply; 3+ messages in thread
From: Vladislav Shpilevoy @ 2020-12-23 15:02 UTC (permalink / raw)
  To: Nikita Pettik, tarantool-patches

Hi! Thanks for the patch!

LGTM.

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [Tarantool-patches] [PATCH] sql: fix return value type of ifnull built-in
  2020-12-23 15:02 ` Vladislav Shpilevoy
@ 2020-12-23 17:07   ` Nikita Pettik
  0 siblings, 0 replies; 3+ messages in thread
From: Nikita Pettik @ 2020-12-23 17:07 UTC (permalink / raw)
  To: Vladislav Shpilevoy; +Cc: tarantool-patches

On 23 Dec 16:02, Vladislav Shpilevoy wrote:
> Hi! Thanks for the patch!
> 
> LGTM.

Pushed to master, 2.6 and 2.5; changelogs are updated correspondingly;
branch is dropped.

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2020-12-23 17:07 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-12-23 10:58 [Tarantool-patches] [PATCH] sql: fix return value type of ifnull built-in Nikita Pettik
2020-12-23 15:02 ` Vladislav Shpilevoy
2020-12-23 17:07   ` Nikita Pettik

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox