File: iterator.test.lua

package info (click to toggle)
tarantool 2.6.0-1.4
  • links: PTS, VCS
  • area: main
  • in suites: sid, trixie
  • size: 85,412 kB
  • sloc: ansic: 513,775; cpp: 69,493; sh: 25,650; python: 19,190; perl: 14,973; makefile: 4,178; yacc: 1,329; sql: 1,074; pascal: 620; ruby: 190; awk: 18; lisp: 7
file content (127 lines) | stat: -rw-r--r-- 4,696 bytes parent folder | download | duplicates (5)
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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
iterate = dofile('utils.lua').iterate

test_run = require('test_run').new()
test_run:cmd("push filter '(error: .builtin/.*[.]lua):[0-9]+' to '\\1'")
# Tree single-part unique

space = box.schema.space.create('tweedledum')
idx1 = space:create_index('primary', { type = 'tree', parts = {1, 'string'}, unique = true})
-- Hash single-part unique
idx5 = space:create_index('i4', { type = 'hash', parts = {1, 'string'}, unique = true})
-- Hash multi-part unique
idx6 = space:create_index('i5', { type = 'hash', parts = {2, 'string', 3, 'string'}, unique = true})

space:insert{'pid_001', 'sid_001', 'tid_998', 'a'}
space:insert{'pid_002', 'sid_001', 'tid_997', 'a'}
space:insert{'pid_003', 'sid_002', 'tid_997', 'b'}
space:insert{'pid_005', 'sid_002', 'tid_996', 'b'}
space:insert{'pid_007', 'sid_003', 'tid_996', 'a'}
space:insert{'pid_011', 'sid_004', 'tid_996', 'c'}
space:insert{'pid_013', 'sid_005', 'tid_996', 'b'}
space:insert{'pid_017', 'sid_006', 'tid_996', 'a'}
space:insert{'pid_019', 'sid_005', 'tid_995', 'a'}
space:insert{'pid_023', 'sid_005', 'tid_994', 'a'}

-------------------------------------------------------------------------------
-- Iterator: hash single-part unique
-------------------------------------------------------------------------------

iterate('tweedledum', 'i4', 0, 1)
iterate('tweedledum', 'i4', 0, 1, box.index.ALL)
iterate('tweedledum', 'i4', 0, 1, box.index.EQ)
iterate('tweedledum', 'i4', 0, 1, box.index.EQ, 'pid_003')
iterate('tweedledum', 'i4', 0, 1, box.index.EQ, 'pid_666')

-------------------------------------------------------------------------------
-- Iterator: hash multi-part unique
-------------------------------------------------------------------------------

iterate('tweedledum', 'i5', 1, 3, box.index.ALL)
iterate('tweedledum', 'i5', 1, 3, box.index.EQ, 'sid_005')
iterate('tweedledum', 'i5', 1, 3, box.index.EQ, 'sid_005', 'tid_995')
iterate('tweedledum', 'i5', 1, 3, box.index.EQ, 'sid_005', 'tid_999')
iterate('tweedledum', 'i5', 1, 3, box.index.EQ, 'sid_005', 'tid_995', 'a')

space:drop()

-------------------------------------------------------------------------------
-- Iterator: https://github.com/tarantool/tarantool/issues/464
-- Iterator safety after changing schema
-------------------------------------------------------------------------------

space = box.schema.space.create('test', {temporary=true})
idx1 = space:create_index('primary', {type='HASH',unique=true})
idx2 = space:create_index('t1', {type='TREE',unique=true})
idx3 = space:create_index('t2', {type='TREE',unique=true})

box.space.test:insert{0}
box.space.test:insert{1}

gen1, param1, state1 = space.index.t1:pairs({}, {iterator = box.index.ALL})
gen1(param1, state1)

gen2, param2, state2 = space.index.t2:pairs({}, {iterator = box.index.ALL})
gen2(param2, state2)

id = space.index.t1.id
box.schema.index.drop(space.id, id)

gen1(param1, state1)
gen2(param2, state2)

gen2, param2, state2 = space.index.t2:pairs({}, {iterator = box.index.ALL})
gen2(param2, state2)
gen2(param2, state2)

space:drop()

-------------------------------------------------------------------------------
-- Iterator: https://github.com/tarantool/tarantool/issues/498
-- Iterator is not checked for wrong type; accept lowercase iterator
-------------------------------------------------------------------------------

space = box.schema.space.create('test', {temporary=true})
idx1 = 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()


-------------------------------------------------------------------------------
--  Restore GE iterator for HASH https://github.com/tarantool/tarantool/issues/836
-------------------------------------------------------------------------------
space = box.schema.space.create('test', {temporary=true})
idx1 = space:create_index('primary', {type='hash',unique=true})

for i = 0,5 do space:insert{i} end

space:select(2)
space:select(5, {iterator="GE"})
space:select(nil, {iterator="GE"})
space:select(5, {iterator="GT"})
l = space:select(nil, {limit=2, iterator="GT"})
l
l = space:select(l[#l][1], {limit=2, iterator="GT"})
l
l = space:select(l[#l][1], {limit=2, iterator="GT"})
l
l = space:select(l[#l][1], {limit=2, iterator="GT"})
l
space:drop()
iterate = nil