@@ -58,26 +58,27 @@ def execute_batch(q: Commands, blobs: Blobs, db: Connector,
5858 blobs_end = blobs_start + blobs_per_query
5959
6060 b_count = 0
61- for req , resp in zip (q [start :end ], r [start :end ]):
62- for k in req :
63- # Ref to https://docs.aperturedata.io/query_language/Reference/shared_command_parameters/blobs
64- blobs_where_default_true = \
65- k in ["FindImage" , "FindBlob" , "FindVideo" ] and (
66- "blobs" not in req [k ] or req [k ]["blobs" ])
67- blobs_where_default_false = \
68- k in [
69- "FindDescriptor" , "FindBoundingBox" ] and "blobs" in req [k ] and req [k ]["blobs" ]
70- if blobs_where_default_true or blobs_where_default_false :
71- count = resp [k ]["returned" ]
72- b_count += count
61+ if issubclass (type (r ), list ):
62+ for req , resp in zip (q [start :end ], r [start :end ]):
63+ for k in req :
64+ # Ref to https://docs.aperturedata.io/query_language/Reference/shared_command_parameters/blobs
65+ blobs_where_default_true = \
66+ k in ["FindImage" , "FindBlob" , "FindVideo" ] and (
67+ "blobs" not in req [k ] or req [k ]["blobs" ])
68+ blobs_where_default_false = \
69+ k in [
70+ "FindDescriptor" , "FindBoundingBox" ] and "blobs" in req [k ] and req [k ]["blobs" ]
71+ if blobs_where_default_true or blobs_where_default_false :
72+ count = resp [k ]["returned" ]
73+ b_count += count
7374
7475 try :
7576 # The returned blobs need to be sliced to match the
7677 # returned entities per command in query.
7778 response_handler (
7879 q [start :end ],
7980 blobs [blobs_start :blobs_end ],
80- r [start :end ],
81+ r [start :end ] if issubclass ( type ( r ), list ) else r ,
8182 b [blobs_returned :blobs_returned + b_count ] if len (b ) >= blobs_returned + b_count else None )
8283 except BaseException as e :
8384 logger .exception (e )
@@ -184,14 +185,23 @@ def update_refs(batched_commands):
184185 values ["image_ref" ] = updates [values ["image_ref" ]]
185186 if "video_ref" in values :
186187 values ["video_ref" ] = updates [values ["video_ref" ]]
187- if "is_connected_to" in values and "_ref" in values ["is_connected_to" ]:
188- values ["is_connected_to" ]["_ref" ] = updates [values ["is_connected_to" ]["_ref" ]]
188+ if "is_connected_to" in values :
189+ if "ref" in values ["is_connected_to" ]:
190+ values ["is_connected_to" ]["ref" ] = updates [values ["is_connected_to" ]["ref" ]]
191+ for op in ["any" , "all" ]:
192+ if op in values ["is_connected_to" ]:
193+ for idx in range (len (values ["is_connected_to" ][op ])):
194+ if "ref" in values ["is_connected_to" ][op ][idx ]:
195+ values ["is_connected_to" ][op ][idx ]["ref" ] = updates [values ["is_connected_to" ][op ][idx ]["ref" ]]
189196 if "connect" in values and "ref" in values ["connect" ]:
190197 values ["connect" ]["ref" ] = updates [values ["connect" ]["ref" ]]
191198 if "src" in values :
192199 values ["src" ] = updates [values ["src" ]]
193200 if "dst" in values :
194201 values ["dst" ] = updates [values ["dst" ]]
202+ if "ref" in values :
203+ values ["ref" ] = updates [values ["ref" ]]
204+
195205 return batched_commands
196206
197207 q = update_refs ([cmd for query in data for cmd in query [0 ]])
@@ -274,8 +284,11 @@ def filter_per_group(group):
274284 [v ['status' ] == 2 for i in r for k , v in filter_per_group (i )])
275285 sq = 0
276286 for i in range (0 , len (r ), self .commands_per_query ):
277- if all ([v ['status' ] == 0 for j in r [i :i + self .commands_per_query ] for k , v in filter_per_group (j )]):
278- sq += 1
287+ # Some errors stop the whole query from being executed
288+ # https://docs.aperturedata.io/query_language/Overview/Responses#return-status
289+ if issubclass (type (r ), list ):
290+ if all ([v ['status' ] == 0 for j in r [i :i + self .commands_per_query ] for k , v in filter_per_group (j )]):
291+ sq += 1
279292 worker_stats ["succeeded_queries" ] = sq
280293 else :
281294 query_time = 1
0 commit comments