Tarantool development patches archive
 help / color / mirror / Atom feed
From: Vladislav Shpilevoy <v.shpilevoy@tarantool.org>
To: Kirill Shcherbatov <kshcherbatov@tarantool.org>,
	tarantool-patches@freelists.org
Subject: [tarantool-patches] Re: [PATCH v2 5/5] box: specify indexes in user-friendly form
Date: Wed, 22 Aug 2018 03:26:41 +0300	[thread overview]
Message-ID: <3b72613d-51ba-0494-757d-bfb44fd87997@tarantool.org> (raw)
In-Reply-To: <85e01e1462538960a3d14276c6cdb1ebbccad43f.1534332920.git.kshcherbatov@tarantool.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,

  reply	other threads:[~2018-08-22  0:26 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-08-15 12:14 [tarantool-patches] [PATCH v2 0/5] box: indexes by JSON path Kirill Shcherbatov
2018-08-15 12:14 ` [tarantool-patches] [PATCH v2 1/5] rfc: describe a Tarantool JSON indexes Kirill Shcherbatov
2018-08-15 12:15 ` [tarantool-patches] [PATCH v2 2/5] box: introduce slot_cache in key_part Kirill Shcherbatov
2018-08-22  0:27   ` [tarantool-patches] " Vladislav Shpilevoy
2018-08-27  7:37     ` Kirill Shcherbatov
2018-09-03 10:32       ` Vladislav Shpilevoy
2018-08-15 12:15 ` [tarantool-patches] [PATCH v2 3/5] box: introduce path field " Kirill Shcherbatov
2018-08-22  0:26   ` [tarantool-patches] " Vladislav Shpilevoy
2018-08-27  7:37     ` Kirill Shcherbatov
2018-08-15 12:15 ` [tarantool-patches] [PATCH v2 4/5] box: introduce path_hash and tuple_field tree Kirill Shcherbatov
2018-08-22  0:26   ` [tarantool-patches] " Vladislav Shpilevoy
2018-08-27  7:37     ` Kirill Shcherbatov
2018-08-15 12:15 ` [tarantool-patches] [PATCH v2 5/5] box: specify indexes in user-friendly form Kirill Shcherbatov
2018-08-22  0:26   ` Vladislav Shpilevoy [this message]
2018-08-27  7:37     ` [tarantool-patches] " Kirill Shcherbatov
2018-08-22  0:28   ` Vladislav Shpilevoy

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=3b72613d-51ba-0494-757d-bfb44fd87997@tarantool.org \
    --to=v.shpilevoy@tarantool.org \
    --cc=kshcherbatov@tarantool.org \
    --cc=tarantool-patches@freelists.org \
    --subject='[tarantool-patches] Re: [PATCH v2 5/5] box: specify indexes in user-friendly form' \
    /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