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 EA9456F852; Sun, 14 Nov 2021 19:12:06 +0300 (MSK) DKIM-Filter: OpenDKIM Filter v2.11.0 dev.tarantool.org EA9456F852 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=tarantool.org; s=dev; t=1636906327; bh=0LjlUOQwW9afr1k+ygXnPDT+t7XSyuHKHB+6HpwZ1TU=; 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=jkUYAZNaopv8qeTZ7L0kv0W+heN+7a1E//3Y7GovCMUqqflTIFfKun7QbftMWRGCw ns+a8FOLzkMrhgHY1GXvTdC8B/ALukUwK5Yw/C/CwFBnIxVWmA40jK1pDsWksWvYkb owdObXcDsR8/vrH6Hwnn5l74LX8jbMwx1FQiae3o= Received: from smtp30.i.mail.ru (smtp30.i.mail.ru [94.100.177.90]) (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 6168E6F852 for ; Sun, 14 Nov 2021 19:12:05 +0300 (MSK) DKIM-Filter: OpenDKIM Filter v2.11.0 dev.tarantool.org 6168E6F852 Received: by smtp30.i.mail.ru with esmtpa (envelope-from ) id 1mmI6u-0003ig-MV; Sun, 14 Nov 2021 19:12:05 +0300 Message-ID: <7c124335-9796-90a4-9c2f-8bf3bfab353a@tarantool.org> Date: Sun, 14 Nov 2021 17:12:03 +0100 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:91.0) Gecko/20100101 Thunderbird/91.3.0 Content-Language: en-US To: imeevma@tarantool.org Cc: tarantool-patches@dev.tarantool.org References: <8a954f84706769e4d685cedac987c2de8eb947cc.1635927295.git.imeevma@gmail.com> In-Reply-To: <8a954f84706769e4d685cedac987c2de8eb947cc.1635927295.git.imeevma@gmail.com> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit X-4EC0790: 10 X-7564579A: B8F34718100C35BD X-77F55803: 4F1203BC0FB41BD9731B3922EC063979787B19701143D42A39EF849E3128968B00894C459B0CD1B9FD57E67FE42A9BB4A519266366751B00BC2B2DCED945EF36F14F8599D8FED5CC X-7FA49CB5: FF5795518A3D127A4AD6D5ED66289B5278DA827A17800CE7C2204D4F9A221771EA1F7E6F0F101C67BD4B6F7A4D31EC0BCC500DACC3FED6E28638F802B75D45FF8AA50765F79006370218B86C916BF3528638F802B75D45FF36EB9D2243A4F8B5A6FCA7DBDB1FC311F39EFFDF887939037866D6147AF826D81BEAC2453D80C670915718EE02F50863117882F4460429724CE54428C33FAD305F5C1EE8F4F765FC2EE5AD8F952D28FBA471835C12D1D9774AD6D5ED66289B52BA9C0B312567BB23117882F446042972877693876707352033AC447995A7AD18CB629EEF1311BF91D2E47CDBA5A96583BA9C0B312567BB2376E601842F6C81A19E625A9149C048EE7B96B19DC4093321436E4CC186B5AB2DD8FC6C240DEA7642DBF02ECDB25306B2B78CF848AE20165D0A6AB1C7CE11FEE35DA91C8160F4BAA06136E347CC761E07C4224003CC836476EA7A3FFF5B025636E2021AF6380DFAD1A18204E546F3947CB11811A4A51E3B096D1867E19FE1407959CC434672EE6371089D37D7C0E48F6C8AA50765F79006373BC478629CBEC79DEFF80C71ABB335746BA297DBC24807EABDAD6C7F3747799A X-B7AD71C0: AC4F5C86D027EB78D6D0BB59C9AE7EFFE8F7B195E1C978319154D11B1C23FE46F4AFB5C2C7CD4746 X-C1DE0DAB: 0D63561A33F958A501CAE06C3EFA3BC7EBF650FE7D8674A1CA524D1384E1262CD59269BC5F550898D99A6476B3ADF6B47008B74DF8BB9EF7333BD3B22AA88B938A852937E12ACA7536C62C4FBC402878410CA545F18667F91A7EA1CDA0B5A7A0 X-C8649E89: 4E36BF7865823D7055A7F0CF078B5EC49A30900B95165D349320586B19AD2C72C42A53609F96A25F78FAAF66C6D6C83BEC0066890C30CD56DB527A06E8B61E511D7E09C32AA3244C875ED07C7E40179917B99362C457E6FAF2F5F14F68F1805B729B2BEF169E0186 X-D57D3AED: 3ZO7eAau8CL7WIMRKs4sN3D3tLDjz0dLbV79QFUyzQ2Ujvy7cMT6pYYqY16iZVKkSc3dCLJ7zSJH7+u4VD18S7Vl4ZUrpaVfd2+vE6kuoey4m4VkSEu530nj6fImhcD4MUrOEAnl0W826KZ9Q+tr5ycPtXkTV4k65bRjmOUUP8cvGozZ33TWg5HZplvhhXbhDGzqmQDTd6OAevLeAnq3Ra9uf7zvY2zzsIhlcp/Y7m53TZgf2aB4JOg4gkr2biojjLiSo6osCe4sMS8ZHEoaTA== X-Mailru-Sender: 1F3202E75A95DDEFFDAA31DDF78A2BDFDC4309A528193C6139F2F2B3BFBCD8E787B591FBD0C59A18841FB911095AA09146E8006E22572C39C920B61C43410E8717BDA556287159EE9437F6177E88F7363CDA0F3B3F5B9367 X-Mras: Ok Subject: Re: [Tarantool-patches] [PATCH v1 1/2] sql: introduce field type ARRAY 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" Hi! Thanks for the patch! See 4 comments below. On 03.11.2021 09:17, Mergen Imeev via Tarantool-patches wrote: > This patch introduces ARRAY to SQL. After this patch, all SQL operations > and built-in functions should work correctly with ARRAY values. However, > there is currently no way to create ARRAY values using only SQL tools. > > Part of #4762 > > @TarantoolBot document > Title: Field type ARRAY in SQL > > Properties of type ARRAY in SQL: > 1) a value ofttype ARRAY can be implicitly and explicitly cast only 1. ofttype -> of type. > to ANY; > 2) only a value of type ANY with primitive type ARRAY can be explicitly > cast to ARRAY; > 3) a value of any other type cannot be implicitly cast to ARRAY; > 4) a value of type ARRAY cannot participate in arithmetic, bitwise, > comparison, and concationation operations. 2. concationation -> concatenation. > diff --git a/src/box/sql/mem.c b/src/box/sql/mem.c > index 244415e02..c84bbe8fe 100644 > --- a/src/box/sql/mem.c > +++ b/src/box/sql/mem.c > @@ -3243,9 +3244,20 @@ port_vdbemem_dump_lua(struct port *base, struct lua_State *L, bool is_flat) > case MEM_TYPE_STR: > case MEM_TYPE_BIN: > case MEM_TYPE_MAP: > - case MEM_TYPE_ARRAY: > lua_pushlstring(L, mem->z, mem->n); > break; > + case MEM_TYPE_ARRAY: { > + const char *data = mem->z; > + uint32_t size = mp_decode_array(&data); > + lua_createtable(L, size, 0); > + for (uint32_t i = 0; i < size; i++) { > + luamp_decode(L, luaL_msgpack_default, &data); > + lua_rawseti(L, -2, i + 1); > + } > + if (luaL_msgpack_default->decode_save_metatables) > + luaL_setarrayhint(L, -1); 3. Why didn't you call luamp_decode() on the root? It does exactly the same for arrays. I wouldn't mind if not the last 2 lines: if we ever add more format options for arrays, we will forget to patch this place for sure. > diff --git a/test/sql-tap/array.test.lua b/test/sql-tap/array.test.lua > new file mode 100755 > index 000000000..2c0f687c0 > --- /dev/null > +++ b/test/sql-tap/array.test.lua > @@ -0,0 +1,985 @@ <...> > +-- Make sure it is possible to update ARRAY field. > +test:do_execsql_test( > + "array-5", > + [[ > + UPDATE t SET a = a1(123) WHERE i = 3; > + SELECT i, a FROM t; > + ]], { > + 3, 123, > + 4, 4, 5, 6, > + }) > + > +-- Make sure ARRAY can only be explicitly cast to ANY and STRING. 4. But in 6.3 test the STRING cast raises an error. > +test:do_execsql_test( > + "array-6.1", > + [[ > + SELECT CAST(a AS ANY) FROM t; > + ]], { > + 123, > + 4, 5, 6, > + }) > + > +test:do_catchsql_test( > + "array-6.2", > + [[ > + SELECT CAST(a AS UNSIGNED) FROM t; > + ]], { > + 1, "Type mismatch: can not convert array([123]) to unsigned" > + }) > + > +test:do_catchsql_test( > + "array-6.3", > + [[ > + SELECT CAST(a AS STRING) FROM t; > + ]], { > + 1, "Type mismatch: can not convert array([123]) to string" > + }) > +