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
|
env = require('test_run')
---
...
test_run = env.new()
---
...
space = box.schema.space.create('tweedledum')
---
...
index = space:create_index('primary', { type = 'tree' })
---
...
test_run:cmd("setopt delimiter ';'")
---
- true
...
function crossjoin(space0, space1, limit)
local result = {}
for _,v0 in space0:pairs() do
for _,v1 in space1:pairs() do
if limit <= 0 then
return result
end
local newtuple = v0:totable()
for _, v in v1:pairs() do table.insert(newtuple, v) end
table.insert(result, newtuple)
limit = limit - 1
end
end
return result
end;
---
...
test_run:cmd("setopt delimiter ''");
---
- true
...
crossjoin(space, space, 0)
---
- []
...
crossjoin(space, space, 10000)
---
- []
...
space:insert{1}
---
- [1]
...
crossjoin(space, space, 10000)
---
- - [1, 1]
...
space:insert{2}
---
- [2]
...
crossjoin(space, space, 10000)
---
- - [1, 1]
- [1, 2]
- [2, 1]
- [2, 2]
...
space:insert{3, 'hello'}
---
- [3, 'hello']
...
crossjoin(space, space, 10000)
---
- - [1, 1]
- [1, 2]
- [1, 3, 'hello']
- [2, 1]
- [2, 2]
- [2, 3, 'hello']
- [3, 'hello', 1]
- [3, 'hello', 2]
- [3, 'hello', 3, 'hello']
...
space:insert{4, 'world'}
---
- [4, 'world']
...
space[0]:insert{5, 'hello world'}
---
- error: '[string "return space[0]:insert{5, ''hello world''} "]:1: attempt to index
a nil value'
...
crossjoin(space, space, 10000)
---
- - [1, 1]
- [1, 2]
- [1, 3, 'hello']
- [1, 4, 'world']
- [2, 1]
- [2, 2]
- [2, 3, 'hello']
- [2, 4, 'world']
- [3, 'hello', 1]
- [3, 'hello', 2]
- [3, 'hello', 3, 'hello']
- [3, 'hello', 4, 'world']
- [4, 'world', 1]
- [4, 'world', 2]
- [4, 'world', 3, 'hello']
- [4, 'world', 4, 'world']
...
space:drop()
---
...
crossjoin = nil
---
...
|