Tarantool development patches archive
 help / color / mirror / Atom feed
From: Nikita Pettik <korablev@tarantool.org>
To: Kirill Shcherbatov <kshcherbatov@tarantool.org>
Cc: tarantool-patches@freelists.org, tarantool-patches@dev.tarantool.org
Subject: Re: [Tarantool-patches] [tarantool-patches] Re: [PATCH v1 1/3] sql: errors for UDFs returning too many values
Date: Tue, 15 Oct 2019 16:10:36 +0300	[thread overview]
Message-ID: <20191015131036.GA88253@tarantool.org> (raw)
In-Reply-To: <673fe725-f68d-e4f6-3ed0-25a4bc6255ad@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.

       reply	other threads:[~2019-10-15 13:10 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <cover.1568639944.git.kshcherbatov@tarantool.org>
     [not found] ` <05d61e713763e45d0e1d59d8c71699f9820a42cc.1568639944.git.kshcherbatov@tarantool.org>
     [not found]   ` <20190925155156.GA42042@tarantool.org>
     [not found]     ` <673fe725-f68d-e4f6-3ed0-25a4bc6255ad@tarantool.org>
2019-10-15 13:10       ` Nikita Pettik [this message]
2019-10-16 14:10         ` Kirill Shcherbatov
2019-10-17 12:51           ` Nikita Pettik
     [not found]     ` <c4766811-74aa-c46c-c4ca-940c991a5a90@tarantool.org>
2019-10-15 13:49       ` [Tarantool-patches] [tarantool-patches] Re: [PATCH v1 2/3] sql: better LUA arguments conversion for UDFs Nikita Pettik
2019-10-16 14:09         ` Kirill Shcherbatov

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20191015131036.GA88253@tarantool.org \
    --to=korablev@tarantool.org \
    --cc=kshcherbatov@tarantool.org \
    --cc=tarantool-patches@dev.tarantool.org \
    --cc=tarantool-patches@freelists.org \
    --subject='Re: [Tarantool-patches] [tarantool-patches] Re: [PATCH v1 1/3] sql: errors for UDFs returning too many values' \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox