def process_result_set(self): """ @return: a Topo_Diff object consisting of the commit node and parent link """ ret = Topo_Diff() hash_parent = None hash_child = None ts_created = None for _, _, r_set in self.iter__r_set(): for row in r_set: for ret_dict in row: assert None == hash_parent # assert hash values set once only assert None == hash_child assert None == ts_created hash_parent = ret_dict['head_parent_commit']['hash'] hash_child = ret_dict['head_commit']['hash'] ts_created = ret_dict['ts_created'] ret.node_set_add = [{'id': self.n_id, '__label_set': ['__Commit']}] l = Link.Link_Ptr(src_id=hash_parent, dst_id=hash_child) l['id'] = self.l_id l['__type'] = '__Parent' ret.link_set_add = [l] ret.meta['ts_created'] = ts_created return ret
def deserialize_param_set(param_json): l_ptr_set_raw = param_json['link_ptr_set'] __sanitize_input(l_ptr_set_raw) l_ptr_set = [] for lptr_dict in l_ptr_set_raw: src_id = lptr_dict.get('__src_id') dst_id = lptr_dict.get('__dst_id') l_ptr_set += [Link.Link_Ptr(src_id=src_id, dst_id=dst_id)] return l_ptr_set
def process_result_set(self): ret_n_set = [] ret_l_set = [] for _, _, r_set in self.iter__r_set(): for row in r_set: n, n_lbl_set, l_set = row.items() # see query return statement # reconstruct nodes assert None != n.get('id'), "db contains nodes with no id" n['__label_set'] = self.process_q_ret__n_label_set(n_lbl_set) ret_n_set.append(n) # reconstruct links from link tuples for l_tuple in l_set: assert 3 == len(l_tuple) # see query return statement if None == l_tuple[0]: # check if link dst is None # as link matching is optional, collect may yield empty sets continue ret_l, ret_l_type, ret_l_dst_id = l_tuple l = Link.Link_Ptr(src_id=n['id'], dst_id=ret_l_dst_id) l['id'] = ret_l['id'] l['__type'] = self.process_q_ret__l_type(ret_l_type) ret_l_set.append(l) if len(ret_n_set ) >= self.limit: # TODO: generalize logic, mv to DB_Driver log.warning( 'DB op result set larger than query limit: size: %d, limit: %d' % (len(ret_n_set), self.limit)) topo_diff = Topo_Diff(node_set_add=ret_n_set, link_set_add=ret_l_set) return topo_diff