[Tarantool-patches] [tarantool-patches] Re: [PATCH v1 1/3] sql: errors for UDFs returning too many values

Nikita Pettik korablev at tarantool.org
Tue Oct 15 16:10:36 MSK 2019


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.



More information about the Tarantool-patches mailing list