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 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240
|
env = require('test_run')
test_run = env.new()
s = box.schema.space.create('spatial')
-- rtree index as primary key must be forbidden (unique)
i = s:create_index('spatial', { type = 'rtree', unique = true, parts = {1, 'array'}})
-- any non-unique index as primary key must be forbidden
i = s:create_index('spatial', { type = 'hash', unique = false, parts = {1, 'unsigned'}})
i = s:create_index('spatial', { type = 'tree', unique = false, parts = {1, 'unsigned'}})
i = s:create_index('spatial', { type = 'rtree', unique = false, parts = {1, 'array'}})
-- tree and hash indexes over array field is not possible
i = s:create_index('primary', { type = 'tree', parts = {1, 'array'}})
i = s:create_index('primary', { type = 'hash', parts = {1, 'array'}})
-- normal indexes
i = s:create_index('primary', { type = 'tree', parts = {1, 'unsigned'}})
i = s:create_index('secondary', { type = 'hash', parts = {2, 'unsigned'}})
-- adding a tuple with array instead of num will fail
i = s:insert{{1, 2, 3}, 4}
i = s:insert{1, {2, 3, 4}}
-- rtree index must be one-part
i = s:create_index('spatial', { type = 'rtree', unique = false, parts = {1, 'array', 2, 'array'}})
-- unique rtree index is not possible
i = s:create_index('spatial', { type = 'rtree', unique = true, parts = {3, 'array'}})
-- num rtree index is not possible
i = s:create_index('spatial', { type = 'rtree', unique = false, parts = {3, 'unsigned'}})
-- str rtree index is not possible
i = s:create_index('spatial', { type = 'rtree', unique = false, parts = {3, 'string'}})
-- normal rtree index
i = s:create_index('spatial', { type = 'rtree', unique = false, parts = {3, 'array'}})
-- inserting wrong values (should fail)
s:insert{1, 2, 3}
s:insert{1, 2, "3"}
s:insert{1, 2, nil, 3}
s:insert{1, 2, {}}
s:insert{1, 2, {"3", "4", "5", "6"}}
s:insert{1, 2, {nil, 4, 5, 6}}
s:insert{1, 2, {3, {4}, 5, 6}}
s:insert{1, 2, {3, 4, {}, 6}}
s:insert{1, 2, {3, 4, 5, "6"}}
s:insert{1, 2, {3}}
s:insert{1, 2, {3, 4, 5}}
-- inserting good value
s:insert{1, 2, {3, 4, 5, 6}}
-- invalid alters
s.index.spatial:alter({unique = true})
s.index.spatial:alter({type = 'tree'})
box.space[box.schema.SPACE_ID]:update({s.id}, {{"=", 4, 'vinyl'}})
-- chech that truncate works
s.index.spatial:select({0, 0, 10, 10}, {iterator = 'le'})
s:truncate()
s.index.spatial:select({0, 0, 10, 10}, {iterator = 'le'})
-- inserting lots of equvalent records
for i = 1,500 do s:insert{i, i, {3, 4, 5, 6}} end
-- and some records for chaos
for i = 1,10 do for j = 1,10 do s:insert{500+i+j*20, 500+i*20+j, {i, j, i, j}} end end
s.index.spatial:count()
#s.index.spatial:select({3, 4, 5, 6})
for i = 1,500,2 do s:delete{i} end
s.index.spatial:count()
#s.index.spatial:select({3, 4, 5, 6})
s.index.spatial:min()
s.index.spatial:max()
-- seems that drop can't fail
s.index.spatial:drop()
s.index.spatial:select({})
s:drop()
s = box.schema.space.create('vinyl', {engine = 'vinyl'})
-- rtree indexes are not enabled in vinyl
i = s:create_index('spatial', { type = 'rtree', unique = true, parts = {3, 'array'}})
i = s:create_index('primary', { type = 'tree', parts = {1, 'unsigned'}})
-- ... even secondary
i = s:create_index('spatial', { type = 'rtree', unique = true, parts = {3, 'array'}})
s:drop()
-- rtree in temp space must work fine
s = box.schema.space.create('spatial', {temporary = true})
i = s:create_index('primary', { type = 'tree', parts = {1, 'unsigned'}})
i = s:create_index('spatial', { type = 'rtree', unique = false, parts = {3, 'array'}})
s:insert{1, 2, {3, 4, 5, 6}}
s.index.spatial:select({0, 0, 10, 10}, {iterator = 'le'})
s:drop()
-- snapshot test
s = box.schema.space.create('spatial')
i = s:create_index('primary', { type = 'tree', parts = {1, 'unsigned'}})
i = s:create_index('spatial', { type = 'rtree', unique = false, parts = {3, 'array'}})
for i = 1,10 do s:insert{i, i, {i, i, i + 1, i + 1}} end
box.snapshot()
i:select({0, 0}, {iterator = 'neighbor'})
test_run:cmd("restart server default")
s = box.space.spatial
i = s.index.spatial
i:select({0, 0}, {iterator = 'neighbor'})
s:drop()
s = box.schema.space.create('spatial')
i = s:create_index('primary', { type = 'tree', parts = {1, 'unsigned'}})
i = s:create_index('spatial', { type = 'rtree', unique = false, parts = {3, 'array'}, dimension = 4})
for i = 1,10 do s:insert{i, i, {i, i, i, i, i + 1, i + 1, i + 1, i + 1}} end
box.snapshot()
i:select({0, 0, 0, 0}, {iterator = 'neighbor'})
test_run:cmd("restart server default")
s = box.space.spatial
i = s.index.spatial
i:select({0, 0, 0, 0}, {iterator = 'neighbor'})
s:drop()
-- distance type
iopts = { type = 'rtree', unique = false, parts = {2, 'array'} }
iopts['distance'] = 'euclid'
s = box.schema.space.create('spatial')
i = s:create_index('primary', { type = 'tree', parts = {1, 'unsigned'}})
i = s:create_index('spatial', iopts)
s:insert{1, {0, 5}}
s:insert{2, {5, 0}}
s:insert{3, {5, 5}}
s:insert{4, {8, 0}}
s:insert{5, {0, 8}}
s.index.spatial:select({{0, 0}}, {iterator = 'neighbor'})
s:drop()
iopts = { type = 'rtree', unique = false, parts = {2, 'array'} }
iopts['distance'] = 'manhattan'
s = box.schema.space.create('spatial')
i = s:create_index('primary', { type = 'tree', parts = {1, 'unsigned'}})
i = s:create_index('spatial', iopts)
s:insert{1, {0, 5}}
s:insert{2, {5, 0}}
s:insert{3, {5, 5}}
s:insert{4, {8, 0}}
s:insert{5, {0, 8}}
s.index.spatial:select({{0, 0}}, {iterator = 'neighbor'})
test_run:cmd("restart server default")
s = box.space.spatial
i = s.index.spatial
s.index.spatial:select({{0, 0}}, {iterator = 'neighbor'})
box.snapshot()
test_run:cmd("restart server default")
utils = require('utils')
s = box.space.spatial
i = s.index.spatial
s.index.spatial:select({{0, 0}}, {iterator = 'neighbor'})
s:drop()
-- RTREE QA https://github.com/tarantool/tarantool/issues/976
s = box.schema.space.create('s')
i = s:create_index('p')
-- dimension too big
i = s:create_index('s', {type = 'rtree', parts = {2, 'array'}, dimension = 21})
-- dimension too low
i = s:create_index('s', {type = 'rtree', parts = {2, 'array'}, dimension = 0})
-- cant be unique
i = s:create_index('s', {type = 'rtree', parts = {2, 'array'}, unique = true})
-- wrong parts
i = s:create_index('s', {type = 'rtree', parts = {2, 'unsigned'}})
i = s:create_index('s', {type = 'rtree', parts = {2, 'array', 3, 'array'}})
-- defaults test
i = s:create_index('s', { type = 'rtree' })
i.dimension
i.parts
i:drop()
-- hide first (id) field of tuple
function f(t) local r = {} for i, v in ipairs(t) do r[i] = v end r[1] = 0 return setmetatable (r, {__serialize = 'seq'}) end
-- new index through inserting to _index space
f(box.space._index:insert{s.id, 2, 's', 'rtree', {unique = false}, {{2, 'array'}}})
s.index.s:drop()
-- with wrong args
box.space._index:insert{s.id, 2, 's', 'rtree', nil, {{2, 'array'}}}
box.space._index:insert{s.id, 2, 's', 'rtree', utils.setmap({}), {{2, 'array'}}}
box.space._index:insert{s.id, 2, 's', 'rtree', {unique = false, dimension = 22}, {{2, 'array'}}}
box.space._index:insert{s.id, 2, 's', 'rtree', {unique = false, dimension = 'dimension'}, {{2, 'array'}}}
box.space._index:insert{s.id, 2, 's', 'rtree', {unique = false}, {{2, 'unsigned'}}}
box.space._index:insert{s.id, 2, 's', 'rtree', {unique = false}, {{2, 'time'}}}
box.space._index:insert{s.id, 2, 's', 'rtree', {unique = false}, {{'no','time'}}}
box.space._index:insert{s.id, 2, 's', 'rtree', {unique = false, distance = 'lobachevsky'}, {{2, 'array'}}}
box.space._index:insert{s.id, 2, 's', 'rtee', {unique = false}, {{2, 'array'}}}
box.space._index:insert{s.id, 2, 's', 'rtree', {unique = false}, {{}}}
-- unknown args checked
f(box.space._index:insert{s.id, 2, 's', 'rtree', {unique = false, holy = 'cow'}, {{2, 'array'}}})
-- unknown part args are no more ignored (#2649)
f(box.space._index:insert{s.id, 2, 's', 'rtree', {unique = false}, {{field=2, type='array', part = 'opts'}}})
-- alter
i = s:create_index('s', {type = 'rtree', parts = {2, 'array'}})
i:alter{type = 'tree' }
i:alter{dimension = 3 }
s:insert{1, {1, 1} }
s:insert{1, {1, 1, 1} }
i:alter{dimension = 4 }
s:select{}
s:insert{2, {2, 0, 0} }
i:alter{distance = 'euclid' }
i:select({0, 0, 0}, {iterator = 'neighbor'})
i:alter{distance = 'manhattan' }
i:select({0, 0, 0}, {iterator = 'neighbor'})
-- gh-1467: invalid iterator type
i:select({1, 2, 3, 4, 5, 6}, {iterator = 'BITS_ALL_SET' } )
s:drop()
|