[Tarantool-patches] [PATCH v1 1/2] sql: introduce field type ARRAY
Vladislav Shpilevoy
v.shpilevoy at tarantool.org
Sun Nov 14 19:12:03 MSK 2021
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"
> + })
> +
More information about the Tarantool-patches
mailing list