Esempio n. 1
0
File: client.py Progetto: beoy/feast
    def list_entities(
        self, project: str = None, labels: Dict[str, str] = dict()
    ) -> List[Entity]:
        """
        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 = Entity.from_proto(entity_proto)
            entity._client = self
            entities.append(entity)
        return entities
Esempio n. 2
0
File: client.py Progetto: beoy/feast
    def get_entity(self, name: str, project: str = None) -> Entity:
        """
        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 = Entity.from_proto(get_entity_response.entity)

        return entity
Esempio n. 3
0
    def from_proto(cls, feature_set_proto: FeatureSetSpecProto):
        """
        Creates a feature set from a protobuf representation of a feature set

        Args:
            from_proto: A protobuf representation of a feature set

        Returns:
            Returns a FeatureSet object based on the feature set protobuf
        """

        feature_set = cls(
            name=feature_set_proto.name,
            features=[
                Feature.from_proto(feature) for feature in feature_set_proto.features
            ],
            entities=[
                Entity.from_proto(entity) for entity in feature_set_proto.entities
            ],
            max_age=feature_set_proto.max_age,
            source=(
                None
                if feature_set_proto.source.type == 0
                else Source.from_proto(feature_set_proto.source)
            ),
        )
        feature_set._version = feature_set_proto.version
        feature_set._is_dirty = False
        return feature_set
Esempio n. 4
0
File: client.py Progetto: beoy/feast
    def _apply_entity(self, project: str, entity: Entity):
        """
        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 = Entity.from_proto(apply_entity_response.entity)

        # Deep copy from the returned entity to the local entity
        entity._update_from_entity(applied_entity)
Esempio n. 5
0
    def from_proto(cls, feature_set_proto: FeatureSetProto):
        """
        Creates a feature set from a protobuf representation of a feature set

        Args:
            feature_set_proto: A protobuf representation of a feature set

        Returns:
            Returns a FeatureSet object based on the feature set protobuf
        """

        feature_set = cls(
            name=feature_set_proto.spec.name,
            features=[
                Feature.from_proto(feature)
                for feature in feature_set_proto.spec.features
            ],
            entities=[
                Entity.from_proto(entity)
                for entity in feature_set_proto.spec.entities
            ],
            max_age=feature_set_proto.spec.max_age,
            source=(None if feature_set_proto.spec.source.type == 0 else
                    Source.from_proto(feature_set_proto.spec.source)),
            project=feature_set_proto.spec.project
            if len(feature_set_proto.spec.project) == 0 else
            feature_set_proto.spec.project,
        )
        feature_set._version = feature_set_proto.spec.version
        feature_set._status = feature_set_proto.meta.status
        feature_set._created_timestamp = feature_set_proto.meta.created_timestamp
        return feature_set
Esempio n. 6
0
    def list_entities(self, project: str) -> List[Entity]:
        """
        Retrieve a list of entities from the registry

        Args:
            project: Filter entities based on project name

        Returns:
            List of entities
        """
        registry_proto = self._registry_store.get_registry()
        entities = []
        for entity_proto in registry_proto.entities:
            if entity_proto.spec.project == project:
                entities.append(Entity.from_proto(entity_proto))
        return entities
Esempio n. 7
0
    def get_entity(self, name: str, project: str) -> Entity:
        """
        Retrieves an entity.

        Args:
            name: Name of entity
            project: Feast project that this entity belongs to

        Returns:
            Returns either the specified entity, or raises an exception if
            none is found
        """
        registry_proto = self._registry_store.get_registry()
        for entity_proto in registry_proto.entities:
            if entity_proto.spec.name == name and entity_proto.spec.project == project:
                return Entity.from_proto(entity_proto)
        raise Exception(f"Entity {name} does not exist in project {project}")
Esempio n. 8
0
    def get_entity(self, name: str, project: str, allow_cache: bool = False) -> Entity:
        """
        Retrieves an entity.

        Args:
            name: Name of entity
            project: Feast project that this entity belongs to

        Returns:
            Returns either the specified entity, or raises an exception if
            none is found
        """
        registry_proto = self._get_registry_proto(allow_cache=allow_cache)
        for entity_proto in registry_proto.entities:
            if entity_proto.spec.name == name and entity_proto.spec.project == project:
                return Entity.from_proto(entity_proto)
        raise EntityNotFoundException(name, project=project)
Esempio n. 9
0
    def list_entities(self, project: str, allow_cache: bool = False) -> List[Entity]:
        """
        Retrieve a list of entities from the registry

        Args:
            allow_cache: Whether to allow returning entities from a cached registry
            project: Filter entities based on project name

        Returns:
            List of entities
        """
        registry_proto = self._get_registry_proto(allow_cache=allow_cache)
        entities = []
        for entity_proto in registry_proto.entities:
            if entity_proto.spec.project == project:
                entities.append(Entity.from_proto(entity_proto))
        return entities
Esempio n. 10
0
 def from_proto(cls, feature_set_proto: FeatureSetSpecProto):
     feature_set = cls(
         name=feature_set_proto.name,
         features=[
             Feature.from_proto(feature) for feature in feature_set_proto.features
         ],
         entities=[
             Entity.from_proto(entity) for entity in feature_set_proto.entities
         ],
         max_age=feature_set_proto.max_age,
         source=(
             None
             if feature_set_proto.source.type == 0
             else Source.from_proto(feature_set_proto.source)
         ),
     )
     feature_set._version = feature_set_proto.version
     feature_set._is_dirty = False
     return feature_set
Esempio n. 11
0
    def get_entity(self, name: str, project: str = None) -> Entity:
        """
        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 self._telemetry_enabled:
            log_usage(
                "get_entity",
                self._telemetry_id,
                datetime.utcnow(),
                self.version(sdk_only=True),
            )

        if project is None:
            project = self.project

        if self._use_object_store_registry:
            return self._registry.get_entity(name, project)
        else:
            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 = Entity.from_proto(get_entity_response.entity)

            return entity