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 A402D28F91 for ; Tue, 21 Aug 2018 20:26:46 -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 OmC3v43Yj1Kz for ; Tue, 21 Aug 2018 20:26:46 -0400 (EDT) Received: from smtp50.i.mail.ru (smtp50.i.mail.ru [94.100.177.110]) (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 11EE828F33 for ; Tue, 21 Aug 2018 20:26:45 -0400 (EDT) Subject: [tarantool-patches] Re: [PATCH v2 5/5] box: specify indexes in user-friendly form References: <85e01e1462538960a3d14276c6cdb1ebbccad43f.1534332920.git.kshcherbatov@tarantool.org> From: Vladislav Shpilevoy Message-ID: <3b72613d-51ba-0494-757d-bfb44fd87997@tarantool.org> Date: Wed, 22 Aug 2018 03:26:41 +0300 MIME-Version: 1.0 In-Reply-To: <85e01e1462538960a3d14276c6cdb1ebbccad43f.1534332920.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 Thanks for the patch! See 3 comments below. On 15/08/2018 15:15, Kirill Shcherbatov wrote: > Since now it is possible to create indexes by JSON-path > using field names specified in format. > > @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:create_index('json_index', > {parts = {{'data.FIO["fname"]', 'str'}}}) > > Part of #1012. > --- > src/box/lua/schema.lua | 58 +++++++++++++++++++++++++++++++++++++++------ > test/engine/iterator.result | 2 +- > test/engine/tuple.result | 36 ++++++++++++++++++++++++++++ > test/engine/tuple.test.lua | 10 ++++++++ > 4 files changed, 98 insertions(+), 8 deletions(-) > > diff --git a/src/box/lua/schema.lua b/src/box/lua/schema.lua > index b9b8c90..62b83aa 100644 > --- a/src/box/lua/schema.lua > +++ b/src/box/lua/schema.lua > @@ -556,6 +556,48 @@ local function update_index_parts_1_6_0(parts) > return result > end > > +local function format_field_index_by_name(format, name) > + for k,v in pairs(format) do > + if v.name == name then > + return k > + end > + end > + return nil > +end > + > +local function format_field_resolve(format, name) > + local idx = nil > + local field_name = nil > + -- try resolve whole name > + idx = format_field_index_by_name(format, name) > + if idx ~= nil then > + return idx, nil > + end > + -- try resolve field by name > + field_name = string.match(name, "^[a-z][a-z,0-9]*") > + if field_name ~= nil then > + idx = format_field_index_by_name(format, field_name) > + local suffix = string.sub(name, string.len(field_name) + 2) > + if idx ~= nil and suffix ~= nil then > + return idx, string.format("[%d]%s", idx, suffix) > + end > + -- simplified json_path > + return idx, nil > + end > + -- try resolve field by index > + field_name = string.match(name, "^%[[0-9]*%]") > + if field_name ~= nil then > + idx = tonumber(string.sub(field_name, 2, -2)) > + local suffix = string.sub(name, string.len(field_name) + 2) > + if suffix == nil then > + -- simplified json_path > + return idx, nil > + end > + return idx, name > + end > + return nil, nil > +end 1. Please, write comments. 2. Start a sentence with a capital letter and finish with the dot. 3. Please, move this routes to C and use tuple_dictionary + json path parser. > + > local function update_index_parts(format, parts) > if type(parts) ~= "table" then > box.error(box.error.ILLEGAL_PARAMS,