Skip to content

Commit

Permalink
Rename utils.extract_key() -> extract_from_tuple()
Browse files Browse the repository at this point in the history
We have functions that have similar purpose - extract key values:

- sharding_key_module.extract_from_pk()
- sharding_key_module.extract_from_index()

Patch renames utils.extract_key() to utils.extract_from_tuple() to make
function's names consistent and make code clear.

Part of #166
  • Loading branch information
ligurio committed Sep 30, 2021
1 parent 51ab777 commit d000199
Show file tree
Hide file tree
Showing 6 changed files with 9 additions and 9 deletions.
2 changes: 1 addition & 1 deletion crud/common/sharding.lua
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ function sharding.tuple_get_bucket_id(tuple, space, specified_bucket_id)
end
sharding_index_parts = sharding_key_fieldnos.parts
end
local key = utils.extract_key(tuple, sharding_index_parts)
local key = utils.extract_from_tuple(tuple, sharding_index_parts)

return sharding.key_get_bucket_id(key)
end
Expand Down
2 changes: 1 addition & 1 deletion crud/common/utils.lua
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ function utils.unflatten(tuple, space_format)
return object
end

function utils.extract_key(tuple, key_parts)
function utils.extract_from_tuple(tuple, key_parts)
local key = {}
for i, part in ipairs(key_parts) do
key[i] = tuple[part.fieldno]
Expand Down
4 changes: 2 additions & 2 deletions crud/compare/comparators.lua
Original file line number Diff line number Diff line change
Expand Up @@ -171,8 +171,8 @@ function comparators.gen_tuples_comparator(cmp_operator, key_parts, field_names,
end
else
return function(lhs, rhs)
local lhs_key = utils.extract_key(lhs, updated_key_parts)
local rhs_key = utils.extract_key(rhs, updated_key_parts)
local lhs_key = utils.extract_from_tuple(lhs, updated_key_parts)
local rhs_key = utils.extract_from_tuple(rhs, updated_key_parts)
return keys_comparator(lhs_key, rhs_key)
end
end
Expand Down
2 changes: 1 addition & 1 deletion crud/select/executor.lua
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ else
generate_value = function(after_tuple, scan_value, index_parts, tarantool_iter)
local cmp_operator = select_comparators.get_cmp_operator(tarantool_iter)
local scan_comparator = select_comparators.gen_tuples_comparator(cmp_operator, index_parts)
local after_tuple_key = utils.extract_key(after_tuple, index_parts)
local after_tuple_key = utils.extract_from_tuple(after_tuple, index_parts)
if scan_comparator(after_tuple_key, scan_value) then
return after_tuple_key
end
Expand Down
2 changes: 1 addition & 1 deletion crud/select/plan.lua
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,7 @@ function select_plan.new(space, conditions, opts)
local key_def = keydef_lib.new(scan_index.parts)
scan_value = key_def:extract_key(scan_after_tuple)
else
scan_value = utils.extract_key(scan_after_tuple, scan_index.parts)
scan_value = utils.extract_from_tuple(scan_after_tuple, scan_index.parts)
end
else
scan_value = nil
Expand Down
6 changes: 3 additions & 3 deletions test/unit/serialization_test.lua
Original file line number Diff line number Diff line change
Expand Up @@ -150,13 +150,13 @@ g.test_unflatten = function()
})
end

g.test_extract_key = function()
g.test_extract_from_tuple = function()
local tuple = {1, nil, 'Marilyn', 50}

local key = utils.extract_key(tuple, {{fieldno = 1}})
local key = utils.extract_from_tuple(tuple, {{fieldno = 1}})
t.assert_equals(key, {1})

local key = utils.extract_key(tuple, {
local key = utils.extract_from_tuple(tuple, {
{fieldno = 3}, {fieldno = 2}, {fieldno = 1},
})
t.assert_equals(key, {'Marilyn', nil, 1})
Expand Down

0 comments on commit d000199

Please sign in to comment.