|
| 1 | +local t = require("luatest") |
| 2 | +local fio = require("fio") |
| 3 | + |
| 4 | +local helpers = require("luatest.helpers") |
| 5 | + |
| 6 | +t.before_suite(function() |
| 7 | + t.datadir = fio.tempdir() |
| 8 | + box.cfg{ |
| 9 | + wal_dir = t.datadir, |
| 10 | + memtx_dir = t.datadir, |
| 11 | + vinyl_dir = t.datadir, |
| 12 | + } |
| 13 | + |
| 14 | + local tree = box.schema.create_space("tree", { if_not_exists = true }) |
| 15 | + tree:format({ |
| 16 | + {name = "id", type = "number"}, |
| 17 | + {name = "first_name", type = "string"}, |
| 18 | + {name = "value", type = "number", is_nullable = true}, |
| 19 | + {name = "count", type = "number", is_nullable = true}, |
| 20 | + {name = "non_unique_id", type = "number", is_nullable = true, unique = false}, |
| 21 | + {name = "json_path_field", is_nullable = true, unique = false}, |
| 22 | + {name = "multikey_field", is_nullable = true}, |
| 23 | + {name = "functional_field", is_nullable = true}, |
| 24 | + }) |
| 25 | + tree:create_index("primary", {type = "TREE", parts={ 1 }}) |
| 26 | + tree:create_index("index_for_first_name", {type = "TREE", parts={ 2 }}) |
| 27 | + tree:create_index("multipart_index", {type = "TREE", parts={ {3, is_nullable = true}, {4, is_nullable = true} }}) |
| 28 | + tree:create_index("non_unique_index", {type = "TREE", parts={ {5, is_nullable = true} }, unique = false}) |
| 29 | + |
| 30 | + local hash = box.schema.create_space("hash", { if_not_exists = true }) |
| 31 | + hash:format({ |
| 32 | + {name = "id", type = "number"}, |
| 33 | + {name = "first_name", type = "string"}, |
| 34 | + {name = "value", type = "number", is_nullable = true}, |
| 35 | + {name = "count", type = "number", is_nullable = true} |
| 36 | + }) |
| 37 | + hash:create_index("primary", {type = "HASH", parts={ 1 }} ) |
| 38 | + hash:create_index("index_for_first_name", {type = "HASH", parts={ 2 }} ) |
| 39 | + hash:create_index("multipart_index", {type = "HASH", parts={ {1}, {2} }}) |
| 40 | + |
| 41 | + local vinyl = box.schema.create_space("vinyl", { if_not_exists = true, engine = "vinyl" }) |
| 42 | + vinyl:format({ |
| 43 | + {name = "id", type = "number"}, |
| 44 | + {name = "first_name", type = "string"}, |
| 45 | + {name = "value", type = "number", is_nullable = true}, |
| 46 | + {name = "count", type = "number", is_nullable = true}, |
| 47 | + {name = "non_unique_id", type = "number", is_nullable = true, unique = false}, |
| 48 | + {name = "json_path_field", is_nullable = true, unique = false}, |
| 49 | + {name = "multikey_field", is_nullable = true, unique = false}, |
| 50 | + }) |
| 51 | + vinyl:create_index("primary", {type = "TREE", parts={ 1 }}) |
| 52 | + vinyl:create_index("index_for_first_name", {type = "TREE", parts={ 2 }}) |
| 53 | + vinyl:create_index("multipart_index", {type = "TREE", parts={ {3, is_nullable = true}, {4, is_nullable = true} }}) |
| 54 | + vinyl:create_index("non_unique_index", {type = "TREE", parts={ {5} }, unique = false }) |
| 55 | + |
| 56 | + if _TARANTOOL >= "2" then |
| 57 | + local tree_code = [[function(tuple) |
| 58 | + if tuple[8] then |
| 59 | + return {string.sub(tuple[8],2,2)} |
| 60 | + end |
| 61 | + return {tuple[2]} |
| 62 | + end]] |
| 63 | + box.schema.func.create("tree_func", |
| 64 | + {body = tree_code, is_deterministic = true, is_sandboxed = true}) |
| 65 | + tree:create_index("json_path_index", |
| 66 | + {type = "TREE", parts = { {6, type = "scalar", path = "age", is_nullable = true} }}) |
| 67 | + tree:create_index("multikey_index", |
| 68 | + {type = "TREE", parts = { {7, type = "str", path = "data[*].name"} }} ) |
| 69 | + tree:create_index("functional_index", |
| 70 | + {type = "TREE", parts={ {1, type = "string"} }, func = "tree_func"}) |
| 71 | + |
| 72 | + vinyl:create_index("json_path_index", |
| 73 | + {type = "TREE", parts = { {6, type = "scalar", path = "age", is_nullable = true} }}) |
| 74 | + vinyl:create_index("multikey_index", |
| 75 | + {type = "TREE", parts = { {7, type = "str", path = "data[*].name", is_nullable = true} }}) |
| 76 | + end |
| 77 | + |
| 78 | + local bitset = box.schema.create_space("bitset", { if_not_exists = true }) |
| 79 | + bitset:create_index("primary", {type = "TREE", parts={ 1 }}) |
| 80 | + bitset:create_index("index_for_first_name", |
| 81 | + {type = "BITSET", parts={ {field = 2, type = "string"} }, unique = false}) |
| 82 | +end) |
| 83 | + |
| 84 | +t.after_suite(function() |
| 85 | + fio.rmtree(t.datadir) |
| 86 | +end) |
| 87 | + |
| 88 | +function helpers.init_spaces(g) |
| 89 | + g.tree = box.space.tree |
| 90 | + g.hash = box.space.hash |
| 91 | + g.vinyl = box.space.vinyl |
| 92 | + g.bitset = box.space.bitset |
| 93 | +end |
| 94 | + |
| 95 | +function helpers.truncate_spaces(g) |
| 96 | + g.tree:truncate() |
| 97 | + g.hash:truncate() |
| 98 | + g.vinyl:truncate() |
| 99 | +end |
| 100 | + |
| 101 | +function helpers.is_expired_true() |
| 102 | + return true |
| 103 | +end |
| 104 | + |
| 105 | +helpers.iteration_result = {} |
| 106 | +function helpers.is_expired_debug(_, tuple) |
| 107 | + table.insert(helpers.iteration_result, tuple) |
| 108 | + return true |
| 109 | +end |
| 110 | + |
| 111 | +return helpers |
0 commit comments