@@ -2,10 +2,18 @@ local errors = require('errors')
22
33local compare_conditions = require (' crud.compare.conditions' )
44local type_comparators = require (' crud.compare.type_comparators' )
5- local operators = compare_conditions .operators
6-
75local utils = require (' crud.common.utils' )
86
7+ local compat = require (' crud.common.compat' )
8+ local has_keydef = compat .exists (' tuple.keydef' , ' key_def' )
9+
10+ local keydef_lib
11+ if has_keydef then
12+ keydef_lib = compat .require (' tuple.keydef' , ' key_def' )
13+ end
14+
15+ local operators = compare_conditions .operators
16+
917local ComparatorsError = errors .new_class (' ComparatorsError' )
1018
1119local comparators = {}
@@ -102,7 +110,8 @@ function comparators.update_key_parts_by_field_names(space_format, field_names,
102110 local field_name = space_format [part .fieldno ].name
103111 local updated_part = {type = part .type ,
104112 fieldno = fields_positions [field_name ],
105- is_nullable = part .is_nullable }
113+ is_nullable = part .is_nullable ,
114+ path = part .path }
106115 table.insert (updated_key_parts , updated_part )
107116 end
108117
@@ -150,13 +159,22 @@ function comparators.gen_tuples_comparator(cmp_operator, key_parts, field_names,
150159 local updated_key_parts = comparators .update_key_parts_by_field_names (
151160 space_format , field_names , key_parts
152161 )
153- local keys_comparator = comparators .gen_func (cmp_operator , updated_key_parts )
154162
155- return function (lhs , rhs )
156- local lhs_key = utils .extract_key (lhs , updated_key_parts )
157- local rhs_key = utils .extract_key (rhs , updated_key_parts )
163+ local keys_comparator = comparators .gen_func (cmp_operator , updated_key_parts )
158164
159- return keys_comparator (lhs_key , rhs_key )
165+ if has_keydef then
166+ local key_def = keydef_lib .new (updated_key_parts )
167+ return function (lhs , rhs )
168+ local lhs_key = key_def :extract_key (lhs )
169+ local rhs_key = key_def :extract_key (rhs )
170+ return keys_comparator (lhs_key , rhs_key )
171+ end
172+ else
173+ return function (lhs , rhs )
174+ local lhs_key = utils .extract_key (lhs , updated_key_parts )
175+ local rhs_key = utils .extract_key (rhs , updated_key_parts )
176+ return keys_comparator (lhs_key , rhs_key )
177+ end
160178 end
161179end
162180
0 commit comments