@@ -145,11 +145,17 @@ def delete_edge(self, src_id, dst_id, edge_type: str = None) -> GbaseExecStatus:
145145
146146 def delete_edges (self , id_pairs : List , edge_type : str = None ) -> GbaseExecStatus :
147147 # geabase 不支持直接根据边关系进行检索
148- src_id , dst_id , timestamp = self .get_current_edgeID (src_id , dst_id , edge_type )
149- # src_id, dst_id = double_hashing(src_id), double_hashing(dst_id)
150- gql = f"MATCH ()-[e:{ edge_type } {{@src_id:{ src_id } , @dst_id:{ dst_id } }}]->() DELETE e"
151- gql = f"MATCH (n:opsgptkg_intent )-[r]->(t1) DELETE r"
152- return self ._get_crud_status (self .execute (gql ))
148+ try :
149+ src_id , dst_id , timestamp = self .get_current_edgeID (src_id , dst_id , edge_type )
150+ # src_id, dst_id = double_hashing(src_id), double_hashing(dst_id)
151+ gql = f"MATCH ()-[e:{ edge_type } {{@src_id:{ src_id } , @dst_id:{ dst_id } }}]->() DELETE e"
152+ gql = f"MATCH (n:opsgptkg_intent )-[r]->(t1) DELETE r"
153+ return self ._get_crud_status (self .execute (gql ))
154+ except Exception as e :
155+ return GbaseExecStatus (
156+ errorMessage = e ,
157+ errorCode = - 1 ,
158+ )
153159
154160 def get_nodeIDs (self , attributes : dict , node_type : str ) -> List [int ]:
155161 result = self .get_current_nodes (attributes , node_type )
@@ -236,22 +242,30 @@ def check_neighbor_exist(self, attributes: dict, node_type: str = None, check_at
236242 filter_result = [i for i in result if all ([item in i .attributes .items () for item in check_attributes .items ()])]
237243 return len (filter_result ) > 0
238244
239- def get_hop_infos (self , attributes : dict , node_type : str = None , hop : int = 2 , block_attributes : List [dict ] = [], select_attributes : dict = {}, reverse = False ) -> Graph :
245+ def get_hop_infos (
246+ self ,
247+ attributes : dict ,
248+ node_type : str = None ,
249+ hop : int = 2 ,
250+ block_attributes : List [dict ] = [],
251+ select_attributes : dict = {},
252+ reverse = False
253+ ) -> Graph :
240254 '''
241- hop >= 2, 表面需要至少两跳
255+ hop >= 1
242256 '''
243257 hop_max = self .hop_max
244258 #
245259 where_str = ' and ' .join ([f"n0.{ k } ='{ v } '" for k , v in attributes .items ()])
246260 if reverse :
247- gql = f"MATCH p = (n0:{ node_type } WHERE { where_str } )<-[e]-{{1 ,{ min (hop , hop_max )} }}(n1) RETURN n0, n1, e, p"
261+ gql = f"MATCH p = (n0:{ node_type } WHERE { where_str } )<-[e]-{{0 ,{ min (hop , hop_max )} }}(n1) RETURN n0, n1, e, p"
248262 else :
249- gql = f"MATCH p = (n0:{ node_type } WHERE { where_str } )-[e]->{{1 ,{ min (hop , hop_max )} }}(n1) RETURN n0, n1, e, p"
263+ gql = f"MATCH p = (n0:{ node_type } WHERE { where_str } )-[e]->{{0 ,{ min (hop , hop_max )} }}(n1) RETURN n0, n1, e, p"
250264 last_node_ids , last_node_types = [], []
251265
252266 result = {}
253267 iter_index = 0
254- while hop > 1 :
268+ while hop >= 1 :
255269 if last_node_ids == [] and iter_index == 0 :
256270 #
257271 result = self .execute (gql )
@@ -272,7 +286,8 @@ def get_hop_infos(self, attributes: dict, node_type: str = None, hop: int = 2, b
272286
273287 result = self .merge_hotinfos (result , _result , reverse = reverse )
274288 #
275- last_node_ids , last_node_types , result = self .deduplicate_paths (result , block_attributes , select_attributes , hop = min (hop , hop_max )+ iter_index * hop_max , reverse = reverse )
289+ last_node_ids , last_node_types , result = self .deduplicate_paths (
290+ result , block_attributes , select_attributes , hop = min (hop , hop_max )+ iter_index * hop_max , reverse = reverse )
276291 hop -= hop_max
277292 iter_index += 1
278293
@@ -381,6 +396,7 @@ def decode_result(self, geabase_result, gql: str) -> Dict:
381396 for col_data , rk , sk in zip (row ["columns" ], return_keys , save_keys ):
382397 _decode_func = decode_geabase_result_func_by_key .get (sk , self .decode_attribute )
383398 # print(sk, json.dumps(col_data, ensure_ascii=False, indent=2))
399+ if col_data is None or col_data == {}: continue
384400 decode_reuslt = _decode_func (col_data , rk )
385401 if ".attr" in sk :
386402 attr_dict .setdefault (sk , {}).update (decode_reuslt )
@@ -447,8 +463,17 @@ def decode_edge(self, col_data, k) -> Dict:
447463 def _decode_edge (data ):
448464 edgeVal = data .get ("edgeVal" , {})
449465 edge_val_json = {
450- ** {"SRCID" : int (edgeVal .get ("srcId" , "" )), "DSTID" : int (edgeVal .get ("dstId" , "" )), "type" : edgeVal .get ("type" , "" )},
451- ** {k : v .get ("strVal" , "" ) if "strVal" in v else v .get ("intVal" , "0" ) for k , v in edgeVal .get ("props" , {}).items ()}
466+ ** {
467+ "SRCID" : int (edgeVal .get ("srcId" , "" )),
468+ "DSTID" : int (edgeVal .get ("dstId" , "" )),
469+ "type" : edgeVal .get ("type" , "" ),
470+ "timestamp" : int (edgeVal .get ("timestamp" , "1" ))
471+ },
472+ ** {
473+ k : v .get ("strVal" , "" )
474+ if "strVal" in v else v .get ("intVal" , "0" )
475+ for k , v in edgeVal .get ("props" , {}).items ()
476+ }
452477 }
453478 # 存在业务逻辑
454479 edge_val_json ["start_id" ] = edge_val_json .pop ("original_src_id1__" )
0 commit comments