def prepare( self, proto: dap_interface_pb2.ConstructQueryObjectRequest ) -> dap_interface_pb2.ConstructQueryMementoResponse: r = dap_interface_pb2.ConstructQueryMementoResponse() #print("NOD NAAME:", proto.node_name) # We'll let someone else handle any bigger branching logic. if len(proto.constraints) == 0 or len(proto.children) > 0: r.success = False return r # We'll let someone else handle anything which isn't an ALL if proto.operator != ProtoHelpers.COMBINER_ALL: #print("Not doing because not ALL") r.success = False return r geoQuery = DapGeo.DapGeoQuery(self) for constraint in proto.constraints: geoQuery.setTablename(constraint.target_table_name) geoQuery.setFieldname( constraint.target_field_name.partition('.')[0]) processes = { (geoQuery.tablename + ".location", "location"): lambda q, x: q.addLocation(x), (geoQuery.tablename + ".location", "location_list"): lambda q, x: q.addLocations(x), (geoQuery.tablename + ".radius", "double"): lambda q, x: q.addRadius(x), (geoQuery.tablename + ".radius", "float"): lambda q, x: q.addRadius(x), (geoQuery.tablename + ".radius", "int32"): lambda q, x: q.addRadius(x), (geoQuery.tablename + ".radius", "int64"): lambda q, x: q.addRadius(x), } for constraint in proto.constraints: func = processes.get( (constraint.target_field_name, constraint.query_field_type), None) if func == None: self.warning("Query cannot be made from ", constraint.target_field_name, " & ", constraint.query_field_type) r.success = False return r else: func(geoQuery, decodeConstraintValue(constraint.query_field_value)) geoQuery.setGeo(self.getGeoByTableName(geoQuery.tablename)) if geoQuery.sanity(): r.success = True r.memento = geoQuery.toJSON().encode('utf8') else: r.success = False return r
def prepareConstraint(self, proto: dap_interface_pb2.ConstructQueryConstraintObjectRequest) -> dap_interface_pb2.ConstructQueryMementoResponse: j = {} j['target_field_name'] = '*' j['target_field_type'] = '*' r = dap_interface_pb2.ConstructQueryMementoResponse() r.memento = json.dumps(j).encode('utf8') r.success = True return r
def prepare(self, proto: dap_interface_pb2.ConstructQueryObjectRequest) -> dap_interface_pb2.ConstructQueryMementoResponse: r = dap_interface_pb2.ConstructQueryMementoResponse() if proto.operator != "result": r.success = False return r self.stats["prepare_count"] += 1 r.memento = b"dummy_token" r.success = True return r
def prepareConstraint( self, proto: dap_interface_pb2.ConstructQueryConstraintObjectRequest ) -> dap_interface_pb2.ConstructQueryMementoResponse: q = SearchEngine.SubQuery().setSearchSystem(self).fromLeaf( DapQueryRepn.Leaf().fromProto(proto)).prepare() r = dap_interface_pb2.ConstructQueryMementoResponse() r.memento = q.toJSON().encode('utf8') r.success = True self.stats["prepare_constraint_count"] += 1 return r
def prepare(self, proto: dap_interface_pb2.ConstructQueryObjectRequest) -> dap_interface_pb2.ConstructQueryMementoResponse: r = dap_interface_pb2.ConstructQueryMementoResponse() if len(proto.constraints) == 0 or len(proto.children) > 0: self.info("No, I only want branches without branches.") r.success = False return r # We'll let someone else handle anything which isn't an ALL if proto.operator != ProtoHelpers.COMBINER_ALL: self.info("No, I only want branches doing AND.") r.success = False return r graphQuery = DapERNetwork.DapGraphQuery() for constraint in proto.constraints: graphQuery.setTablename(constraint.target_table_name) processes = { (graphQuery.tablename + ".origin", "string"): lambda q,x: q.addOriginStr(x), (graphQuery.tablename + ".origin", "string_list"): lambda q,x: q.addOriginsStrList(x), (graphQuery.tablename + ".origin", "string_pair"): lambda q,x: q.addOrigin(x), (graphQuery.tablename + ".origin", "string_pair_list"): lambda q,x: q.addOrigins(x), (graphQuery.tablename + ".label", "string"): lambda q,x: q.addLabel(x), (graphQuery.tablename + ".label", "string_list"): lambda q,x: q.addLabels(x), (graphQuery.tablename + ".weight", "int"): lambda q,x: q.addWeight(x), (graphQuery.tablename + ".weight", "double"): lambda q,x: q.addWeight(x), (graphQuery.tablename + ".weight", "int32"): lambda q,x: q.addWeight(x), (graphQuery.tablename + ".weight", "int64"): lambda q,x: q.addWeight(x), } for constraint in proto.constraints: func = processes.get((constraint.target_field_name, constraint.query_field_type), None) if func == None: self.log.error("Graph Query cannot be made") r.success = False return r else: func(graphQuery, decodeConstraintValue(constraint.query_field_value)) graphQuery.setGraph(self.graphs[graphQuery.tablename]) if graphQuery.sanity(): r.success = True r.memento = graphQuery.toJSON().encode('utf8') self.info("Yeah, that'll be ok.") else: self.info("No, the resultant query was not sane.") r.success = False return r
def prepareConstraint( self, proto: dap_interface_pb2.ConstructQueryConstraintObjectRequest ) -> dap_interface_pb2.ConstructQueryMementoResponse: query_settings = {} query_settings['target_table_name'] = proto.target_table_name query_settings['target_field_name'] = proto.target_field_name query_settings['target_field_type'] = proto.target_field_type query_settings['operator'] = proto.operator query_settings['query_field_type'] = proto.query_field_type query_settings[ 'query_field_value'] = DapInterface.decodeConstraintValue( proto.query_field_value) r = dap_interface_pb2.ConstructQueryMementoResponse() r.memento = json.dumps(query_settings).encode('utf8') r.success = True return r
def prepareConstraint( self, proto: dap_interface_pb2.ConstructQueryConstraintObjectRequest ) -> dap_interface_pb2.ConstructQueryMementoResponse: query_settings = {} target_field_name = proto.target_field_name if target_field_name[0:5] != 'them.': target_field_name = 'them.' + target_field_name query_settings['target_field_name'] = target_field_name query_settings['target_field_type'] = proto.target_field_type query_settings['operator'] = proto.operator query_settings['query_field_type'] = proto.query_field_type query_settings[ 'query_field_value'] = DapInterface.decodeConstraintValue( proto.query_field_value) r = dap_interface_pb2.ConstructQueryMementoResponse() r.memento = json.dumps(query_settings).encode('utf8') r.success = True self.stats["prepare_constraint_count"] += 1 return r
def prepare( self, proto: dap_interface_pb2.ConstructQueryObjectRequest ) -> dap_interface_pb2.ConstructQueryMementoResponse: reply = dap_interface_pb2.ConstructQueryMementoResponse() reply.success = False return reply