Skip to content

Commit 4de7d35

Browse files
scan: fix nil filters
Before this patch, some nil conditions failed with internal filter library build error. This patch fixes this internal error, as well as normalize filters to behave similar to core indexes. The logic in core Tarantool select is as follows. `nil` condition in index select is an absence of condition, thus all data is returned disregarding the condition (condition may affect the order). `box.NULL` condition is a condition for the null value -- in case of EQ, only records with null index value are returned, in case of GT, all non-null values are returned since nulls are in the beginning of an index and so on. `nil`s and `box.NULL`s in tuple are both satisfy `box.NULL` equity. After this patch, `nil` filter condition is treated as no condition. This is a breaking change since conditions for `'>'` and `'<'` operator with `nil` operand had resulted with empty response before this patch. But since it was inconsistent with scanning index conditions and wasn't intentional, we change it here. Closes #422
1 parent e19757d commit 4de7d35

File tree

9 files changed

+396
-13
lines changed

9 files changed

+396
-13
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
1717
non-iterating indexes (#373).
1818
* Passing errors from storages for merger operations (`crud.select`,
1919
`crud.pairs`, `readview:select`, `readview:pairs`) (#423).
20+
* Working with `nil` operand conditions in case of non-indexed fields or
21+
non-iterating indexes (#422).
2022

2123
## [1.4.3] - 05-02-24
2224

crud/compare/filters.lua

Lines changed: 23 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -345,9 +345,14 @@ local function gen_eq_func_code(func_name, cond, func_args_code)
345345
local header = LIB_FUNC_HEADER_TEMPLATE:format(func_name, func_args_code)
346346
table.insert(func_code_lines, header)
347347

348-
local return_line = string.format(
349-
' return %s', concat_conditions(eq_conds, 'and')
350-
)
348+
local return_line
349+
if #eq_conds > 0 then
350+
return_line = string.format(
351+
' return %s', concat_conditions(eq_conds, 'and')
352+
)
353+
else -- nil condition is treated as no condition
354+
return_line = ' return true'
355+
end
351356
table.insert(func_code_lines, return_line)
352357

353358
table.insert(func_code_lines, 'end')
@@ -398,18 +403,23 @@ local function gen_cmp_array_func_code(operator, func_name, cond, func_args_code
398403
local results = results_by_operators[operator]
399404
assert(results ~= nil)
400405

401-
for i = 1, #eq_conds do
402-
local comp_value_code = table.concat({
403-
string.format(' if %s then return %s end', lt_conds[i], results.le),
404-
string.format(' if not %s then return %s end', eq_conds[i], results.not_eq),
405-
'',
406-
}, '\n')
406+
if #eq_conds > 0 then
407+
for i = 1, #eq_conds do
408+
local comp_value_code = table.concat({
409+
string.format(' if %s then return %s end', lt_conds[i], results.le),
410+
string.format(' if not %s then return %s end', eq_conds[i], results.not_eq),
411+
'',
412+
}, '\n')
407413

408-
table.insert(func_code_lines, comp_value_code)
409-
end
414+
table.insert(func_code_lines, comp_value_code)
415+
end
410416

411-
local return_code = (' return %s'):format(results.default)
412-
table.insert(func_code_lines, return_code)
417+
local return_code = (' return %s'):format(results.default)
418+
table.insert(func_code_lines, return_code)
419+
else -- nil condition is treated as no condition
420+
local return_line = ' return true'
421+
table.insert(func_code_lines, return_line)
422+
end
413423

414424
table.insert(func_code_lines, 'end')
415425

test/helper.lua

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -962,6 +962,10 @@ function helpers.is_decimal_supported()
962962
return crud_utils.tarantool_supports_decimals()
963963
end
964964

965+
function helpers.is_uuid_supported()
966+
return crud_utils.tarantool_supports_uuids()
967+
end
968+
965969
function helpers.is_datetime_supported()
966970
return crud_utils.tarantool_supports_datetimes()
967971
end

test/integration/count_test.lua

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -893,3 +893,11 @@ for case_name_template, case in pairs(gh_373_types_cases) do
893893
case(g, read_impl)
894894
end
895895
end
896+
897+
for case_name_template, case in pairs(read_scenario.gh_422_nullability_cases) do
898+
local case_name = 'test_' .. case_name_template:format('count')
899+
900+
pgroup[case_name] = function(g)
901+
case(g, read_impl)
902+
end
903+
end

test/integration/pairs_readview_test.lua

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -936,3 +936,11 @@ pgroup.after_test(
936936
'test_pairs_merger_process_storage_error',
937937
read_scenario.after_merger_process_storage_error
938938
)
939+
940+
for case_name_template, case in pairs(read_scenario.gh_422_nullability_cases) do
941+
local case_name = 'test_' .. case_name_template:format('pairs')
942+
943+
pgroup[case_name] = function(g)
944+
case(g, read_impl)
945+
end
946+
end

test/integration/pairs_test.lua

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -944,3 +944,11 @@ pgroup.after_test(
944944
'test_pairs_merger_process_storage_error',
945945
read_scenario.after_merger_process_storage_error
946946
)
947+
948+
for case_name_template, case in pairs(read_scenario.gh_422_nullability_cases) do
949+
local case_name = 'test_' .. case_name_template:format('pairs')
950+
951+
pgroup[case_name] = function(g)
952+
case(g, read_impl)
953+
end
954+
end

0 commit comments

Comments
 (0)