[patches] [PATCH 1/1] schema: do not ignore space:format field type if no 'type = ...'
Vladislav Shpilevoy
v.shpilevoy at tarantool.org
Mon Feb 26 18:19:09 MSK 2018
When a field type is specified as numbered key, and a name is
named key, then the type is ignored. For example:
{name = '<name>', '<type>'} - here the '<type>' is ignored and
result space format contains 'any' regardless of <type>.
Fix tuple format field parsing to take this case into account.
Closes #2895
Signed-off-by: Vladislav Shpilevoy <v.shpilevoy at tarantool.org>
---
src/box/lua/schema.lua | 14 +++++++++++---
test/box/alter.result | 34 ++++++++++++++++++++++++++++++++++
test/box/alter.test.lua | 16 ++++++++++++++++
test/engine/iterator.result | 2 +-
4 files changed, 62 insertions(+), 4 deletions(-)
diff --git a/src/box/lua/schema.lua b/src/box/lua/schema.lua
index bf8b1db29..30c6bc69c 100644
--- a/src/box/lua/schema.lua
+++ b/src/box/lua/schema.lua
@@ -335,9 +335,17 @@ function update_format(format)
else
for k, v in pairs(given) do
if k == 1 then
- field.name = v;
- elseif k == 2 then
- field.type = v;
+ if given.name then
+ if not given.type then
+ field.type = v
+ else
+ field[1] = v
+ end
+ else
+ field.name = v
+ end
+ elseif k == 2 and not given.type and not given.name then
+ field.type = v
else
field[k] = v
end
diff --git a/test/box/alter.result b/test/box/alter.result
index 00e1cb791..347de4772 100644
--- a/test/box/alter.result
+++ b/test/box/alter.result
@@ -2327,3 +2327,37 @@ pk:alter{parts = {{1, 'string'}}} -- Must fail.
s:drop()
---
...
+--
+-- gh-2895: do not ignore field type in space format, if it is not
+-- specified via 'type = ...'.
+--
+format = {}
+---
+...
+format[1] = {name = 'field1', 'unsigned'}
+---
+...
+format[2] = {name = 'field2', 'unsigned'}
+---
+...
+s = box.schema.create_space('test', {format = format})
+---
+...
+s:format()
+---
+- [{'type': 'unsigned', 'name': 'field1'}, {'type': 'unsigned', 'name': 'field2'}]
+...
+format[2] = {name = 'field2', 'unsigned', 'unknown'}
+---
+...
+s:format(format)
+---
+- error: 'Can''t modify space ''test'': field 2 format is not map with string keys'
+...
+s:format()
+---
+- [{'type': 'unsigned', 'name': 'field1'}, {'type': 'unsigned', 'name': 'field2'}]
+...
+s:drop()
+---
+...
diff --git a/test/box/alter.test.lua b/test/box/alter.test.lua
index eb0739aad..f6b2eb49c 100644
--- a/test/box/alter.test.lua
+++ b/test/box/alter.test.lua
@@ -886,3 +886,19 @@ pk = s:create_index('pk')
s:replace{1}
pk:alter{parts = {{1, 'string'}}} -- Must fail.
s:drop()
+
+--
+-- gh-2895: do not ignore field type in space format, if it is not
+-- specified via 'type = ...'.
+--
+format = {}
+format[1] = {name = 'field1', 'unsigned'}
+format[2] = {name = 'field2', 'unsigned'}
+s = box.schema.create_space('test', {format = format})
+s:format()
+
+format[2] = {name = 'field2', 'unsigned', 'unknown'}
+s:format(format)
+s:format()
+
+s:drop()
diff --git a/test/engine/iterator.result b/test/engine/iterator.result
index 63fead40e..9cedc6a58 100644
--- a/test/engine/iterator.result
+++ b/test/engine/iterator.result
@@ -4215,7 +4215,7 @@ s:replace{35}
...
state, value = gen(param,state)
---
-- error: 'builtin/box/schema.lua:975: usage: next(param, state)'
+- error: 'builtin/box/schema.lua:983: usage: next(param, state)'
...
value
---
--
2.14.3 (Apple Git-98)
More information about the Tarantool-patches
mailing list