From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from smtpng3.m.smailru.net (smtpng3.m.smailru.net [94.100.177.149]) (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 AACE143D67A for ; Tue, 15 Oct 2019 16:10:37 +0300 (MSK) Date: Tue, 15 Oct 2019 16:10:36 +0300 From: Nikita Pettik Message-ID: <20191015131036.GA88253@tarantool.org> References: <05d61e713763e45d0e1d59d8c71699f9820a42cc.1568639944.git.kshcherbatov@tarantool.org> <20190925155156.GA42042@tarantool.org> <673fe725-f68d-e4f6-3ed0-25a4bc6255ad@tarantool.org> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline In-Reply-To: <673fe725-f68d-e4f6-3ed0-25a4bc6255ad@tarantool.org> Subject: Re: [Tarantool-patches] [tarantool-patches] Re: [PATCH v1 1/3] sql: errors for UDFs returning too many values List-Id: Tarantool development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Kirill Shcherbatov Cc: tarantool-patches@freelists.org, tarantool-patches@dev.tarantool.org On 08 Oct 11:38, Kirill Shcherbatov wrote: > This patch introduces handling the situation when UDF returns > too many values. Previously Tarantool used to silently use > the first value returned. Now an error is raised. > > Moreover a test coverage is improved also for the situation when > no value is returned. > > Needed for #4387 > --- > src/box/sql/func.c | 16 +++++++++------- > test/box/function1.c | 19 +++++++++++++++++++ > test/box/function1.result | 33 +++++++++++++++++++++++++++++++++ > test/box/function1.test.lua | 12 ++++++++++++ > 4 files changed, 73 insertions(+), 7 deletions(-) > > diff --git a/src/box/sql/func.c b/src/box/sql/func.c > index 60efd0d9a..551613908 100644 > --- a/src/box/sql/func.c > +++ b/src/box/sql/func.c > @@ -242,9 +242,10 @@ port_lua_get_vdbemem(struct port *base, uint32_t *size) > struct port_lua *port = (struct port_lua *) base; > struct lua_State *L = port->L; > int argc = lua_gettop(L); > - if (argc == 0) { > + if (argc == 0 || argc > 1) { > diag_set(ClientError, ER_SQL_EXECUTE, > - "No value was passed from Lua"); > + argc == 0 ? "No value was passed from Lua" : > + "Too many values were returned from LUA"); Why not add new errcode? Like "SQL expects exactly one argument returned from %s, got %d".. > return NULL; > } > *size = argc; Please add asserts below and fixme comment (since actually vectors are supported in SQL). assert(argc == 1); > @@ -288,9 +289,10 @@ port_tuple_get_vdbemem(struct port *base, uint32_t *size) > { > struct port_tuple *port = (struct port_tuple *)base; > *size = port->size; > - if (*size == 0) { > + if (*size == 0 || *size > 1) { > diag_set(ClientError, ER_SQL_EXECUTE, > - "No value was passed from C"); > + *size == 0 ? "No value was passed from C" : > + "Too many values were returned from C"); > return NULL; > } > struct region *region = &fiber()->gc; Same here.