Tarantool development patches archive
 help / color / mirror / Atom feed
From: "v.shpilevoy@tarantool.org" <v.shpilevoy@tarantool.org>
To: tarantool-patches@freelists.org
Cc: Kirill Shcherbatov <kshcherbatov@tarantool.org>
Subject: [tarantool-patches] Re: [PATCH v2 1/1] tuple:tomap: only_names option
Date: Tue, 27 Mar 2018 13:14:31 +0300	[thread overview]
Message-ID: <2169D9B3-D807-4BF1-9996-EB5E60B70BFB@tarantool.org> (raw)
In-Reply-To: <9131f9838c0bed9b459a974ed07ffd0a8817ca88.1522145167.git.kshcherbatov@tarantool.org>

See below 5 comments.

> 27 марта 2018 г., в 13:06, Kirill Shcherbatov <kshcherbatov@tarantool.org> написал(а):
> 
> 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(-)
> 
> 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 = lua_checktuple(L, 1);
> +    int argc = lua_gettop(L);
> +	if (argc < 1 || argc > 2)
> +		goto error;
> +	int names_only = 0;
> +	if (argc == 2) {
> +		if (!lua_istable(L, 2))
> +			goto error;
> +		lua_getfield(L, 2, "names_only");
> +		if (!lua_isboolean(L, -1))
> +			goto error;
> +		names_only = lua_toboolean(L, -1);
> +		lua_pop(L, 1);

1. Seems that you fixed only indentation. Please, fix other comments too.

> +    }
> +
> +    const struct tuple *tuple = lua_checktuple(L, 1);
> 	const struct tuple_format *format = tuple_format(tuple);
> 	const struct tuple_field *field = &format->fields[0];
> 	const char *pos = 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 = true})");
> +	return 1;
> }
> 
> /**
> 
> 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 = t1:tomap()
> maplen(t1map), t1map[1], t1map[2], t1map[3]
> s:drop()
> 
> +--
> +-- gh-2821: tuple:tomap() names_only feature.
> +--
> +subscriber = 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 = subscriber:create_index('primary', {parts={'contract_id', 'subscriber_id'}})
> +--subscriber:create_index('phone', {parts={'phone'}, unique = 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 = subscriber:get({1, 1})

4. replace() returns a result tuple, so you can just do t = subscriber:replace(), with no get().

> +t:tomap({names_only = false})
> +t:tomap({names_only = true})

5. Like I wrote in the previous review, please, add tests on tomap with invalid options, on tomap with names_only = non-boolean, on tomap with empty options. Do not hurry so much.

> +s:drop()
> +
> engine = nil
> test_run = nil
> -- 
> 2.7.4
> 
> 

  reply	other threads:[~2018-03-27 10:14 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-03-27 10:06 [tarantool-patches] " Kirill Shcherbatov
2018-03-27 10:14 ` v.shpilevoy [this message]
2018-03-27 10:28   ` [tarantool-patches] " Kirill Shcherbatov
     [not found] <b9c53caf-7c00-6bef-3e90-c71f519553fe@tarantool.org>
2018-03-27 15:00 ` [tarantool-patches] " Kirill Shcherbatov
2018-03-27 15:34   ` [tarantool-patches] " v.shpilevoy
2018-03-28  8:01     ` Kirill Shcherbatov
2018-03-28  8:05       ` Kirill Shcherbatov
2018-03-28  8:16         ` v.shpilevoy
2018-03-28 10:20           ` Vladimir Davydov

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=2169D9B3-D807-4BF1-9996-EB5E60B70BFB@tarantool.org \
    --to=v.shpilevoy@tarantool.org \
    --cc=kshcherbatov@tarantool.org \
    --cc=tarantool-patches@freelists.org \
    --subject='[tarantool-patches] Re: [PATCH v2 1/1] tuple:tomap: only_names option' \
    /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