Skip to content
Snippets Groups Projects
Commit b7547484 authored by Vladislav Shpilevoy's avatar Vladislav Shpilevoy Committed by Roman Tsisyk
Browse files

Remove null from scalar type, added more tests for new types (#1556)

parent cad04551
No related branches found
No related tags found
No related merge requests found
......@@ -69,7 +69,7 @@ const uint32_t key_mp_type[] = {
/* [NUMBER] = */ (1U << MP_UINT) | (1U << MP_INT) | (1U << MP_FLOAT) | (1U << MP_DOUBLE),
/* [INT] = */ (1U << MP_UINT) | (1U << MP_INT),
/* [SCALAR] = */ (1U << MP_UINT) | (1U << MP_INT) | (1U << MP_FLOAT) | (1U << MP_DOUBLE) |
(1U << MP_NIL) | (1U << MP_STR) | (1U << MP_BIN) | (1U << MP_BOOL),
(1U << MP_STR) | (1U << MP_BIN) | (1U << MP_BOOL),
};
const struct key_opts key_opts_default = {
......
......@@ -472,14 +472,6 @@ mp_decode_number(const char **data)
return val;
}
static int
mp_compare_nil(const char *field_a, const char *field_b)
{
(void)field_a;
(void)field_b;
return 0;
}
static int
mp_compare_bool(const char *field_a, const char *field_b)
{
......@@ -560,7 +552,7 @@ mp_compare_bin(const char *field_a, const char *field_b)
typedef int (*mp_compare_f)(const char *, const char *);
static mp_compare_f mp_class_comparators[] = {
/* .MP_CLASS_NIL = */ mp_compare_nil,
/* .MP_CLASS_NIL = */ NULL,
/* .MP_CLASS_BOOL = */ mp_compare_bool,
/* .MP_CLASS_NUMBER = */ mp_compare_number,
/* .MP_CLASS_STR = */ mp_compare_str,
......
-- Test for unique indices
-- Tests for TREE index type
s0 = box.schema.space.create('my_space1')
---
...
i0 = s0:create_index('my_space1_idx1', {type='TREE', parts={1, 'NUMBER'}})
i0 = s0:create_index('my_space1_idx1', {type='TREE', parts={1, 'NUMBER'}, unique=true})
---
...
s0:insert({10})
......@@ -197,7 +199,7 @@ s0:drop()
s1 = box.schema.space.create('my_space2')
---
...
i1 = s1:create_index('my_space2_idx1', {type='TREE', parts={1, 'SCALAR'}})
i1 = s1:create_index('my_space2_idx1', {type='TREE', parts={1, 'SCALAR'}, unique=true})
---
...
s1:insert({10})
......@@ -431,10 +433,10 @@ s1:drop()
s2 = box.schema.space.create('my_space3')
---
...
i2_1 = s2:create_index('my_space3_idx1', {type='TREE', parts={1, 'SCALAR', 2, 'INT', 3, 'NUMBER'}})
i2_1 = s2:create_index('my_space3_idx1', {type='TREE', parts={1, 'SCALAR', 2, 'INT', 3, 'NUMBER'}, unique=true})
---
...
i2_2 = s2:create_index('my_space3_idx2', {type='TREE', parts={4, 'STR', 5, 'SCALAR'}})
i2_2 = s2:create_index('my_space3_idx2', {type='TREE', parts={4, 'STR', 5, 'SCALAR'}, unique=true})
---
...
s2:insert({10, 1, -1, 'z', true})
......@@ -702,3 +704,210 @@ s2.index.my_space3_idx2:select{}
s2:drop()
---
...
-- Tests for HASH index type
s3 = box.schema.space.create('my_space4')
---
...
i3_1 = s3:create_index('my_space4_idx1', {type='HASH', parts={1, 'SCALAR', 2, 'INT', 3, 'NUMBER'}, unique=true})
---
...
i3_2 = s3:create_index('my_space4_idx2', {type='HASH', parts={4, 'STR', 5, 'SCALAR'}, unique=true})
---
...
s3:insert({100.5, 30, 95, "str1", 5})
---
- [100.5, 30, 95, 'str1', 5]
...
s3:insert({"abc#$23", 1000, -21.542, "namesurname", 99})
---
- ['abc#$23', 1000, -21.542, 'namesurname', 99]
...
s3:insert({true, -459, 4000, "foobar", "36.6"})
---
- [true, -459, 4000, 'foobar', '36.6']
...
s3:select{}
---
- - [true, -459, 4000, 'foobar', '36.6']
- ['abc#$23', 1000, -21.542, 'namesurname', 99]
- [100.5, 30, 95, 'str1', 5]
...
i3_1:select({100.5})
---
- error: Invalid key part count in an exact match (expected 3, got 1)
...
i3_1:select({true, -459})
---
- error: Invalid key part count in an exact match (expected 3, got 2)
...
i3_1:select({"abc#$23", 1000, -21.542})
---
- - ['abc#$23', 1000, -21.542, 'namesurname', 99]
...
i3_2:select({"str1", 5})
---
- - [100.5, 30, 95, 'str1', 5]
...
i3_2:select({"str"})
---
- error: Invalid key part count in an exact match (expected 2, got 1)
...
i3_2:select({"str", 5})
---
- []
...
i3_2:select({"foobar", "36.6"})
---
- - [true, -459, 4000, 'foobar', '36.6']
...
s3:drop()
---
...
-- Tests for NULL
mp = require('msgpack')
---
...
s4 = box.schema.space.create('my_space5')
---
...
i4_1 = s4:create_index('my_space5_idx1', {type='HASH', parts={1, 'SCALAR', 2, 'INT', 3, 'NUMBER'}, unique=true})
---
...
i4_2 = s4:create_index('my_space5_idx2', {type='TREE', parts={4, 'SCALAR'}, unique=true})
---
...
s4:insert({mp.NULL, 1, 1, 1})
---
- error: 'Tuple field 1 type does not match one required by operation: expected SCALAR'
...
s4:insert({2, mp.NULL, 2, 2}) -- all nulls must fail
---
- error: 'Tuple field 2 type does not match one required by operation: expected INT'
...
s4:insert({3, 3, mp.NULL, 3})
---
- error: 'Tuple field 3 type does not match one required by operation: expected NUMBER'
...
s4:insert({4, 4, 4, mp.NULL})
---
- error: 'Tuple field 4 type does not match one required by operation: expected SCALAR'
...
s4:drop()
---
...
-- Test for nonunique indices
-- Test TREE index type
s5 = box.schema.space.create('my_space6')
---
...
i5_1 = s5:create_index('my_space6_idx1', {type='TREE', parts={1, 'NUM'}, unique=true})
---
...
i5_2 = s5:create_index('my_space6_idx2', {type='TREE', parts={2, 'SCALAR'}, unique=false})
---
...
s5:insert({1, "123"})
---
- [1, '123']
...
s5:insert({2, "123"})
---
- [2, '123']
...
s5:insert({3, "123"})
---
- [3, '123']
...
s5:insert({4, 123})
---
- [4, 123]
...
s5:insert({5, 123})
---
- [5, 123]
...
s5:insert({6, true})
---
- [6, true]
...
s5:insert({7, true})
---
- [7, true]
...
s5:insert({8, mp.NULL}) -- must fail
---
- error: 'Tuple field 2 type does not match one required by operation: expected SCALAR'
...
s5:insert({9, -40.5})
---
- [9, -40.5]
...
s5:insert({10, -39.5})
---
- [10, -39.5]
...
s5:insert({11, -38.5})
---
- [11, -38.5]
...
s5:insert({12, 100.5})
---
- [12, 100.5]
...
s5:select{}
---
- - [1, '123']
- [2, '123']
- [3, '123']
- [4, 123]
- [5, 123]
- [6, true]
- [7, true]
- [9, -40.5]
- [10, -39.5]
- [11, -38.5]
- [12, 100.5]
...
i5_2:select({123})
---
- - [4, 123]
- [5, 123]
...
i5_2:select({"123"})
---
- - [1, '123']
- [2, '123']
- [3, '123']
...
i5_2:select({true})
---
- - [6, true]
- [7, true]
...
i5_2:select({false})
---
- []
...
i5_2:select({true})
---
- - [6, true]
- [7, true]
...
i5_2:select({-38.5})
---
- - [11, -38.5]
...
i5_2:select({-40}, {iterator = 'GE'})
---
- - [10, -39.5]
- [11, -38.5]
- [12, 100.5]
- [4, 123]
- [5, 123]
- [1, '123']
- [2, '123']
- [3, '123']
...
s5:drop()
---
...
-- Test for unique indices
-- Tests for TREE index type
s0 = box.schema.space.create('my_space1')
i0 = s0:create_index('my_space1_idx1', {type='TREE', parts={1, 'NUMBER'}})
i0 = s0:create_index('my_space1_idx1', {type='TREE', parts={1, 'NUMBER'}, unique=true})
s0:insert({10})
s0:insert({11})
......@@ -38,7 +43,7 @@ s0:select{}
s0:drop()
s1 = box.schema.space.create('my_space2')
i1 = s1:create_index('my_space2_idx1', {type='TREE', parts={1, 'SCALAR'}})
i1 = s1:create_index('my_space2_idx1', {type='TREE', parts={1, 'SCALAR'}, unique=true})
s1:insert({10})
s1:insert({11})
......@@ -84,8 +89,8 @@ s1:select{}
s1:drop()
s2 = box.schema.space.create('my_space3')
i2_1 = s2:create_index('my_space3_idx1', {type='TREE', parts={1, 'SCALAR', 2, 'INT', 3, 'NUMBER'}})
i2_2 = s2:create_index('my_space3_idx2', {type='TREE', parts={4, 'STR', 5, 'SCALAR'}})
i2_1 = s2:create_index('my_space3_idx1', {type='TREE', parts={1, 'SCALAR', 2, 'INT', 3, 'NUMBER'}, unique=true})
i2_2 = s2:create_index('my_space3_idx2', {type='TREE', parts={4, 'STR', 5, 'SCALAR'}, unique=true})
s2:insert({10, 1, -1, 'z', true})
s2:insert({11, 2, 2, 'g', false})
......@@ -131,3 +136,72 @@ s2:select{}
s2.index.my_space3_idx2:select{}
s2:drop()
-- Tests for HASH index type
s3 = box.schema.space.create('my_space4')
i3_1 = s3:create_index('my_space4_idx1', {type='HASH', parts={1, 'SCALAR', 2, 'INT', 3, 'NUMBER'}, unique=true})
i3_2 = s3:create_index('my_space4_idx2', {type='HASH', parts={4, 'STR', 5, 'SCALAR'}, unique=true})
s3:insert({100.5, 30, 95, "str1", 5})
s3:insert({"abc#$23", 1000, -21.542, "namesurname", 99})
s3:insert({true, -459, 4000, "foobar", "36.6"})
s3:select{}
i3_1:select({100.5})
i3_1:select({true, -459})
i3_1:select({"abc#$23", 1000, -21.542})
i3_2:select({"str1", 5})
i3_2:select({"str"})
i3_2:select({"str", 5})
i3_2:select({"foobar", "36.6"})
s3:drop()
-- Tests for NULL
mp = require('msgpack')
s4 = box.schema.space.create('my_space5')
i4_1 = s4:create_index('my_space5_idx1', {type='HASH', parts={1, 'SCALAR', 2, 'INT', 3, 'NUMBER'}, unique=true})
i4_2 = s4:create_index('my_space5_idx2', {type='TREE', parts={4, 'SCALAR'}, unique=true})
s4:insert({mp.NULL, 1, 1, 1})
s4:insert({2, mp.NULL, 2, 2}) -- all nulls must fail
s4:insert({3, 3, mp.NULL, 3})
s4:insert({4, 4, 4, mp.NULL})
s4:drop()
-- Test for nonunique indices
-- Test TREE index type
s5 = box.schema.space.create('my_space6')
i5_1 = s5:create_index('my_space6_idx1', {type='TREE', parts={1, 'NUM'}, unique=true})
i5_2 = s5:create_index('my_space6_idx2', {type='TREE', parts={2, 'SCALAR'}, unique=false})
s5:insert({1, "123"})
s5:insert({2, "123"})
s5:insert({3, "123"})
s5:insert({4, 123})
s5:insert({5, 123})
s5:insert({6, true})
s5:insert({7, true})
s5:insert({8, mp.NULL}) -- must fail
s5:insert({9, -40.5})
s5:insert({10, -39.5})
s5:insert({11, -38.5})
s5:insert({12, 100.5})
s5:select{}
i5_2:select({123})
i5_2:select({"123"})
i5_2:select({true})
i5_2:select({false})
i5_2:select({true})
i5_2:select({-38.5})
i5_2:select({-40}, {iterator = 'GE'})
s5:drop()
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment