Tarantool development patches archive
 help / color / mirror / Atom feed
* Re: [Tarantool-patches] [tarantool-patches] Re: [PATCH v1 1/3] sql: errors for UDFs returning too many values
       [not found]     ` <673fe725-f68d-e4f6-3ed0-25a4bc6255ad@tarantool.org>
@ 2019-10-15 13:10       ` Nikita Pettik
  2019-10-16 14:10         ` Kirill Shcherbatov
  0 siblings, 1 reply; 5+ messages in thread
From: Nikita Pettik @ 2019-10-15 13:10 UTC (permalink / raw)
  To: Kirill Shcherbatov; +Cc: tarantool-patches, tarantool-patches

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.

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [Tarantool-patches] [tarantool-patches] Re: [PATCH v1 2/3] sql: better LUA arguments conversion for UDFs
       [not found]     ` <c4766811-74aa-c46c-c4ca-940c991a5a90@tarantool.org>
@ 2019-10-15 13:49       ` Nikita Pettik
  2019-10-16 14:09         ` Kirill Shcherbatov
  0 siblings, 1 reply; 5+ messages in thread
From: Nikita Pettik @ 2019-10-15 13:49 UTC (permalink / raw)
  To: Kirill Shcherbatov; +Cc: tarantool-patches, tarantool-patches

On 08 Oct 11:38, Kirill Shcherbatov wrote:
> >>  		case MP_UINT: {
> >> -			sql_int64 val = sql_value_int64(param);
> >> +			sql_uint64 val = sql_value_uint64(param);
> > 
> > If this is a bug, please move it to a separate patch and provide
> > test case.
> > 
> >>  			mpstream_encode_uint(&stream, val);
> 
> Formally, it is a bug, but nobody can reproduce it. sql_value_int64 and sql_value_uint64 do
> exactly the same thing inside while mpstream_encode_uint internally casts val variable
> to uint64_t.
> 
> I need mention the scenario when this code works: it should be uint64_t passed to
> C-language UDF. I've analyzed it carefully, and everything is ok there.
> This test case is big enough and is not important: C-language UDFs are already covered
> by tests.
> 
> I believe that fixing this problem (same as a problem below) silently in scope of "better LUA
> arguments conversion for UDFs" is ok.  

Ok, as you wish.
 
> >> -			sqlVdbeMemSetNull(val);
> >> +			sqlVdbeMemSetNull(&val[i]);
> >>
> > These two places also look like bugs as well...
> UDF function may return multiple values, but we can't handle such situation
> normally in SQL. This must be banned. I've included a path that does it in
> a separate letter.
> >> +                        param_list = {'any'}, returns = 'scalar',
> > 
> > Why did you have to change types? What is the difference between them,
> > if the base type is not map or array?
> This doesn't makes sense now. Ok, let's do not change param_list arguments.
> 
> > Btw, is this documented fact that nil is converted to NULL?
> > So box.NULL and nil means the same in SQL..
> This behavior is confirmed as OK by Kostya. I've included  TarantoolBot request
> to document it.
> 
> =======================================================
> 
> Start using comprehensive serializer luaL_tofield() to prepare
> LUA arguments for UDFs. This allows to support cdata types
> returned from Lua function.
> 
> Needed for #4387
> 
> @TarantoolBot document
> Title: UDF returning nil or box.NULL in SQL
> 
> Values nil and box.NULL returned by UDF in SQL
> both transformed to SQL NULL and are equal.
> 
> Example:
> tarantool> box.execute("SELECT LUA('return nil') is NULL
>                                and LUA('return nil') is NULL")

Two conditions are equal. I guess second one should be 'return box.NULL'.
The rest is OK.

> ---
> - metadata:
>   - name: LUA('return nil') is NULL and LUA('return nil') is NULL
>     type: boolean
>   rows:
>   - [true]
> ...
> ---

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [Tarantool-patches] [tarantool-patches] Re: [PATCH v1 2/3] sql: better LUA arguments conversion for UDFs
  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
  0 siblings, 0 replies; 5+ messages in thread
From: Kirill Shcherbatov @ 2019-10-16 14:09 UTC (permalink / raw)
  To: tarantool-patches, Nikita Pettik; +Cc: tarantool-patches

>> Example:
>> tarantool> box.execute("SELECT LUA('return nil') is NULL
>>                                and LUA('return nil') is NULL")
> 
> Two conditions are equal. I guess second one should be 'return box.NULL'.
> The rest is OK.
Right, fixed.

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [Tarantool-patches] [tarantool-patches] Re: [PATCH v1 1/3] sql: errors for UDFs returning too many values
  2019-10-15 13:10       ` [Tarantool-patches] [tarantool-patches] Re: [PATCH v1 1/3] sql: errors for UDFs returning too many values Nikita Pettik
@ 2019-10-16 14:10         ` Kirill Shcherbatov
  2019-10-17 12:51           ` Nikita Pettik
  0 siblings, 1 reply; 5+ messages in thread
From: Kirill Shcherbatov @ 2019-10-16 14:10 UTC (permalink / raw)
  To: tarantool-patches, Nikita Pettik; +Cc: tarantool-patches


> Why not add new errcode? Like "SQL expects exactly one argument returned
> from %s, got %d"..
Done.

> 
> Please add asserts below and fixme comment (since actually vectors are
> supported in SQL).
> 
>  assert(argc == 1);
> Same here.
Done.

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [Tarantool-patches] [tarantool-patches] Re: [PATCH v1 1/3] sql: errors for UDFs returning too many values
  2019-10-16 14:10         ` Kirill Shcherbatov
@ 2019-10-17 12:51           ` Nikita Pettik
  0 siblings, 0 replies; 5+ messages in thread
From: Nikita Pettik @ 2019-10-17 12:51 UTC (permalink / raw)
  To: Kirill Shcherbatov; +Cc: tarantool-patches, tarantool-patches

On 16 Oct 17:10, Kirill Shcherbatov wrote:
> 
> > Why not add new errcode? Like "SQL expects exactly one argument returned
> > from %s, got %d"..
> Done.
> 
> > 
> > Please add asserts below and fixme comment (since actually vectors are
> > supported in SQL).
> > 
> >  assert(argc == 1);
> > Same here.
> Done.

Pushed whole patch-set to master.

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2019-10-17 12:51 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
     [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       ` [Tarantool-patches] [tarantool-patches] Re: [PATCH v1 1/3] sql: errors for UDFs returning too many values Nikita Pettik
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

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