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 E27446EC40; Wed, 2 Jun 2021 23:13:35 +0300 (MSK) DKIM-Filter: OpenDKIM Filter v2.11.0 dev.tarantool.org E27446EC40 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=tarantool.org; s=dev; t=1622664815; bh=S8nJ3m4JfPLub/64lL7kGu2nECC71YPxefdEDcN5T28=; h=To:Cc:References:In-Reply-To:Date:Subject:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From:Reply-To:From; b=mQx7ijWAYIWuHFwam/H36KZvy9HZna8BzR93ww6I5dXnF6x4YjOzRZekuHFj4cWVl r+/W+vP92UwAM7cNu/JPhjMBAobGX0AHV31Le7GTdT9rYN1ZgpZjfZkeLNC1dN0M7z 3D+KGHnlCujkE7H3V3uMNH0tFG7aW7mS6N5g02Ik= Received: from smtp31.i.mail.ru (smtp31.i.mail.ru [94.100.177.91]) (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 4C9276EC43 for ; Wed, 2 Jun 2021 23:13:06 +0300 (MSK) DKIM-Filter: OpenDKIM Filter v2.11.0 dev.tarantool.org 4C9276EC43 Received: by smtp31.i.mail.ru with esmtpa (envelope-from ) id 1loXEf-0006uI-B2; Wed, 02 Jun 2021 23:13:05 +0300 To: Cc: References: <8562fcc66ad464231cd916a94a41f556d6e57f38.1622620858.git.imeevma@gmail.com> In-Reply-To: <8562fcc66ad464231cd916a94a41f556d6e57f38.1622620858.git.imeevma@gmail.com> Date: Wed, 2 Jun 2021 23:13:05 +0300 Message-ID: <04ea01d757eb$b26b5a70$17420f50$@tarantool.org> MIME-Version: 1.0 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Mailer: Microsoft Outlook 16.0 Thread-Index: AQHg7e1IgrM3NmEZeoSIT89ocQXnegG8hqgeqt/gtvA= Content-Language: ru X-7564579A: 646B95376F6C166E X-77F55803: 4F1203BC0FB41BD9D5B0DA836B685C54F4BC37E91F2690B85F43D7652182C513182A05F53808504013289F06164BE0CF86A1D7EFD2657D3312B87A0E05D2F19F413F8B4B1A752C33 X-7FA49CB5: FF5795518A3D127A4AD6D5ED66289B5278DA827A17800CE7B356E3E4D202B32AEA1F7E6F0F101C67BD4B6F7A4D31EC0BCC500DACC3FED6E28638F802B75D45FF8AA50765F79006371ECA800C705ED7E68638F802B75D45FF36EB9D2243A4F8B5A6FCA7DBDB1FC311F39EFFDF887939037866D6147AF826D8A0797E70345C74027B0BA93760A6596A117882F4460429724CE54428C33FAD305F5C1EE8F4F765FCAA867293B0326636D2E47CDBA5A96583BD4B6F7A4D31EC0BC014FD901B82EE079FA2833FD35BB23D27C277FBC8AE2E8BAA867293B0326636D2E47CDBA5A96583BA9C0B312567BB2376E601842F6C81A19E625A9149C048EE4B6963042765DA4B985B8ACC81218E19D8FC6C240DEA7642DBF02ECDB25306B2B78CF848AE20165D0A6AB1C7CE11FEE38ED1AC82D843A2BB040F9FF01DFDA4A8C4224003CC836476EA7A3FFF5B025636E2021AF6380DFAD1A18204E546F3947CB11811A4A51E3B096D1867E19FE1407959CC434672EE6371089D37D7C0E48F6C8AA50765F7900637BBEA499411984DA1EFF80C71ABB335746BA297DBC24807EABDAD6C7F3747799A X-B7AD71C0: AC4F5C86D027EB782CDD5689AFBDA7A2368A440D3B0F6089093C9A16E5BC824A2A04A2ABAA09D25379311020FFC8D4AD494FFA51BD827F93B7F0067CEA8BDB59 X-C1DE0DAB: 0D63561A33F958A574F256819BE32F8C8F282141C92DBB9C0A7644598DD7D09ED59269BC5F550898D99A6476B3ADF6B47008B74DF8BB9EF7333BD3B22AA88B938A852937E12ACA75FBC5FED0552DA851410CA545F18667F91A7EA1CDA0B5A7A0 X-C8649E89: 4E36BF7865823D7055A7F0CF078B5EC49A30900B95165D344A431191C56981FEFD4BB788CEAA2B64096492A4B41D769BD9BDE7930B1EB74A52BECBD71F5A52021D7E09C32AA3244CCFA18149AA5466C7FD146C593959C3D497FE24653F78E668729B2BEF169E0186 X-D57D3AED: 3ZO7eAau8CL7WIMRKs4sN3D3tLDjz0dLbV79QFUyzQ2Ujvy7cMT6pYYqY16iZVKkSc3dCLJ7zSJH7+u4VD18S7Vl4ZUrpaVfd2+vE6kuoey4m4VkSEu530nj6fImhcD4MUrOEAnl0W826KZ9Q+tr5ycPtXkTV4k65bRjmOUUP8cvGozZ33TWg5HZplvhhXbhDGzqmQDTd6OAevLeAnq3Ra9uf7zvY2zzsIhlcp/Y7m53TZgf2aB4JOg4gkr2bioj+mfSpkNmA2pWWtthEpQsLw== X-Mailru-Sender: B5B6A6EBBD94DAD840208BF9E14C1DD23F7CEC366120BBB62D15FB4D445EF19E0BF894E8893BBBED1EC9E4A2C82A33BC8C24925A86E657CE0C70AEE3C9A96FBAB3D7EE8ED63280BE112434F685709FCF0DA7A0AF5A3A8387 X-Mras: Ok Subject: Re: [Tarantool-patches] [PATCH v2 2/2] sql: introduce SQL built-in function UUID() 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: Timur Safin via Tarantool-patches Reply-To: Timur Safin Errors-To: tarantool-patches-bounces@dev.tarantool.org Sender: "Tarantool-patches" LGTM : From: imeevma@tarantool.org : Sent: Wednesday, June 2, 2021 11:03 AM : To: tsafin@tarantool.org : Cc: tarantool-patches@dev.tarantool.org : Subject: [PATCH v2 2/2] sql: introduce SQL built-in function UUID() :=20 : This patch introduces a new SQL built-in function UUID(). :=20 : Closes #5886 :=20 : @TarantoolBot document : Title: SQL built-in function UUID() :=20 : SQL built-in function UUID() takes zero or one argument. If no = argument : is specified, a UUID v4 is generated. If the version of the UUID to : generate is specified as an argument, the function returns the new = UUID : of the given version. Currently only version 4 of UUID is supported. : --- : .../unreleased/introduce-uuid-to-sql.md | 3 + : src/box/bootstrap.snap | Bin 5991 -> 6016 = bytes : src/box/lua/upgrade.lua | 19 +++++++ : src/box/sql/func.c | 39 +++++++++++++ : src/box/sql/parse.y | 2 +- : test/box-py/bootstrap.result | 3 +- : test/box/access.result | 2 +- : test/box/access.test.lua | 2 +- : test/box/access_bin.result | 2 +- : test/box/access_bin.test.lua | 2 +- : test/box/access_sysview.result | 8 +-- : test/box/function1.result | 6 +- : test/sql-tap/uuid.test.lua | 52 = +++++++++++++++++- : test/wal_off/func_max.result | 8 +-- : 14 files changed, 130 insertions(+), 18 deletions(-) : create mode 100644 changelogs/unreleased/introduce-uuid-to-sql.md :=20 : diff --git a/changelogs/unreleased/introduce-uuid-to-sql.md : b/changelogs/unreleased/introduce-uuid-to-sql.md : new file mode 100644 : index 000000000..642ac94fb : --- /dev/null : +++ b/changelogs/unreleased/introduce-uuid-to-sql.md : @@ -0,0 +1,3 @@ : +## feature/core : + : + * Field type UUID is now available in SQL, and new UUID can be = generated : using new SQL built-in function uuid() (gh-5886). :=20 ... : diff --git a/src/box/lua/upgrade.lua b/src/box/lua/upgrade.lua : index 6fba260bd..97afc0b4d 100644 : --- a/src/box/lua/upgrade.lua : +++ b/src/box/lua/upgrade.lua : @@ -1000,6 +1000,24 @@ local function upgrade_to_2_7_1() : function_access() : end :=20 : = +------------------------------------------------------------------------= --- : ----- : +-- Tarantool 2.9.1 : = +------------------------------------------------------------------------= --- : ----- : +local function sql_builtin_function_uuid() : + local _func =3D box.space._func : + local _priv =3D box.space._priv : + local datetime =3D os.date("%Y-%m-%d %H:%M:%S") : + local t =3D _func:auto_increment({ADMIN, 'UUID', 1, = 'SQL_BUILTIN', '', : + 'function', {}, 'any', 'none', = 'none', : + false, false, true, {}, = setmap({}), '', : + datetime, datetime}) : + _priv:replace{ADMIN, PUBLIC, 'function', t.id, box.priv.X} : +end : + : +local function upgrade_to_2_9_1() : + sql_builtin_function_uuid() : +end : + : = -------------------------------------------------------------------------= -- : ----- :=20 : local handlers =3D { : @@ -1015,6 +1033,7 @@ local handlers =3D { : {version =3D mkversion(2, 3, 0), func =3D upgrade_to_2_3_0, auto = =3D true}, : {version =3D mkversion(2, 3, 1), func =3D upgrade_to_2_3_1, auto = =3D true}, : {version =3D mkversion(2, 7, 1), func =3D upgrade_to_2_7_1, auto = =3D true}, : + {version =3D mkversion(2, 9, 1), func =3D upgrade_to_2_9_1, auto = =3D true}, : } :=20 : -- Schema version of the snapshot. : diff --git a/src/box/sql/func.c b/src/box/sql/func.c : index 9c4480a92..f93ae867d 100644 : --- a/src/box/sql/func.c : +++ b/src/box/sql/func.c : @@ -66,6 +66,35 @@ mem_as_bin(struct Mem *mem) : return s; : } :=20 : +static void : +sql_func_uuid(struct sql_context *ctx, int argc, struct Mem **argv) : +{ : + if (argc > 1) { : + diag_set(ClientError, ER_FUNC_WRONG_ARG_COUNT, "UUID", : + "one or zero", argc); : + ctx->is_aborted =3D true; : + return; : + } : + if (argc =3D=3D 1) { : + uint64_t version; : + if (mem_get_uint(argv[0], &version) !=3D 0) { : + diag_set(ClientError, ER_SQL_TYPE_MISMATCH, : + mem_str(argv[0]), "integer"); : + ctx->is_aborted =3D true; : + return; : + } : + if (version !=3D 4) { : + diag_set(ClientError, ER_UNSUPPORTED, "Function UUID", : + "versions other than 4"); : + ctx->is_aborted =3D true; : + return; : + } : + } : + struct tt_uuid uuid; : + tt_uuid_create(&uuid); : + mem_set_uuid(ctx->pOut, &uuid); : +} : + : /* : * Return the collating function associated with a function. : */ : @@ -2544,6 +2573,16 @@ static struct { : .call =3D UpperICUFunc, : .finalize =3D NULL, : .export_to_sql =3D true, : + }, { : + .name =3D "UUID", : + .param_count =3D -1, : + .returns =3D FIELD_TYPE_UUID, : + .aggregate =3D FUNC_AGGREGATE_NONE, : + .is_deterministic =3D false, : + .flags =3D 0, : + .call =3D sql_func_uuid, : + .finalize =3D NULL, : + .export_to_sql =3D true, : }, { : .name =3D "VERSION", : .param_count =3D 0, : diff --git a/src/box/sql/parse.y b/src/box/sql/parse.y : index 4c9cf475e..bd041e862 100644 : --- a/src/box/sql/parse.y : +++ b/src/box/sql/parse.y : @@ -268,7 +268,7 @@ columnlist ::=3D tcons. : CONFLICT DEFERRED END ENGINE FAIL : IGNORE INITIALLY INSTEAD NO MATCH PLAN : QUERY KEY OFFSET RAISE RELEASE REPLACE RESTRICT : - RENAME CTIME_KW IF ENABLE DISABLE : + RENAME CTIME_KW IF ENABLE DISABLE UUID : . : %wildcard ANY. :=20 : diff --git a/test/box-py/bootstrap.result = b/test/box-py/bootstrap.result : index ed7accea3..b2328487c 100644 : --- a/test/box-py/bootstrap.result : +++ b/test/box-py/bootstrap.result : @@ -4,7 +4,7 @@ box.internal.bootstrap() : box.space._schema:select{} : --- : - - ['max_id', 511] : - - ['version', 2, 7, 1] : + - ['version', 2, 9, 1] : ... : box.space._cluster:select{} : --- : @@ -242,6 +242,7 @@ box.space._priv:select{} : - [1, 2, 'function', 65, 4] : - [1, 2, 'function', 66, 4] : - [1, 2, 'function', 67, 4] : + - [1, 2, 'function', 68, 4] : - [1, 2, 'space', 276, 2] : - [1, 2, 'space', 277, 1] : - [1, 2, 'space', 281, 1] : diff --git a/test/box/access.result b/test/box/access.result : index 27e636122..1a8730f1a 100644 : --- a/test/box/access.result : +++ b/test/box/access.result : @@ -703,7 +703,7 @@ box.schema.func.exists(1) : --- : - true : ... : -box.schema.func.exists(68) : +box.schema.func.exists(69) : --- : - false : ... : diff --git a/test/box/access.test.lua b/test/box/access.test.lua : index a62f87ad8..2bf772b7b 100644 : --- a/test/box/access.test.lua : +++ b/test/box/access.test.lua : @@ -282,7 +282,7 @@ box.schema.user.exists{} : box.schema.func.exists('nosuchfunc') : box.schema.func.exists('guest') : box.schema.func.exists(1) : -box.schema.func.exists(68) : +box.schema.func.exists(69) : box.schema.func.exists('box.schema.user.info') : box.schema.func.exists() : box.schema.func.exists(nil) : diff --git a/test/box/access_bin.result b/test/box/access_bin.result : index c58f331d3..aeb8b3bd8 100644 : --- a/test/box/access_bin.result : +++ b/test/box/access_bin.result : @@ -298,7 +298,7 @@ box.schema.user.grant('guest', 'execute', = 'universe') : function f1() return box.space._func:get(1)[4] end : --- : ... : -function f2() return box.space._func:get(68)[4] end : +function f2() return box.space._func:get(69)[4] end : --- : ... : box.schema.func.create('f1') : diff --git a/test/box/access_bin.test.lua = b/test/box/access_bin.test.lua : index 41d5f4245..954266858 100644 : --- a/test/box/access_bin.test.lua : +++ b/test/box/access_bin.test.lua : @@ -112,7 +112,7 @@ test:drop() : -- notice that guest can execute stuff, but can't read space _func : box.schema.user.grant('guest', 'execute', 'universe') : function f1() return box.space._func:get(1)[4] end : -function f2() return box.space._func:get(68)[4] end : +function f2() return box.space._func:get(69)[4] end : box.schema.func.create('f1') : box.schema.func.create('f2',{setuid=3Dtrue}) : c =3D net.connect(box.cfg.listen) : diff --git a/test/box/access_sysview.result = b/test/box/access_sysview.result : index 6468a0709..d7a7b7534 100644 : --- a/test/box/access_sysview.result : +++ b/test/box/access_sysview.result : @@ -258,11 +258,11 @@ box.session.su('guest') : ... : #box.space._vpriv:select{} : --- : -- 82 : +- 83 : ... : #box.space._vfunc:select{} : --- : -- 67 : +- 68 : ... : #box.space._vcollation:select{} : --- : @@ -290,11 +290,11 @@ box.session.su('guest') : ... : #box.space._vpriv:select{} : --- : -- 82 : +- 83 : ... : #box.space._vfunc:select{} : --- : -- 67 : +- 68 : ... : #box.space._vsequence:select{} : --- : diff --git a/test/box/function1.result b/test/box/function1.result : index 928cd5758..0166c828f 100644 : --- a/test/box/function1.result : +++ b/test/box/function1.result : @@ -97,7 +97,7 @@ box.func["function1.args"] : exports: : lua: true : sql: false : - id: 68 : + id: 69 : setuid: false : is_multikey: false : is_deterministic: false : @@ -593,7 +593,7 @@ func : exports: : lua: true : sql: false : - id: 68 : + id: 69 : setuid: false : is_multikey: false : is_deterministic: false : @@ -665,7 +665,7 @@ func : exports: : lua: true : sql: false : - id: 68 : + id: 69 : setuid: false : is_multikey: false : is_deterministic: false : diff --git a/test/sql-tap/uuid.test.lua b/test/sql-tap/uuid.test.lua : index 4287f0921..83fcc3d0e 100755 : --- a/test/sql-tap/uuid.test.lua : +++ b/test/sql-tap/uuid.test.lua : @@ -3,7 +3,7 @@ local build_path =3D os.getenv("BUILDDIR") : package.cpath =3D = build_path..'/test/sql-tap/?.so;'..build_path..'/test/sql- : tap/?.dylib;'..package.cpath :=20 : local test =3D require("sqltester") : -test:plan(139) : +test:plan(145) :=20 : local uuid =3D require("uuid") : local uuid1 =3D uuid.fromstr("11111111-1111-1111-1111-111111111111") : @@ -1266,6 +1266,56 @@ test:do_execsql_test( : 3,2,1 : }) :=20 : +-- Check function uuid(). : +test:do_execsql_test( : + "uuid-16.1", : + [[ : + SELECT typeof(uuid()); : + ]], { : + "uuid" : + }) : + : +test:do_execsql_test( : + "uuid-16.2", : + [[ : + SELECT typeof(uuid(4)); : + ]], { : + "uuid" : + }) : + : +test:do_catchsql_test( : + "uuid-16.3", : + [[ : + SELECT uuid(1); : + ]], { : + 1, "Function UUID does not support versions other than 4" : + }) : + : +test:do_catchsql_test( : + "uuid-16.4", : + [[ : + SELECT uuid('asd'); : + ]], { : + 1, "Type mismatch: can not convert asd to integer" : + }) : + : +test:do_catchsql_test( : + "uuid-16.5", : + [[ : + SELECT uuid(4, 5); : + ]], { : + 1, "Wrong number of arguments is passed to UUID(): expected = one or : zero, got 2" : + }) : + : +-- Make sure the uuid() function generates a new UUID each time when : called. : +test:do_execsql_test( : + "uuid-16.6", : + [[ : + SELECT uuid() !=3D uuid(); : + ]], { : + true : + }) : + : test:execsql([[ : DROP TRIGGER t; : DROP VIEW v; : diff --git a/test/wal_off/func_max.result = b/test/wal_off/func_max.result : index 78db38d6b..cc5bcc141 100644 : --- a/test/wal_off/func_max.result : +++ b/test/wal_off/func_max.result : @@ -42,11 +42,11 @@ test_run:cmd("setopt delimiter ''"); : ... : func_limit() : --- : -- error: 'Failed to create function ''func31934'': function id is too = big' : +- error: 'Failed to create function ''func31933'': function id is too = big' : ... : drop_limit_func() : --- : -- error: Function 'func31934' does not exist : +- error: Function 'func31933' does not exist : ... : box.schema.user.create('testuser') : --- : @@ -62,11 +62,11 @@ session.su('testuser') : ... : func_limit() : --- : -- error: 'Failed to create function ''func31934'': function id is too = big' : +- error: 'Failed to create function ''func31933'': function id is too = big' : ... : drop_limit_func() : --- : -- error: Function 'func31934' does not exist : +- error: Function 'func31933' does not exist : ... : session.su('admin') : --- : -- : 2.25.1