Skip to content

Commit cb60c8e

Browse files
committed
Allow custom fields in space format
Tarantool allows space format to have custom fields. And users say it may be valuable. This patch allows to add custom `space.format` fields, for example ```lua spaces = { test = { format = {{ name = 'size', type = 'number', scale = 'bananas', }}, } } ``` The only restriction is that a custom field must be a string.
1 parent 1449887 commit cb60c8e

File tree

4 files changed

+37
-7
lines changed

4 files changed

+37
-7
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,10 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
66

77
## [Unreleased]
88

9+
### Added
10+
11+
- Allow custom fields in space format
12+
913
## [1.2.0] - 2020-07-20
1014

1115
### Added

ddl/check.lua

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -73,14 +73,13 @@ local function check_field(i, field, space)
7373
end
7474

7575

76-
do -- check redundant keys
77-
local k = utils.redundant_key(field,
78-
{'name', 'type', 'is_nullable'}
79-
)
80-
if k ~= nil then
76+
-- non-string keys are forbidden
77+
for k, _ in pairs(field) do
78+
if type(k) ~= 'string' then
8179
return nil, string.format(
82-
"spaces[%q].format[%q]: redundant key %q",
83-
space.name, field.name, k
80+
"spaces[%q].format[%q]: bad key %s" ..
81+
" (string expected, got %s)",
82+
space.name, field.name, k, type(k)
8483
)
8584
end
8685
end

test/check_schema_test.lua

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,8 @@ local test_space = {
3838
{name = 'double_null', type = 'double', is_nullable = true},
3939
{name = 'uuid_nonnull', type = 'uuid', is_nullable = false},
4040
{name = 'uuid_null', type = 'uuid', is_nullable = true},
41+
42+
{name = 'annotated', type = 'any', is_nullable = true, comment = 'x'},
4143
},
4244
}
4345

test/set_schema_test.lua

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -890,6 +890,31 @@ function g.test_missing_format()
890890
)
891891
end
892892

893+
function g.test_annotated_format()
894+
local schema = {spaces = table.deepcopy(test_space)}
895+
schema.spaces.test.indexes = {{
896+
type = 'TREE',
897+
unique = true,
898+
name = 'primary',
899+
parts = {{path = 'unsigned_nonnull', type = 'unsigned', is_nullable = false}}
900+
}}
901+
902+
local k = 1ULL
903+
schema.spaces.test.format[2][k] = 'forbidden-cdata'
904+
local res, err = ddl.set_schema(schema)
905+
t.assert_equals(res, nil)
906+
t.assert_equals(err,
907+
'spaces["test"].format["unsigned_nullable"]:' ..
908+
' bad key 1ULL (string expected, got cdata)'
909+
)
910+
schema.spaces.test.format[2][k] = nil
911+
912+
schema.spaces.test.format[1].scale = 'bananas'
913+
local res, err = ddl.set_schema(schema)
914+
t.assert_equals({res, err}, {true, nil})
915+
t.assert_equals(ddl.get_schema(), schema)
916+
end
917+
893918
function g.test_missing_indexes()
894919
local schema = {spaces = table.deepcopy(test_space)}
895920
schema.spaces.test.indexes = nil

0 commit comments

Comments
 (0)