From d0001993187bcdfb917b001840f7d247403ef5f6 Mon Sep 17 00:00:00 2001 From: Sergey Bronnikov Date: Tue, 14 Sep 2021 21:56:57 +0300 Subject: [PATCH] Rename utils.extract_key() -> extract_from_tuple() 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 --- crud/common/sharding.lua | 2 +- crud/common/utils.lua | 2 +- crud/compare/comparators.lua | 4 ++-- crud/select/executor.lua | 2 +- crud/select/plan.lua | 2 +- test/unit/serialization_test.lua | 6 +++--- 6 files changed, 9 insertions(+), 9 deletions(-) diff --git a/crud/common/sharding.lua b/crud/common/sharding.lua index 964130922..f0630cf6e 100644 --- a/crud/common/sharding.lua +++ b/crud/common/sharding.lua @@ -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 diff --git a/crud/common/utils.lua b/crud/common/utils.lua index 9c8f8287e..58da32c5e 100644 --- a/crud/common/utils.lua +++ b/crud/common/utils.lua @@ -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] diff --git a/crud/compare/comparators.lua b/crud/compare/comparators.lua index e59bf0531..f7e283cbc 100644 --- a/crud/compare/comparators.lua +++ b/crud/compare/comparators.lua @@ -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 diff --git a/crud/select/executor.lua b/crud/select/executor.lua index 6d6f74837..f466fc23a 100644 --- a/crud/select/executor.lua +++ b/crud/select/executor.lua @@ -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 diff --git a/crud/select/plan.lua b/crud/select/plan.lua index cc97e1039..dad409698 100644 --- a/crud/select/plan.lua +++ b/crud/select/plan.lua @@ -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 diff --git a/test/unit/serialization_test.lua b/test/unit/serialization_test.lua index 5decefe47..ed1a0e024 100644 --- a/test/unit/serialization_test.lua +++ b/test/unit/serialization_test.lua @@ -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})