From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Date: Thu, 10 Jan 2019 13:21:06 +0300 From: Vladimir Davydov Subject: Re: [PATCH v7 5/5] box: specify indexes in user-friendly form Message-ID: <20190110102106.5kb6y7hhyifpsehy@esperanza> References: <6e7ca7dcfd69ce7f9cc787490f2c32a1ab2ad37c.1547022001.git.kshcherbatov@tarantool.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <6e7ca7dcfd69ce7f9cc787490f2c32a1ab2ad37c.1547022001.git.kshcherbatov@tarantool.org> To: Kirill Shcherbatov Cc: tarantool-patches@freelists.org, kostja@tarantool.org List-ID: On Wed, Jan 09, 2019 at 11:29:40AM +0300, Kirill Shcherbatov wrote: > Implemented a more convenient interface for creating an index > by JSON path. Instead of specifying fieldno and relative path > it comes possible to pass full JSON path to data. > > Closes #1012 > > @TarantoolBot document > Title: Indexes by JSON path > Sometimes field data could have complex document structure. > When this structure is consistent across whole document, > you are able to create an index by JSON path. > > Example: > s = box.schema.space.create('sample') > format = {{'id', 'unsigned'}, {'data', 'map'}} > s:format(format) > -- explicit JSON index creation > age_idx = s:create_index('age', {{2, 'number', path = ".age"}}) > -- user-friendly syntax for JSON index creation > parts = {{'data.FIO["fname"]', 'str'}, {'data.FIO["sname"]', 'str'}, > {'data.age', 'number'}} > info_idx = s:create_index('info', {parts = parts}}) > s:insert({1, {FIO={fname="James", sname="Bond"}, age=35}}) > --- > src/box/lua/index.c | 64 +++++++++++++++++++++++++++++++++++++++ > src/box/lua/schema.lua | 22 +++++++------- > test/engine/json.result | 28 +++++++++++++++++ > test/engine/json.test.lua | 8 +++++ > 4 files changed, 111 insertions(+), 11 deletions(-) > > diff --git a/src/box/lua/index.c b/src/box/lua/index.c > index 6265c044a..9b04c5d9a 100644 > --- a/src/box/lua/index.c > +++ b/src/box/lua/index.c > @@ -35,6 +35,9 @@ > #include "box/box.h" > #include "box/index.h" > #include "box/lua/tuple.h" > +#include "box/schema.h" > +#include "box/tuple_format.h" > +#include "json/json.h" > #include "box/lua/misc.h" /* lbox_encode_tuple_on_gc() */ > > /** {{{ box.index Lua library: access to spaces and indexes > @@ -328,6 +331,66 @@ lbox_index_compact(lua_State *L) > return 0; > } > > +/** > + * Resolve field index by absolute JSON path first component and > + * return relative JSON path. > + */ > +static int > +lbox_index_path_resolve(struct lua_State *L) > +{ > + if (lua_gettop(L) != 3 || > + !lua_isnumber(L, 1) || !lua_isnumber(L, 2) || !lua_isstring(L, 3)) { > + return luaL_error(L, "Usage box.internal." > + "path_resolve(part_id, space_id, path)"); > + } > + uint32_t part_id = lua_tonumber(L, 1); > + uint32_t space_id = lua_tonumber(L, 2); Are you kidding me? You silently ignored my comments to this patch TWICE! https://www.freelists.org/post/tarantool-patches/PATCH-v6-88-box-specify-indexes-in-userfriendly-form,1