From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from [87.239.111.99] (localhost [127.0.0.1]) by dev.tarantool.org (Postfix) with ESMTP id 436F96F3E5; Thu, 11 Nov 2021 13:47:29 +0300 (MSK) DKIM-Filter: OpenDKIM Filter v2.11.0 dev.tarantool.org 436F96F3E5 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=tarantool.org; s=dev; t=1636627649; bh=4LUxgQcLWU8fMoGT/O9W3ZTUbWpKsq3Q7rm+zFgZSVY=; h=To:Cc:Date:In-Reply-To:References:Subject:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From:Reply-To:From; b=xKyaLfFcTnrpFe4VkEckLY2nw3IrbuSE3WWUQhd/VjHATuPtzLIkmm0iiwjSwzHX6 F6j/kbp9XjXnC3f/nxr9aciYmkfCCQ2pMH0HcllvS4Hkhx8o5zazDF+paBgAgXv4Pd VLF1hDwdoSDs7+jCEHfLcaOaWLhS6YrhPSv337ds= Received: from smtpng1.i.mail.ru (smtpng1.i.mail.ru [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 DDEC970296 for ; Thu, 11 Nov 2021 13:45:31 +0300 (MSK) DKIM-Filter: OpenDKIM Filter v2.11.0 dev.tarantool.org DDEC970296 Received: by smtpng1.m.smailru.net with esmtpa (envelope-from ) id 1ml7aE-0002yb-W7; Thu, 11 Nov 2021 13:45:31 +0300 To: kyukhin@tarantool.org Cc: tarantool-patches@dev.tarantool.org Date: Thu, 11 Nov 2021 13:45:30 +0300 Message-Id: X-Mailer: git-send-email 2.25.1 In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-4EC0790: 10 X-7564579A: B8F34718100C35BD X-77F55803: 4F1203BC0FB41BD9731B3922EC063979A442978D427656AE2233A9C8B25E6BF500894C459B0CD1B97B08D93702511917A426C4E22A85851FBD7B9CED87D25567A02D50AE20F21E99 X-7FA49CB5: FF5795518A3D127A4AD6D5ED66289B5278DA827A17800CE74B51810D54EC17F0C2099A533E45F2D0395957E7521B51C2CFCAF695D4D8E9FCEA1F7E6F0F101C6778DA827A17800CE7B7733D0215A2F71AEA1F7E6F0F101C6723150C8DA25C47586E58E00D9D99D84E1BDDB23E98D2D38BBCA57AF85F7723F24C2A4101CFBD33FA657DE04D0338B167CC7F00164DA146DAFE8445B8C89999728AA50765F7900637F924B32C592EA89F389733CBF5DBD5E9C8A9BA7A39EFB766F5D81C698A659EA7CC7F00164DA146DA9985D098DBDEAEC8ED96AA85C75E140D117882F4460429728AD0CFFFB425014E868A13BD56FB6657E2021AF6380DFAD1A18204E546F3947CB11811A4A51E3B096D1867E19FE1407959CC434672EE6371089D37D7C0E48F6C8AA50765F7900637AF8E4F18C523FAA9EFF80C71ABB335746BA297DBC24807EABDAD6C7F3747799A X-C1DE0DAB: C20DE7B7AB408E4181F030C43753B8186998911F362727C414F749A5E30D975C7E9FEBB9C11794A195E9E1320EE8D9422A6F49D26FF046129C2B6934AE262D3EE7EAB7254005DCED7532B743992DF240BDC6A1CF3F042BAD6DF99611D93F60EF309DFB797F6729CB699F904B3F4130E343918A1A30D5E7FCCB5012B2E24CD356 X-C8649E89: 4E36BF7865823D7055A7F0CF078B5EC49A30900B95165D34C786159FDC4342B0AD2296EC554A0361C21D979C542515A35F76A64DEC1D44CACA3F33A9F52ED4E81D7E09C32AA3244C621DE253AEAB507E5AE5804EC34E92E5F94338140B71B8EE729B2BEF169E0186 X-D57D3AED: 3ZO7eAau8CL7WIMRKs4sN3D3tLDjz0dLbV79QFUyzQ2Ujvy7cMT6pYYqY16iZVKkSc3dCLJ7zSJH7+u4VD18S7Vl4ZUrpaVfd2+vE6kuoey4m4VkSEu530nj6fImhcD4MUrOEAnl0W826KZ9Q+tr5ycPtXkTV4k65bRjmOUUP8cvGozZ33TWg5HZplvhhXbhDGzqmQDTd6OAevLeAnq3Ra9uf7zvY2zzsIhlcp/Y7m53TZgf2aB4JOg4gkr2bioj4t8MBgWr8bL3kRZKyIt9gQ== X-Mailru-Sender: 689FA8AB762F7393C37E3C1AEC41BA5D5B4A8A2D90716B4770F89777D86C61B383D72C36FC87018B9F80AB2734326CD2FB559BB5D741EB96352A0ABBE4FDA4210A04DAD6CC59E33667EA787935ED9F1B X-Mras: Ok Subject: [Tarantool-patches] [PATCH v1 4/8] sql: refactor NULLIF() function X-BeenThere: tarantool-patches@dev.tarantool.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: Tarantool development patches List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , From: Mergen Imeev via Tarantool-patches Reply-To: imeevma@tarantool.org Errors-To: tarantool-patches-bounces@dev.tarantool.org Sender: "Tarantool-patches" 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