From: Vladislav Shpilevoy via Tarantool-patches <tarantool-patches@dev.tarantool.org> To: imeevma@tarantool.org Cc: tarantool-patches@dev.tarantool.org Subject: Re: [Tarantool-patches] [PATCH v1 1/2] sql: introduce field type ARRAY Date: Sun, 14 Nov 2021 17:12:03 +0100 [thread overview] Message-ID: <7c124335-9796-90a4-9c2f-8bf3bfab353a@tarantool.org> (raw) In-Reply-To: <8a954f84706769e4d685cedac987c2de8eb947cc.1635927295.git.imeevma@gmail.com> 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" > + }) > +
next prev parent reply other threads:[~2021-11-14 16:12 UTC|newest] Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top 2021-11-03 8:17 [Tarantool-patches] [PATCH v1 0/2] Introduce field type ARRAY to SQL Mergen Imeev via Tarantool-patches 2021-11-03 8:17 ` [Tarantool-patches] [PATCH v1 1/2] sql: introduce field type ARRAY Mergen Imeev via Tarantool-patches 2021-11-03 12:09 ` Mergen Imeev via Tarantool-patches 2021-11-03 13:53 ` Konstantin Osipov via Tarantool-patches 2021-11-03 14:27 ` Mergen Imeev via Tarantool-patches 2021-11-03 14:33 ` Konstantin Osipov via Tarantool-patches 2021-11-14 16:12 ` Vladislav Shpilevoy via Tarantool-patches [this message] 2021-11-15 16:38 ` Mergen Imeev via Tarantool-patches 2021-11-03 8:17 ` [Tarantool-patches] [PATCH v1 2/2] sql: introduce ARRAY() function Mergen Imeev via Tarantool-patches 2021-11-03 12:11 ` Mergen Imeev via Tarantool-patches 2021-11-14 16:12 ` Vladislav Shpilevoy via Tarantool-patches 2021-11-15 16:40 ` Mergen Imeev via Tarantool-patches 2021-11-18 21:19 ` [Tarantool-patches] [PATCH v1 0/2] Introduce field type ARRAY to SQL Vladislav Shpilevoy via Tarantool-patches
Reply instructions: You may reply publicly to this message via plain-text email using any one of the following methods: * Save the following mbox file, import it into your mail client, and reply-to-all from there: mbox Avoid top-posting and favor interleaved quoting: https://en.wikipedia.org/wiki/Posting_style#Interleaved_style * Reply using the --to, --cc, and --in-reply-to switches of git-send-email(1): git send-email \ --in-reply-to=7c124335-9796-90a4-9c2f-8bf3bfab353a@tarantool.org \ --to=tarantool-patches@dev.tarantool.org \ --cc=imeevma@tarantool.org \ --cc=v.shpilevoy@tarantool.org \ --subject='Re: [Tarantool-patches] [PATCH v1 1/2] sql: introduce field type ARRAY' \ /path/to/YOUR_REPLY https://kernel.org/pub/software/scm/git/docs/git-send-email.html * If your mail client supports setting the In-Reply-To header via mailto: links, try the mailto: link
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox