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 76D036EC40; Thu, 23 Sep 2021 01:49:01 +0300 (MSK) DKIM-Filter: OpenDKIM Filter v2.11.0 dev.tarantool.org 76D036EC40 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=tarantool.org; s=dev; t=1632350941; bh=5iaVmYat6jU1rtA/CbQTppImhhg7sIBqrV47GBzNMGk=; 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=uiFG2XvSlxcbcWTi/iWmvsJgNH+v/9WYLUx0hu2lPNK/cm3RDmmCjHEaVwFeLAWNV m6Qdf5QJdZdQXnktZSGrpKwbrulVoldn6JEdhE4erRtDtQmcKcYme6pPeRNH8f9mMw 5ySqZr0ZVx3PEm9CM3Ra6sjZU6cesiWpCx62gtYU= 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 14F546EC40 for ; Thu, 23 Sep 2021 01:49:00 +0300 (MSK) DKIM-Filter: OpenDKIM Filter v2.11.0 dev.tarantool.org 14F546EC40 Received: by smtpng1.m.smailru.net with esmtpa (envelope-from ) id 1mTB2x-0004oN-BC; Thu, 23 Sep 2021 01:48:59 +0300 To: imeevma@tarantool.org Cc: tarantool-patches@dev.tarantool.org References: <48ee23c47c696c5e002347841b652677ca877507.1632220375.git.imeevma@gmail.com> Message-ID: <62bdd807-6f60-4307-1ed8-0badb6c014ae@tarantool.org> Date: Thu, 23 Sep 2021 00:48:58 +0200 User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:78.0) Gecko/20100101 Thunderbird/78.14.0 MIME-Version: 1.0 In-Reply-To: <48ee23c47c696c5e002347841b652677ca877507.1632220375.git.imeevma@gmail.com> Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 8bit X-7564579A: B8F34718100C35BD X-77F55803: 4F1203BC0FB41BD91AE02D33A9C88A2FBA0FFC16CEFBFC694531AE86BFF036DF00894C459B0CD1B9B3E7A97135C7D85BECA3203CFB4729BBDC443D2BA0B873E52059E94B53F79380 X-7FA49CB5: FF5795518A3D127A4AD6D5ED66289B5278DA827A17800CE79B4AFF82F0254274EA1F7E6F0F101C67BD4B6F7A4D31EC0BCC500DACC3FED6E28638F802B75D45FF8AA50765F79006370BACBAB4C30C4AEB8638F802B75D45FF36EB9D2243A4F8B5A6FCA7DBDB1FC311F39EFFDF887939037866D6147AF826D880D6892EB79BFF26E191106BA56CD26C117882F4460429724CE54428C33FAD305F5C1EE8F4F765FC8C7ADC89C2F0B2A5A471835C12D1D9774AD6D5ED66289B52BA9C0B312567BB23117882F44604297287769387670735201E561CDFBCA1751F2CC0D3CB04F14752D2E47CDBA5A96583BA9C0B312567BB231DD303D21008E29813377AFFFEAFD269A417C69337E82CC2E827F84554CEF50127C277FBC8AE2E8BA83251EDC214901ED5E8D9A59859A8B613439FA09F3DCB32089D37D7C0E48F6C5571747095F342E88FB05168BE4CE3AF X-C1DE0DAB: 0D63561A33F958A5CC90BE531B6F430D38AEF322CB0E5FD5EF066B33D025E0BAD59269BC5F550898D99A6476B3ADF6B47008B74DF8BB9EF7333BD3B22AA88B938A852937E12ACA759D2A03B9C34326B3410CA545F18667F91A7EA1CDA0B5A7A0 X-C8649E89: 4E36BF7865823D7055A7F0CF078B5EC49A30900B95165D345CB6DE26F165466765F534C8C664FC636907B8A2137E87A2AF7F673548FAFA1F3CAFAB631EDD49771D7E09C32AA3244C89340017D96FFFA441F453A6A37B3F5595A9E0DC41E9A4CF729B2BEF169E0186 X-D57D3AED: 3ZO7eAau8CL7WIMRKs4sN3D3tLDjz0dLbV79QFUyzQ2Ujvy7cMT6pYYqY16iZVKkSc3dCLJ7zSJH7+u4VD18S7Vl4ZUrpaVfd2+vE6kuoey4m4VkSEu530nj6fImhcD4MUrOEAnl0W826KZ9Q+tr5ycPtXkTV4k65bRjmOUUP8cvGozZ33TWg5HZplvhhXbhDGzqmQDTd6OAevLeAnq3Ra9uf7zvY2zzsIhlcp/Y7m53TZgf2aB4JOg4gkr2biojYVPXnTWjYf5sfedVTAh4xg== X-Mailru-Sender: 689FA8AB762F7393C37E3C1AEC41BA5DFAEF6F8A24A159372BA582E3E6C10C5E3841015FED1DE5223CC9A89AB576DD93FB559BB5D741EB963CF37A108A312F5C27E8A8C3839CE0E267EA787935ED9F1B X-Mras: Ok Subject: Re: [Tarantool-patches] [PATCH v2 09/15] sql: rework AVG() 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: Vladislav Shpilevoy via Tarantool-patches Reply-To: Vladislav Shpilevoy Errors-To: tarantool-patches-bounces@dev.tarantool.org Sender: "Tarantool-patches" Thanks for the fixes! > diff --git a/src/box/sql/func.c b/src/box/sql/func.c > index 12a6a5a2c..b5f154fb1 100644 > --- a/src/box/sql/func.c > +++ b/src/box/sql/func.c > @@ -102,6 +102,54 @@ fin_total(struct sql_context *ctx) > mem_copy_as_ephemeral(ctx->pOut, ctx->pMem); > } > > +/** Implementation of the AVG() function. */ > +static void > +step_avg(struct sql_context *ctx, int argc, struct Mem **argv) > +{ > + assert(argc == 1); > + (void)argc; > + assert(ctx->pMem->type == MEM_TYPE_NULL || mem_is_bin(ctx->pMem)); > + if (argv[0]->type == MEM_TYPE_NULL) > + return; > + struct Mem *mem; > + uint32_t *count; > + if (ctx->pMem->type == MEM_TYPE_NULL) { > + uint32_t size = sizeof(struct Mem) + sizeof(uint32_t); > + mem = sqlDbMallocRawNN(sql_get(), size); 1. Where is it deleted? Can't find. > + if (mem == NULL) { > + ctx->is_aborted = true; > + return; > + } > + count = (uint32_t *)(mem + 1); > + mem_create(mem); > + *count = 1; > + mem_copy_as_ephemeral(mem, argv[0]); > + mem_set_bin_allocated(ctx->pMem, (char *)mem, size); > + return; > + } > diff --git a/test/sql-tap/built-in-functions.test.lua b/test/sql-tap/built-in-functions.test.lua > index 507d06549..08a63b86d 100755 > --- a/test/sql-tap/built-in-functions.test.lua > +++ b/test/sql-tap/built-in-functions.test.lua > @@ -605,4 +605,33 @@ test:do_execsql_test( > } > ) > > +-- Make sure AVG() accepts and returns DOUBLE by default. > +test:do_test( > + "builtins-4.1.1", > + function() > + return box.execute([[SELECT AVG(?);]], {1}).metadata > + end, { > + {name = "COLUMN_1", type = "double"}, > + }) > + > +test:do_test( > + "builtins-4.1.2", > + function() > + local res = {pcall(box.execute, [[SELECT AVG(?);]], {-1ULL})} > + return {tostring(res[3])} > + end, { > + "Type mismatch: can not convert integer(18446744073709551615) to double" > + }) > + > +-- Make sure AVG() works with DECIMAL properly. > +test:do_execsql_test( > + "builtins-4.1.3", > + [[ > + SELECT AVG(cast(column_2 as DECIMAL)) from (values(1), (123.432)); 2. I don't understand how does it work. Why not column_1? Why does it fail? tarantool> box.execute('SELECT column_1 from (values(1), (123.432));') --- - null - Can’t resolve field 'COLUMN_1' ... Isn't there 2 tuples [1], and [123.432] with just 1 column each? And why does it work when I delete one of the values? tarantool> box.execute('SELECT column_1 from (values(1));') --- - metadata: - name: COLUMN_1 type: integer rows: - [1] ... > + ]], > + { > + dec.new(62.216) > + } > +) > + > test:finish_test() >