Skip to content

Commit

Permalink
filters: use proper checks for type support
Browse files Browse the repository at this point in the history
`pcall(require, module)` check is insufficient for external types
since module presence often precedes box format support and index
support for a type. Sometimes the nature of the module may change
between versions: for example, there is a `'uuid'` module in 1.10.x,
but a separate type was introduced only in 2.4.1

Part of #422
  • Loading branch information
DifferentialOrange committed Mar 20, 2024
1 parent 0781bd3 commit 5e78a65
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 11 deletions.
32 changes: 26 additions & 6 deletions crud/common/utils.lua
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@ local fun = require('fun')
local vshard = require('vshard')
local log = require('log')

local datetime_supported, datetime = pcall(require, 'datetime')

local is_cartridge, cartridge = pcall(require, 'cartridge')
local is_cartridge_hotreload, cartridge_hotreload = pcall(require, 'cartridge.hotreload')

Expand Down Expand Up @@ -605,10 +603,34 @@ local function determine_enabled_features()
enabled_tarantool_features.fieldpaths = is_version_ge(major, minor, patch, suffix,
2, 3, 1, nil)

-- since Tarantool 2.4.1
-- Full support (Lua type, space format type and indexes) for decimal type
-- is since Tarantool 2.3.1 [1]
--
-- [1] https://github.com/tarantool/tarantool/commit/485439e33196e26d120e622175f88b4edc7a5aa1
enabled_tarantool_features.decimals = is_version_ge(major, minor, patch, suffix,
2, 3, 1, nil)

-- Full support (Lua type, space format type and indexes) for uuid type
-- is since Tarantool 2.4.1 [1]
--
-- [1] https://github.com/tarantool/tarantool/commit/b238def8065d20070dcdc50b54c2536f1de4c7c7
enabled_tarantool_features.uuids = is_version_ge(major, minor, patch, suffix,
2, 4, 1, nil)

-- Full support (Lua type, space format type and indexes) for datetime type
-- is since Tarantool 2.10.0-beta2 [1]
--
-- [1] https://github.com/tarantool/tarantool/commit/3bd870261c462416c29226414fe0a2d79aba0c74
enabled_tarantool_features.datetimes = is_version_ge(major, minor, patch, suffix,
2, 10, 0, 'beta2')

-- Full support (Lua type, space format type and indexes) for datetime type
-- is since Tarantool 2.10.0-rc1 [1]
--
-- [1] https://github.com/tarantool/tarantool/commit/38f0c904af4882756c6dc802f1895117d3deae6a
enabled_tarantool_features.intervals = is_version_ge(major, minor, patch, suffix,
2, 10, 0, 'rc1')

-- since Tarantool 2.6.3 / 2.7.2 / 2.8.1
enabled_tarantool_features.jsonpath_indexes = is_version_ge(major, minor, patch, suffix,
2, 8, 1, nil)
Expand Down Expand Up @@ -1304,9 +1326,7 @@ function utils.is_cartridge_hotreload_supported()
return true, cartridge_hotreload
end

local interval_supported = datetime_supported and (datetime.interval ~= nil)

if interval_supported then
if utils.tarantool_supports_intervals() then
-- https://github.com/tarantool/tarantool/blob/0510ffa07afd84a70c9c6f1a4c28aacd73a393d6/src/lua/datetime.lua#L175-179
local interval_t = ffi.typeof('struct interval')

Expand Down
10 changes: 5 additions & 5 deletions crud/compare/filters.lua
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
local datetime_supported, datetime = pcall(require, 'datetime')
local decimal_supported, decimal = pcall(require, 'decimal')

local errors = require('errors')

local _, datetime = pcall(require, 'datetime')
local _, decimal = pcall(require, 'decimal')

local utils = require('crud.common.utils')
local dev_checks = require('crud.common.dev_checks')
local collations = require('crud.common.collations')
Expand Down Expand Up @@ -160,12 +160,12 @@ local function format_value(value)
return tostring(value)
elseif type(value) == 'boolean' then
return tostring(value)
elseif decimal_supported and decimal.is_decimal(value) then
elseif utils.tarantool_supports_decimals() and decimal.is_decimal(value) then
-- decimal supports comparison with string.
return ("%q"):format(tostring(value))
elseif utils.is_uuid(value) then
return ("%q"):format(value)
elseif datetime_supported and datetime.is_datetime(value) then
elseif utils.tarantool_supports_datetimes() and datetime.is_datetime(value) then
return ("%q"):format(value:format())
elseif utils.is_interval(value) then
-- As for Tarantool 3.0 and older, datetime intervals
Expand Down

0 comments on commit 5e78a65

Please sign in to comment.