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 649586EC40; Mon, 16 Aug 2021 22:48:53 +0300 (MSK) DKIM-Filter: OpenDKIM Filter v2.11.0 dev.tarantool.org 649586EC40 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=tarantool.org; s=dev; t=1629143333; bh=z4qyw3swPxo5Gs85GydVx74Ku5/RhI3YBf2+599n60U=; h=To:Cc:References:Date:In-Reply-To:Subject:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From:Reply-To:From; b=Lsiu8SpF7DuHF0efwtUcPMgXIBBNwcXchGP7WnT53SwF42B27pE8nxIP6WPjao+mx ts88l9TNSrRl0uwaMbAO4iWZtiQ87fO6k82DQnUNcnnqQUIKv7VIj/uRxWfN2shGXU 4ikQ4YVpxAbbj6mSzaujua5fkJ1kfXIheMVSSic8= Received: from smtp56.i.mail.ru (smtp56.i.mail.ru [217.69.128.36]) (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 C09936EC40 for ; Mon, 16 Aug 2021 22:48:51 +0300 (MSK) DKIM-Filter: OpenDKIM Filter v2.11.0 dev.tarantool.org C09936EC40 Received: by smtp56.i.mail.ru with esmtpa (envelope-from ) id 1mFibK-00051Y-8T; Mon, 16 Aug 2021 22:48:50 +0300 To: imeevma@tarantool.org, korablev@tarantool.org, Serge Petrenko Cc: tarantool-patches@dev.tarantool.org References: Message-ID: <20b1ddcb-2cbc-5cad-9036-5c317c9f7c71@tarantool.org> Date: Mon, 16 Aug 2021 22:48:40 +0300 User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:78.0) Gecko/20100101 Thunderbird/78.13.0 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-US Content-Transfer-Encoding: 7bit X-7564579A: B8F34718100C35BD X-77F55803: 4F1203BC0FB41BD92087353F0EC44DD9F9A2272A1D086A28553D1D5C4B4124EF182A05F538085040D53958E4464B7B29B41941F7B757D9A91FE8E162B43FD98F56CFA309B2C9E70E X-7FA49CB5: FF5795518A3D127A4AD6D5ED66289B5278DA827A17800CE72424932217190DC2EA1F7E6F0F101C67BD4B6F7A4D31EC0BCC500DACC3FED6E28638F802B75D45FF8AA50765F79006376D321F80F15DC2F18638F802B75D45FF36EB9D2243A4F8B5A6FCA7DBDB1FC311F39EFFDF887939037866D6147AF826D8DD4A1137831A902A98036D0A17F83152117882F4460429724CE54428C33FAD305F5C1EE8F4F765FC8C7ADC89C2F0B2A5A471835C12D1D9774AD6D5ED66289B52BA9C0B312567BB23117882F446042972877693876707352033AC447995A7AD18BDFBBEFFF4125B51D2E47CDBA5A96583BA9C0B312567BB2376E601842F6C81A19E625A9149C048EE7B96B19DC4093321E21AE983DBD7FFC1D8FC6C240DEA7642DBF02ECDB25306B2B78CF848AE20165D0A6AB1C7CE11FEE3A6C7FFFE744CA7FB6E0066C2D8992A16C4224003CC836476EA7A3FFF5B025636E2021AF6380DFAD1A18204E546F3947CB11811A4A51E3B096D1867E19FE1407959CC434672EE6371089D37D7C0E48F6C8AA50765F7900637427B078F297B269AEFF80C71ABB335746BA297DBC24807EABDAD6C7F3747799A X-B7AD71C0: AC4F5C86D027EB782CDD5689AFBDA7A213B5FB47DCBC3458F0AFF96BAACF4158235E5A14AD4A4A4625E192CAD1D9E79D0B18DC6AC13D9A1C8F90619D3573E1AD X-C1DE0DAB: 0D63561A33F958A5384B41EB5578430DEF5246314552661D667E313ED619CBC0D59269BC5F550898D99A6476B3ADF6B47008B74DF8BB9EF7333BD3B22AA88B938A852937E12ACA7567C209D01CC1E34B410CA545F18667F91A7EA1CDA0B5A7A0 X-C8649E89: 4E36BF7865823D7055A7F0CF078B5EC49A30900B95165D3447DF5779098ECEE92CD5A27B85370B2B8DA9E82F726DD3B6DF60A92AA60D11403CF4756A4A8F688A1D7E09C32AA3244C37BE4861637BF005CEF1F1398E02B131F165894D92D62706927AC6DF5659F194 X-D57D3AED: 3ZO7eAau8CL7WIMRKs4sN3D3tLDjz0dLbV79QFUyzQ2Ujvy7cMT6pYYqY16iZVKkSc3dCLJ7zSJH7+u4VD18S7Vl4ZUrpaVfd2+vE6kuoey4m4VkSEu530nj6fImhcD4MUrOEAnl0W826KZ9Q+tr5ycPtXkTV4k65bRjmOUUP8cvGozZ33TWg5HZplvhhXbhDGzqmQDTd6OAevLeAnq3Ra9uf7zvY2zzsIhlcp/Y7m53TZgf2aB4JOg4gkr2biojIrFL/N5KnVF1RSFq+NZWSw== X-Mailru-Sender: B5B6A6EBBD94DAD86FFBA9D33F758965B59629D940B9C4A67F777BE53FC10FEC65AA5CEE0DD0B02F5C2808D6142752370A8ED71B308007E3DC85537438B7E1A423D748DE48713E689437F6177E88F7363CDA0F3B3F5B9367 X-Mras: Ok Subject: Re: [Tarantool-patches] [PATCH v1 4/4] sql: introduce decimal to arithmetic 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: Safin Timur via Tarantool-patches Reply-To: Safin Timur Errors-To: tarantool-patches-bounces@dev.tarantool.org Sender: "Tarantool-patches" On 16.08.2021 18:57, Mergen Imeev via Tarantool-patches wrote: > This patch introduces arithmetic for DECIMAL in SQL. After this patch, > DECIMAL values can participate in arithmetic along with INTEGER, > UNSIGNED, DOUBLE, and other DECIMAL values. > > Part of #4415 > --- > src/box/sql/mem.c | 124 +++++++++++++++++++++++++++++- > test/sql-tap/decimal.test.lua | 141 +++++++++++++++++++++++++++++++++- > 2 files changed, 262 insertions(+), 3 deletions(-) > > diff --git a/src/box/sql/mem.c b/src/box/sql/mem.c > index ff8b40d7f..a4ec98f34 100644 > --- a/src/box/sql/mem.c > +++ b/src/box/sql/mem.c > @@ -1733,6 +1733,18 @@ mem_get_int(const struct Mem *mem, int64_t *i, bool > *is_neg) > } > return -1; > } > + if (mem->type == MEM_TYPE_DEC) { > + if (decimal_is_neg(&mem->u.d)) { > + if (decimal_to_int64(&mem->u.d, i) == NULL) > + return -1; > + *is_neg = *i < 0; > + return 0; > + } > + if (decimal_to_uint64(&mem->u.d, (uint64_t *)i) == NULL) > + return -1; > + *is_neg = false; > + return 0; > + } > return -1; > } > > @@ -1760,6 +1772,19 @@ mem_get_uint(const struct Mem *mem, uint64_t *u) > } > return -1; > } > + if (mem->type == MEM_TYPE_DEC) { > + if (decimal_is_neg(&mem->u.d)) { > + int64_t i; > + if (decimal_to_int64(&mem->u.d, &i) == NULL || i < > 0) > + return -1; > + assert(i == 0); > + *u = 0; > + return 0; > + } > + if (decimal_to_uint64(&mem->u.d, u) == NULL) > + return -1; > + return 0; > + } > return -1; > } > > @@ -1778,6 +1803,10 @@ mem_get_double(const struct Mem *mem, double *d) > *d = (double)mem->u.u; > return 0; > } > + if (mem->type == MEM_TYPE_DEC) { > + *d = atof(decimal_str(&mem->u.d)); > + return 0; > + } 1st question is - was it intentionally that you call here atof, while few lines belowe we use sqlAtoF? 2nd complain is - it all looks that we miss decimal_to_double() function in src/core/decimal.c (where we do have decimal_from_double() but not the reverse direction). It will look more consistent if this implementation would be there. And, I stll believe, there is better way for converting decimal to double, than converting it to string, and then to double. [Though quick navigation over decNumber API didn't reveal the direct approach. Serge, could you please recommend the easiest way here?] > @@ -1946,12 +2003,12 @@ mem_concat(struct Mem *a, struct Mem *b, struct > Mem *result) > static inline int > check_types_numeric_arithmetic(const struct Mem *a, const struct Mem *b) > { > - if (!mem_is_num(a) || mem_is_metatype(a) || a->type == > MEM_TYPE_DEC) { > + if (!mem_is_num(a) || mem_is_metatype(a)) { And now it looks better than before, and less confusing, I do not have complains here anymore... > diag_set(ClientError, ER_SQL_TYPE_MISMATCH, mem_str(a), > "integer, unsigned or double"); > return -1; > } > - if (!mem_is_num(b) || mem_is_metatype(b) || b->type == > MEM_TYPE_DEC) { > + if (!mem_is_num(b) || mem_is_metatype(b)) { And here. > diag_set(ClientError, ER_SQL_TYPE_MISMATCH, mem_str(b), > "integer, unsigned or double"); > return -1; Thanks, Timur