[Tarantool-patches] [PATCH v1 1/2] sql: introduce field type MAP
Vladislav Shpilevoy
v.shpilevoy at tarantool.org
Sun Nov 14 19:24:21 MSK 2021
Thanks for the patch!
See 5 comments below.
On 11.11.2021 12:37, imeevma at 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'}
> +});
More information about the Tarantool-patches
mailing list