1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58
|
utils = dofile('utils.lua')
hash = box.schema.space.create('tweedledum')
tmp = hash:create_index('primary', { type = 'hash', parts = {1, 'unsigned', 2, 'string', 3, 'unsigned'}, unique = true })
tmp = hash:create_index('unique', { type = 'hash', parts = {3, 'unsigned', 5, 'unsigned'}, unique = true })
-- insert rows
hash:insert{0, 'foo', 0, '', 1}
hash:insert{0, 'foo', 1, '', 1}
hash:insert{1, 'foo', 0, '', 2}
hash:insert{1, 'foo', 1, '', 2}
hash:insert{0, 'bar', 0, '', 3}
hash:insert{0, 'bar', 1, '', 3}
hash:insert{1, 'bar', 0, '', 4}
hash:insert{1, 'bar', 1, '', 4}
-- try to insert a row with a duplicate key
hash:insert{1, 'bar', 1, '', 5}
-- output all rows
env = require('test_run')
test_run = env.new()
test_run:cmd("setopt delimiter ';'")
function select_all()
local result = {}
local tuple, v
for tuple, v in hash:pairs() do
table.insert(result, v)
end
return result
end;
test_run:cmd("setopt delimiter ''");
utils.sort(select_all())
select_all = nil
-- primary index select
hash.index['primary']:get{1, 'foo', 0}
hash.index['primary']:get{1, 'bar', 0}
-- primary index select with missing part
hash.index['primary']:get{1, 'foo'}
-- primary index select with extra part
hash.index['primary']:get{1, 'foo', 0, 0}
-- primary index select with wrong type
hash.index['primary']:get{1, 'foo', 'baz'}
-- secondary index select
hash.index['unique']:get{1, 4}
-- secondary index select with no such key
hash.index['unique']:get{1, 5}
-- secondary index select with missing part
hash.index['unique']:get{1}
-- secondary index select with wrong type
hash.index['unique']:select{1, 'baz'}
-- cleanup
hash:truncate()
hash:len()
hash:drop()
|