Skip to content

Add function to validate tuple against space format in Lua #9979

@locker

Description

@locker

The only way to validate a tuple against a space format without inserting it into the space is using box.tuple.new with the format option:

tarantool> box.tuple.new({'a', 1}, {format = box.space._schema:format()})
---
- ['a', 1]
...

tarantool> box.tuple.new({1, 2}, {format = box.space._schema:format()})
---
- error: 'Tuple field 1 (key) type does not match one required by operation: expected
    string, got unsigned'
...

It'd be nice if a tuple format object had the validate method so that we wouldn't have to create a new tuple in this case:

local format = box.tuple.format.new({{'key', 'string'}, {'value', 'any'}})
format:validate({'a', 1}) -- ok
format:validate(box.tuple.new({'a', 1})) -- ok
format:validate({1, 2}) -- error
format:validate(box.tuple.new({1, 2})) -- error

Similarly to index.parts, it should be possible to use validate with space.format:

box.space._schema.format -- returns format object
box.space._schema.format:validate({'a', 1}) -- ok
box.space._schema.format:validate(box.tuple.new({'a', 1})) -- ok
box.space._schema.format:validate({1, 2}) -- error
box.space._schema.format:validate(box.tuple.new({1, 2})) -- error

Similar tickets for key_def and index.parts:

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions