From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from smtpng1.m.smailru.net (smtpng1.m.smailru.net [94.100.181.251]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dev.tarantool.org (Postfix) with ESMTPS id 31B714765E0 for ; Wed, 23 Dec 2020 13:58:25 +0300 (MSK) From: Nikita Pettik Date: Wed, 23 Dec 2020 13:58:22 +0300 Message-Id: <20201223105822.4748-1-korablev@tarantool.org> Subject: [Tarantool-patches] [PATCH] sql: fix return value type of ifnull built-in List-Id: Tarantool development patches List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: tarantool-patches@dev.tarantool.org Cc: v.shpilevoy@tarantool.org 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