Skip to content

Commit cd23fe0

Browse files
committed
Unit tests
1 parent f62693a commit cd23fe0

File tree

1 file changed

+68
-0
lines changed

1 file changed

+68
-0
lines changed

test/unit/select_filters_test.lua

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ local collations = require('crud.common.collations')
99
local t = require('luatest')
1010
local g = t.group('select_filters')
1111

12+
local crud_utils = require('crud.common.utils')
13+
1214
local helpers = require('test.helper')
1315

1416
g.before_all = function()
@@ -43,10 +45,47 @@ g.before_all = function()
4345
unique = false,
4446
if_not_exists = true,
4547
})
48+
49+
if crud_utils.tarantool_supports_jsonpath_indexes() then
50+
local cars_space = box.schema.space.create('cars', {
51+
format = {
52+
{name = 'id', type = 'map'},
53+
{name = 'bucket_id', type = 'unsigned'},
54+
{name = 'age', type = 'number'},
55+
{name = 'manufacturer', type = 'string'},
56+
{name = 'data', type = 'map'}
57+
},
58+
if_not_exists = true,
59+
})
60+
61+
-- primary index
62+
cars_space:create_index('id_ind', {
63+
parts = {
64+
{1, 'unsigned', path = 'car_id.signed'},
65+
},
66+
if_not_exists = true,
67+
})
68+
69+
cars_space:create_index('bucket_id', {
70+
parts = { 'bucket_id' },
71+
unique = false,
72+
if_not_exists = true,
73+
})
74+
75+
cars_space:create_index('data_index', {
76+
parts = {
77+
{5, 'str', path = 'car.color'},
78+
{5, 'str', path = 'car.model'},
79+
},
80+
unique = false,
81+
if_not_exists = true,
82+
})
83+
end
4684
end
4785

4886
g.after_all(function()
4987
box.space.customers:drop()
88+
box.space.cars:drop()
5089
end)
5190

5291
g.test_empty_conditions = function()
@@ -815,5 +854,34 @@ return M]]
815854
t.assert_equals({ filter_func(box.tuple.new({{field_1 = 5, f2 = 3}, {fld_1 = "jsonpath_test"}, 23})) }, {false, false})
816855
end
817856

857+
g.test_jsonpath_indexes = function()
858+
t.skip_if(
859+
not crud_utils.tarantool_supports_jsonpath_indexes(),
860+
"Jsonpath indexes supported since 2.6.3/2.7.2/2.8.1"
861+
)
862+
863+
local conditions = {
864+
cond_funcs.gt('id', 20),
865+
cond_funcs.eq('data_index', {'Yellow', 'BMW'})
866+
}
867+
868+
local plan, err = select_plan.new(box.space.cars, conditions)
869+
t.assert_equals(err, nil)
870+
871+
local filter_conditions, err = select_filters.internal.parse(box.space.cars, conditions, {
872+
scan_condition_num = plan.scan_condition_num,
873+
tarantool_iter = plan.tarantool_iter,
874+
})
875+
876+
t.assert_equals(err, nil)
877+
878+
local data_condition = filter_conditions[1]
879+
t.assert_type(data_condition, 'table')
880+
t.assert_equals(data_condition.fields, {"[5]car.color", "[5]car.model"})
881+
t.assert_equals(data_condition.operator, compare_conditions.operators.EQ)
882+
t.assert_equals(data_condition.values, {'Yellow', 'BMW'})
883+
t.assert_equals(data_condition.types, {'string', 'string'})
884+
t.assert_equals(data_condition.early_exit_is_possible, false)
885+
end
818886

819887
-- luacheck: pop

0 commit comments

Comments
 (0)