@@ -33,6 +33,7 @@ local function select_on_storage(space_name, index_id, conditions, opts)
3333 iter = ' number' ,
3434 limit = ' number' ,
3535 scan_condition_num = ' ?number' ,
36+ field_names = ' ?table' ,
3637 })
3738
3839 local space = box .space [space_name ]
@@ -64,7 +65,9 @@ local function select_on_storage(space_name, index_id, conditions, opts)
6465 return nil , SelectError :new (" Failed to execute select: %s" , err )
6566 end
6667
67- return tuples
68+ -- getting tuples with user defined fields (if `fields` option is specified)
69+ -- and fields that are needed for comparison on router (primary key + scan key)
70+ return schema .filter_tuples_fields (tuples , opts .field_names )
6871end
6972
7073function select_module .init ()
@@ -86,6 +89,7 @@ local function select_iteration(space_name, plan, opts)
8689 iter = plan .iter ,
8790 limit = opts .limit ,
8891 scan_condition_num = plan .scan_condition_num ,
92+ field_names = plan .field_names ,
8993 }
9094
9195 local storage_select_args = {
@@ -125,6 +129,7 @@ local function build_select_iterator(space_name, user_conditions, opts)
125129 timeout = ' ?number' ,
126130 batch_size = ' ?number' ,
127131 bucket_id = ' ?number|cdata' ,
132+ field_names = ' ?table' ,
128133 })
129134
130135 opts = opts or {}
@@ -157,6 +162,7 @@ local function build_select_iterator(space_name, user_conditions, opts)
157162 local plan , err = select_plan .new (space , conditions , {
158163 first = opts .first ,
159164 after_tuple = opts .after ,
165+ field_names = opts .field_names ,
160166 })
161167
162168 if err ~= nil then
@@ -181,16 +187,27 @@ local function build_select_iterator(space_name, user_conditions, opts)
181187 local primary_index = space .index [0 ]
182188 local cmp_key_parts = utils .merge_primary_key_parts (scan_index .parts , primary_index .parts )
183189 local cmp_operator = select_comparators .get_cmp_operator (plan .iter )
190+
191+ -- generator of tuples comparator needs field_names and space_format
192+ -- to update fieldno in each part in cmp_key_parts because storage result contains
193+ -- fields in order specified by field_names
184194 local tuples_comparator , err = select_comparators .gen_tuples_comparator (
185- cmp_operator , cmp_key_parts
195+ cmp_operator , cmp_key_parts , opts . field_names , space_format
186196 )
187197 if err ~= nil then
188198 return nil , SelectError :new (" Failed to generate comparator function: %s" , err )
189199 end
190200
201+ -- filter space format by plan.field_names (user defined fields + primary key + scan key)
202+ -- to pass it user as metadata
203+ local filtered_space_format , err = utils .get_fields_format (space_format , plan .field_names )
204+ if err ~= nil then
205+ return nil , err
206+ end
207+
191208 local iter = Iterator .new ({
192209 space_name = space_name ,
193- space_format = space_format ,
210+ space_format = filtered_space_format ,
194211 iteration_func = select_iteration ,
195212 comparator = tuples_comparator ,
196213
@@ -213,6 +230,7 @@ function select_module.pairs(space_name, user_conditions, opts)
213230 batch_size = ' ?number' ,
214231 use_tomap = ' ?boolean' ,
215232 bucket_id = ' ?number|cdata' ,
233+ fields = ' ?table' ,
216234 })
217235
218236 opts = opts or {}
@@ -227,6 +245,7 @@ function select_module.pairs(space_name, user_conditions, opts)
227245 timeout = opts .timeout ,
228246 batch_size = opts .batch_size ,
229247 bucket_id = opts .bucket_id ,
248+ field_names = opts .fields ,
230249 }
231250
232251 local iter , err = schema .wrap_func_reload (
@@ -268,6 +287,7 @@ function select_module.call(space_name, user_conditions, opts)
268287 timeout = ' ?number' ,
269288 batch_size = ' ?number' ,
270289 bucket_id = ' ?number|cdata' ,
290+ fields = ' ?table' ,
271291 })
272292
273293 opts = opts or {}
@@ -284,6 +304,7 @@ function select_module.call(space_name, user_conditions, opts)
284304 timeout = opts .timeout ,
285305 batch_size = opts .batch_size ,
286306 bucket_id = opts .bucket_id ,
307+ field_names = opts .fields ,
287308 }
288309
289310 local iter , err = schema .wrap_func_reload (
@@ -313,7 +334,7 @@ function select_module.call(space_name, user_conditions, opts)
313334 end
314335
315336 return {
316- metadata = table . copy ( iter .space_format ) ,
337+ metadata = iter .space_format ,
317338 rows = tuples ,
318339 }
319340end
0 commit comments