Skip to content
Snippets Groups Projects
Commit 47d7d501 authored by Konstantin Osipov's avatar Konstantin Osipov
Browse files

Merge branch 'fix-gh-498'

parents bdcc5658 637d60b9
No related branches found
No related tags found
No related merge requests found
......@@ -566,16 +566,19 @@ function box.schema.space.bless(space)
end
-- iteration
index_mt.pairs = function(index, key, opts)
check_param_table(opts, {iterator = 'number,string'});
local pkey, pkey_end = msgpackffi.encode_tuple(key)
-- Use ALL for {} and nil keys and EQ for other keys
local itype = pkey + 1 < pkey_end and box.index.EQ or box.index.ALL
if opts then
if opts and opts.iterator then
if type(opts.iterator) == "number" then
itype = opts.iterator
elseif box.index[opts.iterator] then
itype = box.index[opts.iterator]
elseif opts.iterator ~= nil then
box.error(box.error.ITERATOR_TYPE, tostring(opts.iterator))
elseif type(opts.iterator) == "string" then
itype = box.index[string.upper(opts.iterator)]
if itype == nil then
box.error(box.error.ITERATOR_TYPE, opts.iterator)
end
end
end
......@@ -635,33 +638,36 @@ function box.schema.space.bless(space)
end
index_mt.select = function(index, key, opts)
local offset = 0
local limit = 4294967295
local iterator = box.index.EQ
local options_template = {
offset = 'number',
limit = 'number',
iterator = 'number,string',
}
check_param_table(opts, options_template);
local options_defaults = {
offset = 0,
limit = 4294967295,
iterator = box.index.EQ,
}
local key, key_end = msgpackffi.encode_tuple(key)
if key_end == key + 1 then -- empty array
iterator = box.index.ALL
options_defaults.iterator = box.index.ALL
end
opts = update_param_table(opts, options_defaults)
if opts ~= nil then
if opts.offset ~= nil then
offset = opts.offset
end
if type(opts.iterator) == "string" then
opts.iterator = box.index[opts.iterator]
end
if opts.iterator ~= nil then
iterator = opts.iterator
end
if opts.limit ~= nil then
limit = opts.limit
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
port.size = 0;
if builtin.boxffi_select(ffi.cast(port_t, port), index.space.id,
index.id, iterator, offset, limit, key, key_end) ~=0 then
local space_id = index.space.id
if builtin.boxffi_select(ffi.cast(port_t, port), space_id, index.id,
opts.iterator, opts.offset, opts.limit, key, key_end) ~= 0 then
return box.error()
end
......
......@@ -938,8 +938,10 @@ box.space.test:insert{1}
gen, param, state = space.index.t1:pairs({}, {iterator = box.index.ALL})
---
...
print(gen(param, state))
gen(param, state)
---
- <iterator state>
- [0]
...
id = space.index.t1.id
---
......@@ -950,8 +952,78 @@ box.schema.index.drop(space.id, id)
box.schema.index.alter(space.id, space.index.t2.id, {id = id})
---
...
print(gen(param, state))
gen(param, state)
---
- null
...
space:drop()
---
...
-------------------------------------------------------------------------------
-- Iterator: https://github.com/tarantool/tarantool/issues/498
-- Iterator is not checked for wrong type; accept lowercase iterator
-------------------------------------------------------------------------------
space = box.schema.create_space('test', {temporary=true})
---
...
space:create_index('primary', {type='TREE',unique=true})
---
...
space:insert{0}
---
- [0]
...
space:insert{1}
---
- [1]
...
gen, param, state = space.index.primary:pairs({}, {iterator = 'ALL'})
---
...
gen(param, state)
---
- <iterator state>
- [0]
...
gen(param, state)
---
- <iterator state>
- [1]
...
gen(param, state)
---
- null
...
gen, param, state = space.index.primary:pairs({}, {iterator = 'all'})
---
...
gen(param, state)
---
- <iterator state>
- [0]
...
gen(param, state)
---
- <iterator state>
- [1]
...
gen, param, state = space.index.primary:pairs({}, {iterator = 'mistake'})
---
- error: Unknown iterator type 'mistake'
...
space:select({}, {iterator = box.index.ALL})
---
- - [0]
- [1]
...
space:select({}, {iterator = 'all'})
---
- - [0]
- [1]
...
space:select({}, {iterator = 'mistake'})
---
- error: Unknown iterator type 'mistake'
...
space:drop()
---
......
......@@ -184,13 +184,40 @@ box.space.test:insert{0}
box.space.test:insert{1}
gen, param, state = space.index.t1:pairs({}, {iterator = box.index.ALL})
print(gen(param, state))
gen(param, state)
id = space.index.t1.id
box.schema.index.drop(space.id, id)
box.schema.index.alter(space.id, space.index.t2.id, {id = id})
print(gen(param, state))
gen(param, state)
space:drop()
-------------------------------------------------------------------------------
-- Iterator: https://github.com/tarantool/tarantool/issues/498
-- Iterator is not checked for wrong type; accept lowercase iterator
-------------------------------------------------------------------------------
space = box.schema.create_space('test', {temporary=true})
space:create_index('primary', {type='TREE',unique=true})
space:insert{0}
space:insert{1}
gen, param, state = space.index.primary:pairs({}, {iterator = 'ALL'})
gen(param, state)
gen(param, state)
gen(param, state)
gen, param, state = space.index.primary:pairs({}, {iterator = 'all'})
gen(param, state)
gen(param, state)
gen, param, state = space.index.primary:pairs({}, {iterator = 'mistake'})
space:select({}, {iterator = box.index.ALL})
space:select({}, {iterator = 'all'})
space:select({}, {iterator = 'mistake'})
space:drop()
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment