[Tarantool-patches] [PATCH] sql: fix return value type of ifnull built-in

Nikita Pettik korablev at tarantool.org
Wed Dec 23 13:58:22 MSK 2020


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



More information about the Tarantool-patches mailing list