@@ -320,8 +320,12 @@ local function process_tuple(self, state, tuple, opts)
320
320
local variables = qcontext .variables
321
321
322
322
-- convert tuple -> object
323
- local obj = opts .unflatten_tuple (self , collection_name , tuple ,
324
- { use_tomap = opts .use_tomap }, opts .default_unflatten_tuple )
323
+ local avro_opts = {
324
+ use_tomap = opts .use_tomap ,
325
+ user_context = qcontext .user_context ,
326
+ }
327
+ local obj = opts .unflatten_tuple (self , collection_name , tuple , avro_opts ,
328
+ opts .default_unflatten_tuple )
325
329
326
330
-- skip all items before pivot (the item pointed by offset)
327
331
if not state .pivot_found and pivot_filter then
@@ -383,15 +387,18 @@ end
383
387
---
384
388
--- @tparam table selected objects to perform the operation
385
389
---
390
+ --- @tparam table avro_opts options for the unflatten_tuple() accessor function
391
+ ---
386
392
--- @tparam string operation 'update_tuple' or 'delete_tuple'
387
393
---
388
394
--- @param [opt ] ... parameters to pass to the function
389
395
---
390
396
--- @treturn table `new_objects` list of returned objects (in the order of the
391
397
--- `selected` parameter)
392
398
local function perform_primary_key_operation (self , collection_name , schema_name ,
393
- selected , operation , ...)
399
+ selected , avro_opts , operation , ...)
394
400
check (operation , ' operation' , ' string' )
401
+ check (avro_opts , ' avro_opts' , ' table' )
395
402
396
403
local _ , primary_index_meta = db_schema_helpers .get_primary_index_meta (
397
404
self , collection_name )
@@ -407,8 +414,7 @@ local function perform_primary_key_operation(self, collection_name, schema_name,
407
414
-- delete_tuple to save one get operation
408
415
local new_tuple = self .funcs [operation ](self , collection_name , key , ... )
409
416
local new_object = self .funcs .unflatten_tuple (self , collection_name ,
410
- new_tuple , {use_tomap = self .collection_use_tomap [collection_name ]},
411
- self .default_unflatten_tuple [schema_name ])
417
+ new_tuple , avro_opts , self .default_unflatten_tuple [schema_name ])
412
418
table.insert (new_objects , new_object )
413
419
end
414
420
@@ -449,21 +455,28 @@ local function prepare_select_internal(self, collection_name, from, filter,
449
455
-- XXX: save type of args.offset at parsing and check here
450
456
-- check(args.offset, 'args.offset', ...)
451
457
check (args .pcre , ' args.pcre' , ' table' , ' nil' )
458
+ check (extra , ' extra' , ' table' )
452
459
check (extra .exp_tuple_count , ' extra.exp_tuple_count' , ' number' , ' nil' )
453
460
461
+ local qcontext = extra .qcontext
462
+ check (qcontext , ' qcontext' , ' table' )
463
+ local get_index_opts = {user_context = qcontext .user_context }
464
+
454
465
local collection = self .collections [collection_name ]
455
466
assert (collection ~= nil ,
456
467
(' cannot find the collection "%s"' ):format (
457
468
collection_name ))
458
- assert (self .funcs .is_collection_exists (self , collection_name ),
459
- (' cannot find collection "%s"' ):format (collection_name ))
469
+ assert (self .funcs .is_collection_exists (self , collection_name ,
470
+ get_index_opts ), (' cannot find collection "%s"' ):format (
471
+ collection_name ))
460
472
461
473
-- search for suitable index
462
474
-- note: we redefine filter here
463
475
local full_match , index_name , filter , index_value , pivot =
464
476
self .index_finder :find (collection_name , from , filter , args )
465
477
local index = index_name ~= nil and
466
- self .funcs .get_index (self , collection_name , index_name ) or nil
478
+ self .funcs .get_index (self , collection_name , index_name ,
479
+ get_index_opts ) or nil
467
480
if index_name ~= nil and index == nil then
468
481
error ((' cannot find actual index "%s" in the collection "%s", ' ..
469
482
' but the index metainformation contains it' ):format (index_name ,
@@ -486,7 +499,6 @@ local function prepare_select_internal(self, collection_name, from, filter,
486
499
collection_name ))
487
500
488
501
-- read-write variables for process_tuple
489
- local qcontext = extra .qcontext
490
502
local select_state = {
491
503
count = 0 ,
492
504
objs = {},
@@ -541,7 +553,8 @@ local function prepare_select_internal(self, collection_name, from, filter,
541
553
if index == nil then
542
554
assert (pivot == nil ,
543
555
' offset for top-level objects must use a primary index' )
544
- index = self .funcs .get_primary_index (self , collection_name )
556
+ index = self .funcs .get_primary_index (self , collection_name ,
557
+ get_index_opts )
545
558
index_value = nil
546
559
is_full_scan = true
547
560
else
@@ -605,6 +618,7 @@ local function invoke_select_internal(self, prepared_select)
605
618
local collection_name = prepared_select .collection_name
606
619
local args = prepared_select .args
607
620
local extra = prepared_select .extra
621
+ local qcontext = extra .qcontext
608
622
609
623
local index = request_opts .index
610
624
local index_name = request_opts .index_name
@@ -618,8 +632,9 @@ local function invoke_select_internal(self, prepared_select)
618
632
-- lookup for needed data in the cache if it is supported
619
633
local iterable
620
634
if self :cache_is_supported () then
635
+ local cache_opts = {user_context = qcontext .user_context }
621
636
iterable = self .funcs .cache_lookup (self , collection_name , index_name ,
622
- index_value , iterator_opts )
637
+ index_value , iterator_opts , cache_opts )
623
638
end
624
639
if iterable == nil then
625
640
iterable = index
@@ -698,23 +713,30 @@ local function insert_internal(self, collection_name, from, filter, args, extra)
698
713
-- allow only top level collection
699
714
check (from .collection_name , ' from.collection_name' , ' nil' )
700
715
701
- -- convert object -> tuple (set default values from a schema)
702
716
local schema_name = db_schema_helpers .get_schema_name (self , collection_name )
717
+ local qcontext = extra .qcontext
718
+ local avro_opts = {
719
+ use_tomap = self .collection_use_tomap [collection_name ],
720
+ service_fields_defaults = self .service_fields_defaults [schema_name ],
721
+ user_context = qcontext .user_context ,
722
+ }
723
+ local dml_opts = {
724
+ user_context = qcontext .user_context ,
725
+ }
726
+
727
+ -- convert object -> tuple (set default values from a schema)
703
728
local default_flatten_object = self .default_flatten_object [schema_name ]
704
729
assert (default_flatten_object ~= nil ,
705
730
(' cannot find default_flatten_object ' ..
706
731
' for collection "%s"' ):format (collection_name ))
707
- local tuple = self .funcs .flatten_object (self , collection_name , object , {
708
- service_fields_defaults =
709
- self .service_fields_defaults [schema_name ],
710
- }, default_flatten_object )
732
+ local tuple = self .funcs .flatten_object (self , collection_name , object ,
733
+ avro_opts , default_flatten_object )
711
734
712
735
-- insert tuple & tuple -> object (with default values set before)
713
- local new_tuple = self .funcs .insert_tuple (self , collection_name , tuple )
714
- local use_tomap = self . collection_use_tomap [ collection_name ]
736
+ local new_tuple = self .funcs .insert_tuple (self , collection_name , tuple ,
737
+ dml_opts )
715
738
local new_object = self .funcs .unflatten_tuple (self , collection_name ,
716
- new_tuple , {use_tomap = use_tomap },
717
- self .default_unflatten_tuple [schema_name ])
739
+ new_tuple , avro_opts , self .default_unflatten_tuple [schema_name ])
718
740
719
741
return {new_object }
720
742
end
@@ -742,19 +764,27 @@ local function update_internal(self, collection_name, extra, selected)
742
764
' arguments'
743
765
assert (next (extra .extra_args , next (extra .extra_args )) == nil , err_msg )
744
766
745
- -- convert xobject -> update statements
746
767
local schema_name = db_schema_helpers .get_schema_name (self , collection_name )
768
+ local qcontext = extra .qcontext
769
+ local avro_opts = {
770
+ use_tomap = self .collection_use_tomap [collection_name ],
771
+ service_fields_defaults = self .service_fields_defaults [schema_name ],
772
+ user_context = qcontext .user_context ,
773
+ }
774
+ local dml_opts = {
775
+ user_context = qcontext .user_context ,
776
+ }
777
+
778
+ -- convert xobject -> update statements
747
779
local default_xflatten = self .default_xflatten [schema_name ]
748
780
assert (default_xflatten ~= nil ,
749
781
(' cannot find default_xflatten ' ..
750
782
' for collection "%s"' ):format (collection_name ))
751
- local statements = self .funcs .xflatten (self , collection_name , xobject , {
752
- service_fields_defaults =
753
- self .service_fields_defaults [schema_name ],
754
- }, default_xflatten )
783
+ local statements = self .funcs .xflatten (self , collection_name , xobject ,
784
+ avro_opts , default_xflatten )
755
785
756
786
return perform_primary_key_operation (self , collection_name , schema_name ,
757
- selected , ' update_tuple' , statements )
787
+ selected , avro_opts , ' update_tuple' , statements , dml_opts )
758
788
end
759
789
760
790
--- Delete an object.
@@ -778,10 +808,18 @@ local function delete_internal(self, collection_name, extra, selected)
778
808
' arguments'
779
809
assert (next (extra .extra_args , next (extra .extra_args )) == nil , err_msg )
780
810
811
+ local qcontext = extra .qcontext
781
812
local schema_name = db_schema_helpers .get_schema_name (self , collection_name )
782
813
814
+ local avro_opts = {
815
+ use_tomap = self .collection_use_tomap [collection_name ],
816
+ user_context = qcontext .user_context ,
817
+ }
818
+ local dml_opts = {
819
+ user_context = qcontext .user_context ,
820
+ }
783
821
return perform_primary_key_operation (self , collection_name , schema_name ,
784
- selected , ' delete_tuple' )
822
+ selected , avro_opts , ' delete_tuple' , dml_opts )
785
823
end
786
824
787
825
--- Set of asserts to check the `funcs` argument of the @{accessor_general.new}
@@ -1122,7 +1160,8 @@ function accessor_general.new(opts, funcs)
1122
1160
return nil
1123
1161
end
1124
1162
1125
- local res = self .funcs .cache_fetch (self , batches )
1163
+ local cache_opts = {user_context = qcontext .user_context }
1164
+ local res = self .funcs .cache_fetch (self , batches , cache_opts )
1126
1165
if res == nil then
1127
1166
return nil
1128
1167
end
@@ -1151,17 +1190,19 @@ function accessor_general.new(opts, funcs)
1151
1190
return fetch_id
1152
1191
end ,
1153
1192
-- Unused for now.
1154
- -- cache_delete = function(self, fetch_id)
1193
+ -- cache_delete = function(self, fetch_id, qcontext )
1155
1194
-- if not self:cache_is_supported() then
1156
1195
-- return
1157
1196
-- end
1158
- -- self.funcs.cache_delete(self, fetch_id)
1197
+ -- local cache_opts = {user_context = qcontext.user_context}
1198
+ -- self.funcs.cache_delete(self, fetch_id, cache_opts)
1159
1199
-- end,
1160
- cache_truncate = function (self )
1200
+ cache_truncate = function (self , qcontext )
1161
1201
if not self :cache_is_supported () then
1162
1202
return
1163
1203
end
1164
- self .funcs .cache_truncate (self )
1204
+ local cache_opts = {user_context = qcontext .user_context }
1205
+ self .funcs .cache_truncate (self , cache_opts )
1165
1206
end ,
1166
1207
}
1167
1208
})
0 commit comments