def list_entities(self, project: str = None, labels: Dict[str, str] = dict()) -> List[EntityV2]: """ Retrieve a list of entities from Feast Core Args: project: Filter entities based on project name labels: User-defined labels that these entities are associated with Returns: List of entities """ if project is None: project = self.project filter = ListEntitiesRequest.Filter(project=project, labels=labels) # Get latest entities from Feast Core entity_protos = self._core_service.ListEntities( ListEntitiesRequest(filter=filter), metadata=self._get_grpc_metadata(), ) # type: ListEntitiesResponse # Extract entities and return entities = [] for entity_proto in entity_protos.entities: entity = EntityV2.from_proto(entity_proto) entity._client = self entities.append(entity) return entities
def get_entity(self, name: str, project: str = None) -> Union[EntityV2, None]: """ Retrieves an entity. Args: project: Feast project that this entity belongs to name: Name of entity Returns: Returns either the specified entity, or raises an exception if none is found """ if project is None: project = self.project try: get_entity_response = self._core_service.GetEntity( GetEntityRequest(project=project, name=name.strip()), metadata=self._get_grpc_metadata(), ) # type: GetEntityResponse except grpc.RpcError as e: raise grpc.RpcError(e.details()) entity = EntityV2.from_proto(get_entity_response.entity) return entity
def test_entity_import_export_yaml(self): test_entity = EntityV2( name="car_driver_entity", description="Driver entity for car rides", value_type=ValueType.STRING, labels={"team": "matchmaking"}, ) # Create a string YAML representation of the entity string_yaml = test_entity.to_yaml() # Create a new entity object from the YAML string actual_entity_from_string = EntityV2.from_yaml(string_yaml) # Ensure equality is upheld to original entity assert test_entity == actual_entity_from_string
def entity_create(filename, project): """ Create or update an entity """ entities = [ EntityV2.from_dict(entity_dict) for entity_dict in yaml_loader(filename) ] feast_client = Client() # type: Client feast_client.apply_entity(entities, project)
def test_entity_class_contains_labels(): entity = EntityV2( "my-entity", description="My entity", value_type=ValueType.STRING, labels={ "key1": "val1", "key2": "val2" }, ) assert "key1" in entity.labels.keys() and entity.labels["key1"] == "val1" assert "key2" in entity.labels.keys() and entity.labels["key2"] == "val2"
def _apply_entity(self, project: str, entity: EntityV2): """ Registers a single entity with Feast Args: entity: Entity that will be registered """ entity.is_valid() entity_proto = entity.to_spec_proto() # Convert the entity to a request and send to Feast Core try: apply_entity_response = self._core_service.ApplyEntity( ApplyEntityRequest(project=project, spec=entity_proto), # type: ignore timeout=self._config.getint( CONFIG_GRPC_CONNECTION_TIMEOUT_DEFAULT_KEY), metadata=self._get_grpc_metadata(), ) # type: ApplyEntityResponse except grpc.RpcError as e: raise grpc.RpcError(e.details()) # Extract the returned entity applied_entity = EntityV2.from_proto(apply_entity_response.entity) # Deep copy from the returned entity to the local entity entity._update_from_entity(applied_entity)
def test_entity_without_labels_empty_dict(): entity = EntityV2("my-entity", description="My entity", value_type=ValueType.STRING) assert entity.labels == dict() assert len(entity.labels) == 0