[tarantool-patches] Re: [PATCH v2 5/5] box: specify indexes in user-friendly form
Vladislav Shpilevoy
v.shpilevoy at tarantool.org
Wed Aug 22 03:26:41 MSK 2018
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,
More information about the Tarantool-patches
mailing list