Skip to content

Commit

Permalink
ddl: support interval type in format
Browse files Browse the repository at this point in the history
Datetime intervals are supported as a part of space schema format since
2.10.0 [1]. They are not allowed to be a part of memtx index [2].

1. tarantool/tarantool@a9e30fb
2. https://github.com/tarantool/tarantool/blob/ddaa5a320ee8d8d1009e07bbf6b8fe5cb4acbb45/src/box/memtx_space.c#L844-L851
  • Loading branch information
DifferentialOrange committed Oct 23, 2023
1 parent b55d0ff commit 0cfee46
Show file tree
Hide file tree
Showing 6 changed files with 47 additions and 1 deletion.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,12 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/)
and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html).

## Unreleased

### Added

- Added support of `interval` type for Tarantool 2.10+ space format.

## [1.6.4] - 2023-07-05

### Added
Expand Down
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,8 @@ format = {
type = 'unsigned' | 'string' | 'varbinary' |
'integer' | 'number' | 'boolean' |
'array' | 'scalar' | 'any' | 'map' |
'decimal' | 'double' | 'uuid' | 'datetime'
'decimal' | 'double' | 'uuid' | 'datetime' |
'interval'
},
...
},
Expand Down
8 changes: 8 additions & 0 deletions ddl/check.lua
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ local function check_field(i, field, space)
double = true,
uuid = true,
datetime = true,
interval = true,
}

if known_field_types[field.type] == nil then
Expand All @@ -81,6 +82,13 @@ local function check_field(i, field, space)
space.name, field.name, _TARANTOOL
)
end

if not db.interval_allowed() and field.type == 'interval' then
return nil, string.format(
"spaces[%q].format[%q].type: interval type isn't allowed in your Tarantool version (%s)",
space.name, field.name, _TARANTOOL
)
end
end


Expand Down
5 changes: 5 additions & 0 deletions ddl/db.lua
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,10 @@ local function datetime_allowed()
return tarantool_version_at_least(2, 10)
end

local function interval_allowed()
return tarantool_version_at_least(2, 10)
end

-- https://github.com/tarantool/tarantool/issues/4083
local function transactional_ddl_allowed()
return tarantool_version_at_least(2, 2)
Expand Down Expand Up @@ -155,6 +159,7 @@ return {
multikey_path_allowed = multikey_path_allowed,
transactional_ddl_allowed = transactional_ddl_allowed,
datetime_allowed = datetime_allowed,
interval_allowed = interval_allowed,
exclude_null_allowed = exclude_null_allowed,

call_atomic = call_atomic,
Expand Down
21 changes: 21 additions & 0 deletions test/check_schema_test.lua
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,12 @@ function g.test_datetime_index_part_type()
end
end

function g.test_interval_index_part_type()
local ok, err = ddl_check.check_index_part_type('interval', 'TREE')
t.assert_not(ok)
t.assert_equals(err, "interval field type is unsupported in TREE index type")
end

function g.test_index_part_path()
local index_info = {type = 'HASH'}

Expand Down Expand Up @@ -1156,6 +1162,21 @@ function g.test_field()
_TARANTOOL
))
end

local ok, err = ddl_check.check_field(
1, {name = 'x', type = 'interval', is_nullable = false}, space_info
)
if db.v(2, 10) then
t.assert(ok)
t.assert_not(err)
else
t.assert_not(ok)
t.assert_equals(err, string.format(
[[spaces["space"].format["x"].type: interval type ]] ..
[[isn't allowed in your Tarantool version (%s)]],
_TARANTOOL
))
end
end

function g.test_scalar_types()
Expand Down
5 changes: 5 additions & 0 deletions test/helper.lua
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,11 @@ function helpers.test_space_format()
table.insert(space_format, {name = 'datetime_nullable', type = 'datetime', is_nullable = true})
end

if db.v(2, 10) then
table.insert(space_format, {name = 'interval_nonnull', type = 'interval', is_nullable = false})
table.insert(space_format, {name = 'interval_nullable', type = 'interval', is_nullable = true})
end

return table.deepcopy(space_format)
end

Expand Down

0 comments on commit 0cfee46

Please sign in to comment.