Tarantool development patches archive
 help / color / mirror / Atom feed
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 MAP
Date: Sun, 14 Nov 2021 17:24:21 +0100	[thread overview]
Message-ID: <a77ff686-3b8b-b081-59fd-49bcc4de43eb@tarantool.org> (raw)
In-Reply-To: <2febbd43dc012c13ccf2de0996b8b1e8bff9da54.1636630534.git.imeevma@gmail.com>

Thanks for the patch!

See 5 comments below.

On 11.11.2021 12:37, imeevma@tarantool.org wrote:
> This patch introduces MAP to SQL. After this patch, all SQL operations
> and built-in functions should work correctly with MAP values. However,
> there is currently no way to create MAP values using only SQL tools.
> 
> Part of #4763
> 
> @TarantoolBot document
> Title: Field type MAP in SQL
> 
> Properties of type MAP in SQL:
> 1) a value ofttype MAP can be implicitly and explicitly cast only to
> ANY;

1. ofttype -> of type.

> 2) only a value of type ANY with primitive type MAP can be explicitly
> cast to MAP;
> 3) a value of any other type cannot be implicitly cast to MAP;
> 4) a value of type MAP cannot participate in arithmetic, bitwise,
> comparison, and concationation operations.

2. concationation -> concatenation.

3. You need to add a changelog file. For the arrays patch too.

> @@ -3258,6 +3268,19 @@ port_vdbemem_dump_lua(struct port *base, struct lua_State *L, bool is_flat)
>  				luaL_setarrayhint(L, -1);
>  			return;
>  		}
> +		case MEM_TYPE_MAP: {
> +			const char *data = mem->z;
> +			uint32_t size = mp_decode_map(&data);
> +			lua_createtable(L, 0, size);
> +			for (uint32_t i = 0; i < size; i++) {
> +				luamp_decode(L, luaL_msgpack_default, &data);
> +				luamp_decode(L, luaL_msgpack_default, &data);
> +				lua_settable(L, -3);
> +			}
> +			if (luaL_msgpack_default->decode_save_metatables)
> +				luaL_setmaphint(L, -1);

4. The same as for arrays. For both of them you can call luamp_decode
on the root.

> diff --git a/test/sql-tap/map.test.lua b/test/sql-tap/map.test.lua
> new file mode 100755
> index 000000000..2be82db61
> --- /dev/null
> +++ b/test/sql-tap/map.test.lua
> @@ -0,0 +1,987 @@
> +#!/usr/bin/env tarantool
> +local test = require("sqltester")
> +test:plan(110)
> +
> +box.schema.func.create('M1', {
> +    language = 'Lua',
> +    body = 'function(a, b) return {[tostring(a)] = b} end',
> +    returns = 'map',
> +    param_list = {'any', 'any'},
> +    exports = {'LUA', 'SQL'}
> +});
> +
> +box.schema.func.create('M2', {
> +    language = 'Lua',
> +    body = 'function(a, b, c, d) return '..
> +           '{[tostring(a)] = b, [tostring(c)] = d} end',
> +    returns = 'map',
> +    param_list = {'any', 'any', 'any', 'any'},
> +    exports = {'LUA', 'SQL'}
> +});
> +
> +box.schema.func.create('M3', {
> +    language = 'Lua',
> +    body = 'function(a, b, c, d, e, f) return '..
> +           '{[tostring(a)] = b, [tostring(c)] = d, [tostring(e)] = f} end',

5. Why do you need the tostrings? Keys are free to have any type in
MessagePack. In Lua too. Can you add tests for non-string keys?

> +    returns = 'map',
> +    param_list = {'any', 'any', 'any', 'any', 'any', 'any'},
> +    exports = {'LUA', 'SQL'}
> +});

  reply	other threads:[~2021-11-14 16:24 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-11-11 11:37 [Tarantool-patches] [PATCH v1 0/2] Introduce field type MAP to SQL Mergen Imeev via Tarantool-patches
2021-11-11 11:37 ` [Tarantool-patches] [PATCH v1 1/2] sql: introduce field type MAP Mergen Imeev via Tarantool-patches
2021-11-14 16:24   ` Vladislav Shpilevoy via Tarantool-patches [this message]
2021-11-15 16:45     ` Mergen Imeev via Tarantool-patches
2021-11-11 11:37 ` [Tarantool-patches] [PATCH v1 2/2] sql: introduce MAP() function Mergen Imeev via Tarantool-patches
2021-11-14 16:24   ` Vladislav Shpilevoy via Tarantool-patches
2021-11-15 16:46     ` Mergen Imeev via Tarantool-patches
2021-11-18 21:21 ` [Tarantool-patches] [PATCH v1 0/2] Introduce field type MAP 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=a77ff686-3b8b-b081-59fd-49bcc4de43eb@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 MAP' \
    /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