From cbb3d9b2c449d4eb2f9f13f6edf09e3c5b48028e Mon Sep 17 00:00:00 2001 From: Roman Tsisyk <roman@tsisyk.com> Date: Tue, 26 May 2015 15:07:06 +0300 Subject: [PATCH] Fix #841: net.box uses incorrect iterator type for select without args --- src/box/lua/schema.lua | 17 +++-------------- src/lua/net_box.lua | 16 ++++------------ test/box/net.box.result | 8 +++++++- test/box/net.box.test.lua | 2 ++ test/box/sql.result | 2 +- 5 files changed, 17 insertions(+), 28 deletions(-) diff --git a/src/box/lua/schema.lua b/src/box/lua/schema.lua index 22b43517ec..d083db8241 100644 --- a/src/box/lua/schema.lua +++ b/src/box/lua/schema.lua @@ -579,6 +579,8 @@ local function check_iterator_type(opts, key_is_nil) return itype end +internal.check_iterator_type = check_iterator_type -- export for net.box + function box.schema.space.bless(space) local index_mt = {} -- __len and __index @@ -684,27 +686,14 @@ function box.schema.space.bless(space) index_mt.select = function(index, key, opts) local offset = 0 local limit = 4294967295 - local iterator = box.index.EQ local key, key_end = msgpackffi.encode_tuple(key) - if key_end == key + 1 then -- empty array - iterator = box.index.ALL - end + local iterator = check_iterator_type(opts, key + 1 >= key_end) if opts ~= nil then if opts.offset ~= nil then offset = opts.offset end - if type(opts.iterator) == "string" then - local resolved_iter = box.index[string.upper(opts.iterator)] - if resolved_iter == nil then - box.error(box.error.ITERATOR_TYPE, opts.iterator); - end - opts.iterator = resolved_iter - end - if opts.iterator ~= nil then - iterator = opts.iterator - end if opts.limit ~= nil then limit = opts.limit end diff --git a/src/lua/net_box.lua b/src/lua/net_box.lua index 0a16a6e831..549831dd86 100644 --- a/src/lua/net_box.lua +++ b/src/lua/net_box.lua @@ -186,10 +186,12 @@ local proto = { box.error(box.error.NO_SUCH_INDEX, indexno, '#'..tostring(spaceno)) end + key = keyfy(key) + local body = { [SPACE_ID] = spaceno, [INDEX_ID] = indexno, - [KEY] = keyfy(key) + [KEY] = key } if opts.limit ~= nil then @@ -203,17 +205,7 @@ local proto = { body[OFFSET] = 0 end - if opts.iterator ~= nil then - if type(opts.iterator) == 'string' then - local iterator = box.index[ opts.iterator ] - if iterator == nil then - box.error(box.error.ITERATOR_TYPE, tostring(opts.iterator)) - end - body[ITERATOR] = iterator - else - body[ITERATOR] = tonumber(opts.iterator) - end - end + body[ITERATOR] = require('box.internal').check_iterator_type(opts, #key == 0) return request( { [SYNC] = sync, [TYPE] = SELECT }, body ) end, diff --git a/test/box/net.box.result b/test/box/net.box.result index b9af7235e7..6f3f53d61e 100644 --- a/test/box/net.box.result +++ b/test/box/net.box.result @@ -232,7 +232,7 @@ cn.space.net_box_test_space:insert{234, 1,2,3} ... cn.space.net_box_test_space.insert{234, 1,2,3} --- -- error: 'builtin/net.box.lua:244: Use space:method(...) instead space.method(...)' +- error: 'builtin/net.box.lua:236: Use space:method(...) instead space.method(...)' ... cn.space.net_box_test_space:replace{354, 1,2,3} --- @@ -350,6 +350,12 @@ cn.space.net_box_test_space:select({}, { iterator = 'ALL' }) - - [234, 1, 2, 3] - [354, 1, 2, 4] ... +-- gh-841: net.box uses incorrect iterator type for select with no arguments +cn.space.net_box_test_space:select() +--- +- - [234, 1, 2, 3] + - [354, 1, 2, 4] +... cn.space.net_box_test_space.index.primary:min() --- - [234, 1, 2, 3] diff --git a/test/box/net.box.test.lua b/test/box/net.box.test.lua index 47cbda5ba9..e4ab82e424 100644 --- a/test/box/net.box.test.lua +++ b/test/box/net.box.test.lua @@ -114,6 +114,8 @@ cn.space.net_box_test_space:update(10, {{':', 2, -2, 0, '})'}}) cn.space.net_box_test_space:delete{10} cn.space.net_box_test_space:select({}, { iterator = 'ALL' }) +-- gh-841: net.box uses incorrect iterator type for select with no arguments +cn.space.net_box_test_space:select() cn.space.net_box_test_space.index.primary:min() cn.space.net_box_test_space.index.primary:min(354) diff --git a/test/box/sql.result b/test/box/sql.result index 1ce121dd4e..4bda0eb580 100644 --- a/test/box/sql.result +++ b/test/box/sql.result @@ -26,7 +26,7 @@ conn:ping() -- xxx: bug currently selects no rows space:select{} --- -- error: Invalid key part count in an exact match (expected 1, got 0) +- [] ... space:insert{1, 'I am a tuple'} --- -- GitLab