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 989B72A12C for ; Tue, 27 Mar 2018 06:14:35 -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 Rif8fsDtNPWK for ; Tue, 27 Mar 2018 06:14:35 -0400 (EDT) Received: from smtp40.i.mail.ru (smtp40.i.mail.ru [94.100.177.100]) (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 59B602A043 for ; Tue, 27 Mar 2018 06:14:35 -0400 (EDT) Content-Type: text/plain; charset=utf-8 Mime-Version: 1.0 (Mac OS X Mail 11.2 \(3445.5.20\)) Subject: [tarantool-patches] Re: [PATCH v2 1/1] tuple:tomap: only_names option From: "v.shpilevoy@tarantool.org" In-Reply-To: <9131f9838c0bed9b459a974ed07ffd0a8817ca88.1522145167.git.kshcherbatov@tarantool.org> Date: Tue, 27 Mar 2018 13:14:31 +0300 Content-Transfer-Encoding: quoted-printable Message-Id: <2169D9B3-D807-4BF1-9996-EB5E60B70BFB@tarantool.org> References: <9131f9838c0bed9b459a974ed07ffd0a8817ca88.1522145167.git.kshcherbatov@tarantool.org> 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: tarantool-patches@freelists.org Cc: Kirill Shcherbatov See below 5 comments. > 27 =D0=BC=D0=B0=D1=80=D1=82=D0=B0 2018 =D0=B3., =D0=B2 13:06, Kirill = Shcherbatov =D0=BD=D0=B0=D0=BF=D0=B8=D1=81=D0= =B0=D0=BB(=D0=B0): >=20 > Fixes #3280 > --- > src/box/lua/tuple.c | 23 ++++++++++++++++++++--- > test/engine/tuple.result | 45 = +++++++++++++++++++++++++++++++++++++++++++++ > test/engine/tuple.test.lua | 14 ++++++++++++++ > 3 files changed, 79 insertions(+), 3 deletions(-) >=20 > diff --git a/src/box/lua/tuple.c b/src/box/lua/tuple.c > index d5ed7c4..da2a80b 100644 > --- a/src/box/lua/tuple.c > +++ b/src/box/lua/tuple.c > @@ -280,9 +280,21 @@ luamp_encode_extension_box(struct lua_State *L, = int idx, > static int > lbox_tuple_to_map(struct lua_State *L) > { > - if (lua_gettop(L) < 1) > - luaL_error(L, "Usage: tuple:tomap()"); > - const struct tuple *tuple =3D lua_checktuple(L, 1); > + int argc =3D lua_gettop(L); > + if (argc < 1 || argc > 2) > + goto error; > + int names_only =3D 0; > + if (argc =3D=3D 2) { > + if (!lua_istable(L, 2)) > + goto error; > + lua_getfield(L, 2, "names_only"); > + if (!lua_isboolean(L, -1)) > + goto error; > + names_only =3D lua_toboolean(L, -1); > + lua_pop(L, 1); 1. Seems that you fixed only indentation. Please, fix other comments = too. > + } > + > + const struct tuple *tuple =3D lua_checktuple(L, 1); > const struct tuple_format *format =3D tuple_format(tuple); > const struct tuple_field *field =3D &format->fields[0]; > const char *pos =3D tuple_data(tuple); > @@ -294,6 +306,8 @@ lbox_tuple_to_map(struct lua_State *L) > lua_pushstring(L, field->name); > luamp_decode(L, luaL_msgpack_default, &pos); > lua_rawset(L, -3); > + if (names_only) > + continue; > /* > * Access the same field by an index. There is no > * copy for tables - lua optimizes it and uses > @@ -309,6 +323,9 @@ lbox_tuple_to_map(struct lua_State *L) > lua_rawseti(L, -2, i + TUPLE_INDEX_BASE); > } > return 1; > +error: > + luaL_error(L, "Usage: tuple:tomap() or tuple:tomap({names_only =3D= true})"); > + return 1; > } >=20 > /** >=20 > diff --git a/test/engine/tuple.test.lua b/test/engine/tuple.test.lua > index 6d7d254..0f139a3 100644 > --- a/test/engine/tuple.test.lua > +++ b/test/engine/tuple.test.lua > @@ -200,5 +200,19 @@ t1map =3D t1:tomap() > maplen(t1map), t1map[1], t1map[2], t1map[3] > s:drop() >=20 > +-- > +-- gh-2821: tuple:tomap() names_only feature. > +-- > +subscriber =3D box.schema.space.create('subscriber') > +box.schema.user.grant('guest','read,write,execute','space', = 'subscriber') 2. You do not need rights, when work locally. > +subscriber:format({{'contract_id', 'integer'}, {'subscriber_id', = 'integer'}, {'phone', 'string'}, {'subscriber_status_id', 'integer'}, }) > +idx =3D subscriber:create_index('primary', {parts=3D{'contract_id', = 'subscriber_id'}}) > +--subscriber:create_index('phone', {parts=3D{'phone'}, unique =3D = false }) 3. Please, do not put a code in comment. If you do not need it, then = just delete. > +subscriber:replace({1, 1, '79160000000', 42}) > +t =3D subscriber:get({1, 1}) 4. replace() returns a result tuple, so you can just do t =3D = subscriber:replace(), with no get(). > +t:tomap({names_only =3D false}) > +t:tomap({names_only =3D true}) 5. Like I wrote in the previous review, please, add tests on tomap with = invalid options, on tomap with names_only =3D non-boolean, on tomap with = empty options. Do not hurry so much. > +s:drop() > + > engine =3D nil > test_run =3D nil > --=20 > 2.7.4 >=20 >=20