From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from localhost (localhost [127.0.0.1]) by turing.freelists.org (Avenir Technologies Mail Multiplex) with ESMTP id B57DF2A7C4 for ; Thu, 21 Mar 2019 09:36:44 -0400 (EDT) Received: from turing.freelists.org ([127.0.0.1]) by localhost (turing.freelists.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id vSYXsin3LJv8 for ; Thu, 21 Mar 2019 09:36:44 -0400 (EDT) Received: from smtpng1.m.smailru.net (smtpng1.m.smailru.net [94.100.181.251]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by turing.freelists.org (Avenir Technologies Mail Multiplex) with ESMTPS id 5FDA9276E7 for ; Thu, 21 Mar 2019 09:36:44 -0400 (EDT) Subject: [tarantool-patches] Re: [PATCH v1 1/1] box: fix format of tuple produced with frommap() References: <558c48af114ba67b997489ce2a150ffa1b7f5a22.1553088664.git.kshcherbatov@tarantool.org> From: Vladislav Shpilevoy Message-ID: Date: Thu, 21 Mar 2019 16:36:40 +0300 MIME-Version: 1.0 In-Reply-To: <558c48af114ba67b997489ce2a150ffa1b7f5a22.1553088664.git.kshcherbatov@tarantool.org> Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-US Content-Transfer-Encoding: 7bit Sender: tarantool-patches-bounce@freelists.org Errors-to: tarantool-patches-bounce@freelists.org Reply-To: tarantool-patches@freelists.org List-Help: List-Unsubscribe: List-software: Ecartis version 1.0.0 List-Id: tarantool-patches List-Subscribe: List-Owner: List-post: List-Archive: To: Kirill Shcherbatov , tarantool-patches@freelists.org, Kirill Yukhin LGTM. On 20/03/2019 16:31, Kirill Shcherbatov wrote: > Previously, all tuples created with frommap() used default format > table_format_runtime, and therefore the created data tuples were > not checked for the ability to be inserted into the target space. > > Moreover frommap(...):tomap(...) procedures sequence also did not > work because tomap(..) routine assumes that the tuple has format > with field names. > > Closes #4045 > > Branch: http://github.com/tarantool/tarantool/tree/kshch/gh-4045-frommap-tuple-format-fix > Issue: https://github.com/tarantool/tarantool/issues/4045 > --- > src/box/lua/space.cc | 2 +- > src/box/lua/tuple.c | 11 ++++++++--- > src/box/lua/tuple.h | 3 ++- > test/box/tuple.result | 25 +++++++++++++++++++++---- > test/box/tuple.test.lua | 12 +++++++++--- > 5 files changed, 41 insertions(+), 12 deletions(-) > > diff --git a/src/box/lua/space.cc b/src/box/lua/space.cc > index 7aa0b6661..9dfc97b6a 100644 > --- a/src/box/lua/space.cc > +++ b/src/box/lua/space.cc > @@ -510,7 +510,7 @@ lbox_space_frommap(struct lua_State *L) > > lua_replace(L, 1); > lua_settop(L, 1); > - return lbox_tuple_new(L); > + return luaT_tuple_new(L, space->format); > usage_error: > return luaL_error(L, "Usage: space:frommap(map, opts)"); > } > diff --git a/src/box/lua/tuple.c b/src/box/lua/tuple.c > index 5f2bfc807..60c1a3999 100644 > --- a/src/box/lua/tuple.c > +++ b/src/box/lua/tuple.c > @@ -94,7 +94,7 @@ luaT_istuple(struct lua_State *L, int narg) > } > > int > -lbox_tuple_new(lua_State *L) > +luaT_tuple_new(struct lua_State *L, struct tuple_format *format) > { > int argc = lua_gettop(L); > if (argc < 1) { > @@ -120,8 +120,7 @@ lbox_tuple_new(lua_State *L) > } > mpstream_flush(&stream); > > - box_tuple_format_t *fmt = box_tuple_format_default(); > - struct tuple *tuple = box_tuple_new(fmt, buf->buf, > + struct tuple *tuple = box_tuple_new(format, buf->buf, > buf->buf + ibuf_used(buf)); > if (tuple == NULL) > return luaT_error(L); > @@ -131,6 +130,12 @@ lbox_tuple_new(lua_State *L) > return 1; > } > > +static int > +lbox_tuple_new(lua_State *L) > +{ > + return luaT_tuple_new(L, box_tuple_format_default()); > +} > + > static int > lbox_tuple_gc(struct lua_State *L) > { > diff --git a/src/box/lua/tuple.h b/src/box/lua/tuple.h > index 5d7062eb8..ba7f01f4b 100644 > --- a/src/box/lua/tuple.h > +++ b/src/box/lua/tuple.h > @@ -37,6 +37,7 @@ extern "C" { > #endif /* defined(__cplusplus) */ > > struct tuple; > +struct tuple_format; > typedef struct tuple box_tuple_t; > struct lua_State; > struct mpstream; > @@ -67,7 +68,7 @@ luaT_istuple(struct lua_State *L, int idx); > /** \endcond public */ > > int > -lbox_tuple_new(struct lua_State *L); > +luaT_tuple_new(struct lua_State *L, struct tuple_format *format); > > static inline int > luaT_pushtupleornil(struct lua_State *L, struct tuple *tuple) > diff --git a/test/box/tuple.result b/test/box/tuple.result > index 16aa66b1a..82ad8404d 100644 > --- a/test/box/tuple.result > +++ b/test/box/tuple.result > @@ -1069,13 +1069,13 @@ format = {} > format[1] = {name = 'aaa', type = 'unsigned'} > --- > ... > -format[2] = {name = 'bbb', type = 'unsigned'} > +format[2] = {name = 'bbb', type = 'unsigned', is_nullable = true} > --- > ... > -format[3] = {name = 'ccc', type = 'unsigned'} > +format[3] = {name = 'ccc', type = 'unsigned', is_nullable = true} > --- > ... > -format[4] = {name = 'ddd', type = 'unsigned'} > +format[4] = {name = 'ddd', type = 'unsigned', is_nullable = true} > --- > ... > s = box.schema.create_space('test', {format = format}) > @@ -1100,7 +1100,7 @@ s:frommap() > ... > s:frommap({}) > --- > -- [] > +- error: Tuple field 1 required by space format is missing > ... > s:frommap({ddd = 1, aaa = 2, ccc = 3, bbb = 4}, {table = true}) > --- > @@ -1211,6 +1211,23 @@ s2:frommap({a="1", k="11"}) > --- > - ['1', null, null, null, null, null, null, null, null, null, '11'] > ... > +-- > +-- gh-4045: space:frommap():tomap() conversion fail > +-- > +s2:frommap({a="1", k="11"}):tomap({names_only = true}) > +--- > +- i: null > + f: null > + c: null > + g: null > + b: null > + j: null > + k: '11' > + d: null > + h: null > + a: '1' > + e: null > +... > s2:drop() > --- > ... > diff --git a/test/box/tuple.test.lua b/test/box/tuple.test.lua > index 0c89feace..8030b0884 100644 > --- a/test/box/tuple.test.lua > +++ b/test/box/tuple.test.lua > @@ -354,9 +354,9 @@ box.tuple.bsize == t.bsize > -- > format = {} > format[1] = {name = 'aaa', type = 'unsigned'} > -format[2] = {name = 'bbb', type = 'unsigned'} > -format[3] = {name = 'ccc', type = 'unsigned'} > -format[4] = {name = 'ddd', type = 'unsigned'} > +format[2] = {name = 'bbb', type = 'unsigned', is_nullable = true} > +format[3] = {name = 'ccc', type = 'unsigned', is_nullable = true} > +format[4] = {name = 'ddd', type = 'unsigned', is_nullable = true} > s = box.schema.create_space('test', {format = format}) > s:frommap({ddd = 1, aaa = 2, ccc = 3, bbb = 4}) > s:frommap({ddd = 1, aaa = 2, bbb = 3}) > @@ -409,4 +409,10 @@ s2:format({{name="a", type="str"}, {name="b", type="str", is_nullable=true}, > {name="k", type="str", is_nullable=true}}); > test_run:cmd("setopt delimiter ''"); > s2:frommap({a="1", k="11"}) > + > +-- > +-- gh-4045: space:frommap():tomap() conversion fail > +-- > +s2:frommap({a="1", k="11"}):tomap({names_only = true}) > + > s2:drop() > -- > 2.21.0 >