[PATCH v1 2/2] netbox: define formats for tuple from netbox

Vladimir Davydov vdavydov.dev at gmail.com
Tue Jun 18 12:00:42 MSK 2019


On Fri, Jun 14, 2019 at 03:29:21PM +0300, Mergen Imeev wrote:
> Second new patch:
> 
> From f9e959e3f0f38e8f6b8f1294ba29c28d41f30968 Mon Sep 17 00:00:00 2001
> Date: Tue, 11 Jun 2019 16:36:39 +0300
> Subject: [PATCH] netbox: define formats for tuple from netbox
> 
> This patch creates tuple_formats for the tuples obtained through
> the netbox.
> 
> Closes #2978
> 
> @TarantoolBot document
> Title: Field names for tuples received from net.box
> 
> It is possible now to access by field name for tuples received
> from net.box. For example:
> 
> box.cfg{listen = 3302}
> box.schema.user.grant('guest','read, write, execute', 'space')
> box.schema.user.grant('guest', 'create', 'space')
> 
> box.schema.create_space("named", {format = {{name = "id"}}})
> box.space.named:create_index('id', {parts = {{1, 'unsigned'}}})
> box.space.named:insert({1})
> require('net.box').connect('localhost', 3302).space.named:get(1).id
> 
> Result:
> 
> tarantool> require('net.box').connect('localhost', 3302).space.named:get(1).id
> ---
> - 1
> ...
> 
> diff --git a/src/box/lua/net_box.c b/src/box/lua/net_box.c
> index 7484a86..946d397 100644
> --- a/src/box/lua/net_box.c
> +++ b/src/box/lua/net_box.c
> @@ -590,12 +590,11 @@ netbox_encode_execute(lua_State *L)
>   * @param data MessagePack.
>   */
>  static void
> -netbox_decode_data(struct lua_State *L, const char **data)
> +netbox_decode_data(struct lua_State *L, const char **data,
> +		   struct tuple_format *format)
>  {
>  	uint32_t count = mp_decode_array(data);
>  	lua_createtable(L, count, 0);
> -	struct tuple_format *format =
> -		box_tuple_format_default();
>  	for (uint32_t j = 0; j < count; ++j) {
>  		const char *begin = *data;
>  		mp_next(data);
> @@ -618,6 +617,15 @@ static int
>  netbox_decode_select(struct lua_State *L)
>  {
>  	uint32_t ctypeid;
> +	int top = lua_gettop(L);
> +	assert(top == 1 || top == 2);
> +	struct tuple_format *format;
> +	if (top == 2 && lua_type(L, 2) == LUA_TCDATA) {
> +		format = *(struct tuple_format **)luaL_checkcdata(L, 2,
> +								  &ctypeid);

I think we should use lbox_check_tuple_format helper from the previous
patch here.

Other than that, this patch looks good to me.

> +	} else {
> +		format = tuple_format_runtime;
> +	}
>  	const char *data = *(const char **)luaL_checkcdata(L, 1, &ctypeid);
>  	assert(mp_typeof(*data) == MP_MAP);
>  	uint32_t map_size = mp_decode_map(&data);



More information about the Tarantool-patches mailing list