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 F30936EC40; Wed, 18 Aug 2021 22:04:36 +0300 (MSK) DKIM-Filter: OpenDKIM Filter v2.11.0 dev.tarantool.org F30936EC40 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=tarantool.org; s=dev; t=1629313477; bh=LvguD1n5O4MgIv88fulEaTt0wU+jL2u9o1Vrmx0UIIA=; h=Date:To:Cc:References:In-Reply-To:Subject:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From:Reply-To:From; b=B4NyeoeczMBm9vGFEBfa5Jo3XACd8R99rendlMThfhtRPGVWOE+wYQGCsn2f0HX0g GTqbG+ZRCk/tTBJma1sMLb3ywLq3QwVRZD43YG3mGuQtO9lO1n3SY2R9Qx6KRXLoM6 6uR1J5ytEO2nBKjTM7wcgmkkBQCv9gzRjXS02VZA= Received: from smtpng2.i.mail.ru (smtpng2.i.mail.ru [94.100.179.3]) (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 B70B36EC40 for ; Wed, 18 Aug 2021 22:04:34 +0300 (MSK) DKIM-Filter: OpenDKIM Filter v2.11.0 dev.tarantool.org B70B36EC40 Received: by smtpng2.m.smailru.net with esmtpa (envelope-from ) id 1mGQrZ-0000Bm-SU; Wed, 18 Aug 2021 22:04:34 +0300 Date: Wed, 18 Aug 2021 22:04:32 +0300 To: Igor Munkin Cc: tarantool-patches@dev.tarantool.org Message-ID: <20210818190432.GA696969@tarantool.org> References: <20210818171840.GG5743@tarantool.org> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline In-Reply-To: <20210818171840.GG5743@tarantool.org> X-4EC0790: 10 X-7564579A: 646B95376F6C166E X-77F55803: 4F1203BC0FB41BD92087353F0EC44DD9BCE6B93DE0C6C3914462CDB1732D383C182A05F538085040C86DF3CF7FA6B758B7C429BCE5F1ED43DC6058DEB0F8CEA925BE0042709333D3 X-7FA49CB5: FF5795518A3D127A4AD6D5ED66289B5278DA827A17800CE7195F30236A8D43B4EA1F7E6F0F101C67BD4B6F7A4D31EC0BCC500DACC3FED6E28638F802B75D45FF8AA50765F7900637E78B284398E2029E8638F802B75D45FF36EB9D2243A4F8B5A6FCA7DBDB1FC311F39EFFDF887939037866D6147AF826D8BFA7F133AA9D9611A9A36258FC9F00D1117882F4460429724CE54428C33FAD305F5C1EE8F4F765FCAA867293B0326636D2E47CDBA5A96583BD4B6F7A4D31EC0BC014FD901B82EE079FA2833FD35BB23D27C277FBC8AE2E8BAA867293B0326636D2E47CDBA5A96583BA9C0B312567BB231DD303D21008E29813377AFFFEAFD269A417C69337E82CC2E827F84554CEF50127C277FBC8AE2E8BA83251EDC214901ED5E8D9A59859A8B6B1CFA6D474D4A6A4089D37D7C0E48F6C5571747095F342E88FB05168BE4CE3AF X-B7AD71C0: AC4F5C86D027EB782CDD5689AFBDA7A213B5FB47DCBC3458834459D11680B50582EBDAF850E8044814A0593921188723 X-C1DE0DAB: 0D63561A33F958A578759B33E295A86FAC57F439C2F86402B56A67195B1861A3D59269BC5F550898D99A6476B3ADF6B47008B74DF8BB9EF7333BD3B22AA88B938A852937E12ACA75C29D03FC76C37677410CA545F18667F91A7EA1CDA0B5A7A0 X-C8649E89: 4E36BF7865823D7055A7F0CF078B5EC49A30900B95165D34D1AE09A115117C96F572A93562E1000EAECEA9A78A2E440F6A96F3B059C392FA7FD5462689ED6FC01D7E09C32AA3244C649CF83283D3B2329B27AB87828107EF408A6A02710B7304729B2BEF169E0186 X-D57D3AED: 3ZO7eAau8CL7WIMRKs4sN3D3tLDjz0dLbV79QFUyzQ2Ujvy7cMT6pYYqY16iZVKkSc3dCLJ7zSJH7+u4VD18S7Vl4ZUrpaVfd2+vE6kuoey4m4VkSEu530nj6fImhcD4MUrOEAnl0W826KZ9Q+tr5ycPtXkTV4k65bRjmOUUP8cvGozZ33TWg5HZplvhhXbhDGzqmQDTd6OAevLeAnq3Ra9uf7zvY2zzsIhlcp/Y7m53TZgf2aB4JOg4gkr2biojGSxK+6r6oBHKlneV5B4+jg== X-Mailru-Sender: 689FA8AB762F7393C37E3C1AEC41BA5D309CE7AAB7F74CD3F3C55959041F757A83D72C36FC87018B9F80AB2734326CD2FB559BB5D741EB96352A0ABBE4FDA4210A04DAD6CC59E33667EA787935ED9F1B X-Mras: Ok Subject: Re: [Tarantool-patches] [PATCH v1 1/1] sql: fix quote() 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: Mergen Imeev Errors-To: tarantool-patches-bounces@dev.tarantool.org Sender: "Tarantool-patches" Hi! Thank you for the review! My answers and new patch below. I did not include diff, since most of changes were in commit-message and there were only couple changes lines in the test. On Wed, Aug 18, 2021 at 08:18:40PM +0300, Igor Munkin wrote: > Mergen, > > Thanks for the patch! Please consider minor comments below. > > On 17.08.21, imeevma@tarantool.org wrote: > > Ater this patch SQL built-in function QUOTE() will return the same > > DOUBLE in case it receives DOUBLE as an argument. If the argument is > > Minor: it's better to say QUOTE() returns the argument in case DOUBLE > value is given. Since we're here: do we need a docbot request for this? > Fixed. Added a docbot request. > > not number, string representation of the argument will be returned. > > > > Closes #6239 > > --- > > https://github.com/tarantool/tarantool/issues/6239 > > https://github.com/tarantool/tarantool/tree/imeevma/gh-6239-quote-with-double-arg > > > > src/box/sql/func.c | 15 +-------------- > > test/sql-tap/engine.cfg | 3 +++ > > .../gh-6239-quote-with-double-arg.test.lua | 14 ++++++++++++++ > > test/sql-tap/trigger5.test.lua | 3 ++- > > test/sql/types.result | 8 ++++---- > > 5 files changed, 24 insertions(+), 19 deletions(-) > > create mode 100755 test/sql-tap/gh-6239-quote-with-double-arg.test.lua > > > > > > > diff --git a/test/sql-tap/gh-6239-quote-with-double-arg.test.lua b/test/sql-tap/gh-6239-quote-with-double-arg.test.lua > > new file mode 100755 > > index 000000000..60f85f20f > > --- /dev/null > > +++ b/test/sql-tap/gh-6239-quote-with-double-arg.test.lua > > @@ -0,0 +1,14 @@ > > +#!/usr/bin/env tarantool > > +local test = require("sqltester") > > +test:plan(1) > > + > > +-- Make sure that QUOTE() returns DOUBLE in cast it receives DOUBLE. > > +test:do_execsql_test( > > + "gh-6239", > > + [[ > > + SELECT QUOTE(1.5); > > + ]], { > > + 1.5 > > Do we need to check QUOTE preserves the type of the argument? > Added check with typeof. I see no sense to add check with metadata, since there we will see "string". It will be fixed in patch-set about SQL built-in functions. > > + }) > > + > > +test:finish_test() > > diff --git a/test/sql-tap/trigger5.test.lua b/test/sql-tap/trigger5.test.lua > > index 8336cdcf2..7f3762126 100755 > > --- a/test/sql-tap/trigger5.test.lua > > +++ b/test/sql-tap/trigger5.test.lua > > @@ -31,7 +31,8 @@ test:do_execsql_test( > > INSERT INTO Undo VALUES > > ((SELECT coalesce(max(id),0) + 1 FROM Undo), > > (SELECT 'INSERT INTO Item (a,b,c) VALUES (' || CAST(coalesce(old.a,'NULL') AS TEXT) > > - || ',' || quote(old.b) || ',' || CAST(old.c AS TEXT) || ');')); > > + || ',' || CAST(quote(old.b) AS STRING) || ',' || > > + CAST(old.c AS TEXT) || ');')); > > [Hm. Expecting nothing is completely broken, since test results are not > changed.] > > > END; > > DELETE FROM Item WHERE a = 1; > > SELECT * FROM Undo; > > diff --git a/test/sql/types.result b/test/sql/types.result > > index 07d5b46e4..358667e94 100644 > > --- a/test/sql/types.result > > +++ b/test/sql/types.result > > @@ -1908,10 +1908,10 @@ box.execute("SELECT quote(d) FROM t;") > > - name: COLUMN_1 > > type: string > > rows: > > - - ['10.0'] > > - - ['-2.0'] > > - - ['3.3'] > > - - ['1.8e+19'] > > + - [10] > > + - [-2] > > + - [3.3] > > Fraction is dropped by YAML serializer, right? > Yes. > > + - [18000000000000000000] > > ... > > box.execute("SELECT LEAST(d, 0) FROM t;") > > --- > > -- > > 2.25.1 > > > > -- > Best regards, > IM New patch: commit 2e2d979c53be8d9f97071d3003e1069fc8c078cf Author: Mergen Imeev Date: Fri Aug 13 05:50:06 2021 +0300 sql: fix quote() function Ater this patch SQL built-in function QUOTE() will return argument in case DOUBLE values is given. If the argument is not number, string representation of the argument will be returned. Closes #6239 @TarantoolBot document Title: QUOTE() and DOUBLE argument After this patch function QUOTE() will return argument in case it receives DOUBLE value as an argument. The same for all other numeric types. In case it was given value of non-numeric type, it will return string representation of the argument. diff --git a/src/box/sql/func.c b/src/box/sql/func.c index 1551d3ef2..3da608c0b 100644 --- a/src/box/sql/func.c +++ b/src/box/sql/func.c @@ -1091,26 +1091,13 @@ quoteFunc(sql_context * context, int argc, sql_value ** argv) assert(argc == 1); UNUSED_PARAMETER(argc); switch (argv[0]->type) { - case MEM_TYPE_DOUBLE:{ - double r1, r2; - char zBuf[50]; - r1 = mem_get_double_unsafe(argv[0]); - sql_snprintf(sizeof(zBuf), zBuf, "%!.15g", r1); - sqlAtoF(zBuf, &r2, 20); - if (r1 != r2) { - sql_snprintf(sizeof(zBuf), zBuf, "%!.20e", - r1); - } - sql_result_text(context, zBuf, -1, - SQL_TRANSIENT); - break; - } case MEM_TYPE_UUID: { char buf[UUID_STR_LEN + 1]; tt_uuid_to_string(&argv[0]->u.uuid, &buf[0]); sql_result_text(context, buf, UUID_STR_LEN, SQL_TRANSIENT); break; } + case MEM_TYPE_DOUBLE: case MEM_TYPE_UINT: case MEM_TYPE_INT: { sql_result_value(context, argv[0]); diff --git a/test/sql-tap/engine.cfg b/test/sql-tap/engine.cfg index 820c72b00..5799780dc 100644 --- a/test/sql-tap/engine.cfg +++ b/test/sql-tap/engine.cfg @@ -26,6 +26,9 @@ "metatypes.test.lua": { "memtx": {"engine": "memtx"} }, + "gh-6239-quote-with-double-arg.test.lua": { + "memtx": {"engine": "memtx"} + }, "gh-4077-iproto-execute-no-bind.test.lua": {}, "*": { "memtx": {"engine": "memtx"}, diff --git a/test/sql-tap/gh-6239-quote-with-double-arg.test.lua b/test/sql-tap/gh-6239-quote-with-double-arg.test.lua new file mode 100755 index 000000000..dab12253e --- /dev/null +++ b/test/sql-tap/gh-6239-quote-with-double-arg.test.lua @@ -0,0 +1,14 @@ +#!/usr/bin/env tarantool +local test = require("sqltester") +test:plan(1) + +-- Make sure that QUOTE() returns DOUBLE in cast it receives DOUBLE. +test:do_execsql_test( + "gh-6239", + [[ + SELECT QUOTE(1.5), TYPEOF(QUOTE(1.5)); + ]], { + 1.5, "double" + }) + +test:finish_test() diff --git a/test/sql-tap/trigger5.test.lua b/test/sql-tap/trigger5.test.lua index 8336cdcf2..7f3762126 100755 --- a/test/sql-tap/trigger5.test.lua +++ b/test/sql-tap/trigger5.test.lua @@ -31,7 +31,8 @@ test:do_execsql_test( INSERT INTO Undo VALUES ((SELECT coalesce(max(id),0) + 1 FROM Undo), (SELECT 'INSERT INTO Item (a,b,c) VALUES (' || CAST(coalesce(old.a,'NULL') AS TEXT) - || ',' || quote(old.b) || ',' || CAST(old.c AS TEXT) || ');')); + || ',' || CAST(quote(old.b) AS STRING) || ',' || + CAST(old.c AS TEXT) || ');')); END; DELETE FROM Item WHERE a = 1; SELECT * FROM Undo; diff --git a/test/sql/types.result b/test/sql/types.result index 68bdcd62e..fa78e8d9a 100644 --- a/test/sql/types.result +++ b/test/sql/types.result @@ -1909,10 +1909,10 @@ box.execute("SELECT quote(d) FROM t;") - name: COLUMN_1 type: string rows: - - ['10.0'] - - ['-2.0'] - - ['3.3'] - - ['1.8e+19'] + - [10] + - [-2] + - [3.3] + - [18000000000000000000] ... box.execute("SELECT LEAST(d, 0) FROM t;") ---