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 DFC3A6EC58; Fri, 28 May 2021 14:42:26 +0300 (MSK) DKIM-Filter: OpenDKIM Filter v2.11.0 dev.tarantool.org DFC3A6EC58 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=tarantool.org; s=dev; t=1622202146; bh=WqSDBzP58jx+P7gFe/jqguPUiELbjhp6FVgVjfYyhdA=; h=To:Cc:Date:In-Reply-To:References:Subject:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From:Reply-To:From; b=mK5EQ1sCqx4VW9zHx5tUo3X28NSW6LwYsqoI/i+0gu8hCiw7wUtmY7zhP6QlDLUqV bPASndCc8GjB/ZNbVfkk+9UfIUze1CXvy6BCnqJhOchvPA7HrCu0a0QhT+HD377AmC 6fqtrck1XnjcUi7lOQbBoXVXSPEi3ooWo1ARDeII= Received: from smtpng2.m.smailru.net (smtpng2.m.smailru.net [94.100.179.3]) (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 75B636EC61 for ; Fri, 28 May 2021 14:41:28 +0300 (MSK) DKIM-Filter: OpenDKIM Filter v2.11.0 dev.tarantool.org 75B636EC61 Received: by smtpng2.m.smailru.net with esmtpa (envelope-from ) id 1lmarn-00066k-S6; Fri, 28 May 2021 14:41:28 +0300 To: v.shpilevoy@tarantool.org Cc: tarantool-patches@dev.tarantool.org Date: Fri, 28 May 2021 14:41:27 +0300 Message-Id: <43a3a45ce4f75288641b5c63299eca9fda69e64c.1622201982.git.imeevma@gmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-7564579A: 646B95376F6C166E X-77F55803: 4F1203BC0FB41BD9157EECD0FDB90B9A08BD84AE47613DD977C0A1DE3008D86900894C459B0CD1B94D6CCFE6ED3FF249FE8CC669452690883966DC9522174D58E9F8F47979F3B776 X-7FA49CB5: FF5795518A3D127A4AD6D5ED66289B5278DA827A17800CE70B8ADF238913687CB287FD4696A6DC2FA8DF7F3B2552694A4E2F5AFA99E116B42401471946AA11AF1661749BA6B977353AB734EB09B81F308F08D7030A58E5AD1A62830130A00468AEEEE3FBA3A834EE7353EFBB553375667E9571940300E71A7572D7E6246175FD1FCBDABF7314517FA471835C12D1D9774AD6D5ED66289B5278DA827A17800CE71AE4D56B06699BBC9FA2833FD35BB23D2EF20D2F80756B5F868A13BD56FB6657A471835C12D1D977725E5C173C3A84C3CA5A41EBD8A3A0199FA2833FD35BB23DF004C906525384302BEBFE083D3B9BA71A620F70A64A45A98AA50765F79006372E808ACE2090B5E1725E5C173C3A84C3C5EA940A35A165FF2DBA43225CD8A89F83C798A30B85E16B57739F23D657EF2BB5C8C57E37DE458BEDA766A37F9254B7 X-C1DE0DAB: C20DE7B7AB408E4181F030C43753B8186998911F362727C414F749A5E30D975C7E9571940300E71A7572D7E6246175FD1FCBDABF7314517F9C2B6934AE262D3EE7EAB7254005DCED7532B743992DF240BDC6A1CF3F042BAD6DF99611D93F60EFB4CA5BC574AE2910699F904B3F4130E343918A1A30D5E7FCCB5012B2E24CD356 X-C8649E89: 4E36BF7865823D7055A7F0CF078B5EC49A30900B95165D348CDF4129B2EA85609CBFAE7F77D65E02D4C168D036636EA3843FDACBD7CDC064738D60A69456A9731D7E09C32AA3244C59A0AEC926FB184D89AC052CA813DDEBCE0B41342B755BCD729B2BEF169E0186 X-D57D3AED: 3ZO7eAau8CL7WIMRKs4sN3D3tLDjz0dLbV79QFUyzQ2Ujvy7cMT6pYYqY16iZVKkSc3dCLJ7zSJH7+u4VD18S7Vl4ZUrpaVfd2+vE6kuoey4m4VkSEu530nj6fImhcD4MUrOEAnl0W826KZ9Q+tr5ycPtXkTV4k65bRjmOUUP8cvGozZ33TWg5HZplvhhXbhDGzqmQDTd6OAevLeAnq3Ra9uf7zvY2zzsIhlcp/Y7m53TZgf2aB4JOg4gkr2biojrzEAfVgW/763zBPfxLzrGA== X-Mailru-Sender: 689FA8AB762F73936BC43F508A063822BC7D44EF8A1F7D4FABA585C743F92C7483D72C36FC87018B9F80AB2734326CD2FB559BB5D741EB96352A0ABBE4FDA4210A04DAD6CC59E33667EA787935ED9F1B X-Mras: Ok Subject: [Tarantool-patches] [PATCH v1 2/2] sql: VARBINARY result for LUA functions 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: Mergen Imeev via Tarantool-patches Reply-To: imeevma@tarantool.org Errors-To: tarantool-patches-bounces@dev.tarantool.org Sender: "Tarantool-patches" This patch allows VARBINARY to be returned for user-defined LUA functions. However, there are currently no values that can be interpreted as VARBINARY by the serializer, so the only way to get a VARBINARY result for user-defined LUA functions is to return a UUID or DECIMAL. Both types are not supported by SQL and are treated as VARBINARY. Closes #6024 --- .../fix-error-on-return-bin-from-funcs.md | 3 ++ src/box/sql/mem.c | 33 ++++++++++++++++++ .../sql-tap/gh-6024-funcs-return-bin.test.lua | 34 ++++++++++++++++++- 3 files changed, 69 insertions(+), 1 deletion(-) create mode 100644 changelogs/unreleased/fix-error-on-return-bin-from-funcs.md diff --git a/changelogs/unreleased/fix-error-on-return-bin-from-funcs.md b/changelogs/unreleased/fix-error-on-return-bin-from-funcs.md new file mode 100644 index 000000000..f82815892 --- /dev/null +++ b/changelogs/unreleased/fix-error-on-return-bin-from-funcs.md @@ -0,0 +1,3 @@ +## bugfix/sql + +* User-defined functions can now return VARBINARY as result (gh-6024). diff --git a/src/box/sql/mem.c b/src/box/sql/mem.c index f81f78e27..9894c09af 100644 --- a/src/box/sql/mem.c +++ b/src/box/sql/mem.c @@ -39,6 +39,8 @@ #include "box/port.h" #include "lua/utils.h" #include "lua/msgpack.h" +#include "uuid/mp_uuid.h" +#include "mp_decimal.h" /* * Make sure pMem->z points to a writable allocation of at least @@ -2967,6 +2969,37 @@ port_lua_get_vdbemem(struct port *base, uint32_t *size) field.sval.len) != 0) goto error; break; + case MP_EXT: { + assert(field.ext_type == MP_UUID || + field.ext_type == MP_DECIMAL); + char *buf; + uint32_t size; + uint32_t svp = region_used(&fiber()->gc); + if (field.ext_type == MP_UUID) { + size = mp_sizeof_uuid(); + buf = region_alloc(&fiber()->gc, size); + if (buf == NULL) { + diag_set(OutOfMemory, size, + "region_alloc", "buf"); + goto error; + } + mp_encode_uuid(buf, field.uuidval); + } else { + size = mp_sizeof_decimal(field.decval); + buf = region_alloc(&fiber()->gc, size); + if (buf == NULL) { + diag_set(OutOfMemory, size, + "region_alloc", "buf"); + goto error; + } + mp_encode_decimal(buf, field.decval); + } + int rc = mem_copy_bin(&val[i], buf, size); + region_truncate(&fiber()->gc, svp); + if (rc != 0) + goto error; + break; + } case MP_NIL: break; default: diff --git a/test/sql-tap/gh-6024-funcs-return-bin.test.lua b/test/sql-tap/gh-6024-funcs-return-bin.test.lua index 90d09b497..bf406ab7b 100755 --- a/test/sql-tap/gh-6024-funcs-return-bin.test.lua +++ b/test/sql-tap/gh-6024-funcs-return-bin.test.lua @@ -3,7 +3,7 @@ local build_path = os.getenv("BUILDDIR") package.cpath = build_path..'/test/sql-tap/?.so;'..build_path..'/test/sql-tap/?.dylib;'..package.cpath local test = require("sqltester") -test:plan(3) +test:plan(5) box.schema.func.create("gh-6024-funcs-return-bin.ret_bin", { language = "C", @@ -50,4 +50,36 @@ test:do_execsql_test( "varbinary" }) +box.schema.func.create("get_uuid", { + language = "LUA", + param_list = {}, + returns = "varbinary", + body = "function(x) return require('uuid').fromstr('11111111-1111-1111-1111-111111111111') end", + exports = {"SQL"}, +}) + +test:do_execsql_test( + "gh-6024-4", + [[ + SELECT typeof("get_uuid"()), "get_uuid"() == "gh-6024-funcs-return-bin.ret_uuid"(); + ]], { + "varbinary", true + }) + +box.schema.func.create("get_decimal", { + language = "LUA", + param_list = {}, + returns = "varbinary", + body = "function(x) return require('decimal').new('9999999999999999999.9999999999999999999') end", + exports = {"SQL"}, +}) + +test:do_execsql_test( + "gh-6024-5", + [[ + SELECT typeof("get_decimal"()), "get_decimal"() == "gh-6024-funcs-return-bin.ret_decimal"(); + ]], { + "varbinary", true + }) + test:finish_test() -- 2.25.1