Exemplo n.º 1
0
    def delete_feature_view(self,
                            name: str,
                            project: str,
                            commit: bool = True):
        """
        Deletes a feature view or raises an exception if not found.

        Args:
            name: Name of feature view
            project: Feast project that this feature view belongs to
            commit: Whether the change should be persisted immediately
        """
        self._prepare_registry_for_changes()
        assert self.cached_registry_proto

        for idx, existing_feature_view_proto in enumerate(
                self.cached_registry_proto.feature_views):
            if (existing_feature_view_proto.spec.name == name
                    and existing_feature_view_proto.spec.project == project):
                del self.cached_registry_proto.feature_views[idx]
                if commit:
                    self.commit()
                return

        raise FeatureViewNotFoundException(name, project)
Exemplo n.º 2
0
def _group_feature_refs(
    features: Union[List[str],
                    FeatureService], all_feature_views: List[FeatureView]
) -> List[Tuple[FeatureView, List[str]]]:
    """ Get list of feature views and corresponding feature names based on feature references"""

    # view name to view proto
    view_index = {view.name: view for view in all_feature_views}

    # view name to feature names
    views_features = defaultdict(list)

    if isinstance(features, list) and isinstance(features[0], str):
        for ref in features:
            view_name, feat_name = ref.split(":")
            if view_name not in view_index:
                raise FeatureViewNotFoundException(view_name)
            views_features[view_name].append(feat_name)
    elif isinstance(features, FeatureService):
        for feature_projection in features.features:
            projected_features = feature_projection.features
            views_features[feature_projection.name].extend(
                [f.name for f in projected_features])

    result = []
    for view_name, feature_names in views_features.items():
        result.append((view_index[view_name], feature_names))
    return result
Exemplo n.º 3
0
 def updater(registry_proto: RegistryProto):
     for idx, existing_feature_view_proto in enumerate(
             registry_proto.feature_views):
         if (existing_feature_view_proto.spec.name == name and
                 existing_feature_view_proto.spec.project == project):
             del registry_proto.feature_views[idx]
             return registry_proto
     raise FeatureViewNotFoundException(name, project)
Exemplo n.º 4
0
    def get_feature_view(self, name: str, project: str) -> FeatureView:
        """
        Retrieves a feature view.

        Args:
            name: Name of feature view
            project: Feast project that this feature view belongs to

        Returns:
            Returns either the specified feature view, or raises an exception if
            none is found
        """
        registry_proto = self._get_registry_proto()
        for feature_view_proto in registry_proto.feature_views:
            if (feature_view_proto.spec.name == name
                    and feature_view_proto.spec.project == project):
                return FeatureView.from_proto(feature_view_proto)
        raise FeatureViewNotFoundException(name, project)
Exemplo n.º 5
0
 def updater(registry_proto: RegistryProto):
     for idx, existing_feature_view_proto in enumerate(
         registry_proto.feature_views
     ):
         if (
             existing_feature_view_proto.spec.name == feature_view.name
             and existing_feature_view_proto.spec.project == project
         ):
             existing_feature_view = FeatureView.from_proto(
                 existing_feature_view_proto
             )
             existing_feature_view.materialization_intervals.append(
                 (start_date, end_date)
             )
             feature_view_proto = existing_feature_view.to_proto()
             feature_view_proto.spec.project = project
             del registry_proto.feature_views[idx]
             registry_proto.feature_views.append(feature_view_proto)
             return registry_proto
     raise FeatureViewNotFoundException(feature_view.name, project)
Exemplo n.º 6
0
    def apply_materialization(
        self,
        feature_view: FeatureView,
        project: str,
        start_date: datetime,
        end_date: datetime,
        commit: bool = True,
    ):
        """
        Updates materialization intervals tracked for a single feature view in Feast

        Args:
            feature_view: Feature view that will be updated with an additional materialization interval tracked
            project: Feast project that this feature view belongs to
            start_date (datetime): Start date of the materialization interval to track
            end_date (datetime): End date of the materialization interval to track
            commit: Whether the change should be persisted immediately
        """
        self._prepare_registry_for_changes()
        assert self.cached_registry_proto

        for idx, existing_feature_view_proto in enumerate(
                self.cached_registry_proto.feature_views):
            if (existing_feature_view_proto.spec.name == feature_view.name
                    and existing_feature_view_proto.spec.project == project):
                existing_feature_view = FeatureView.from_proto(
                    existing_feature_view_proto)
                existing_feature_view.materialization_intervals.append(
                    (start_date, end_date))
                existing_feature_view.last_updated_timestamp = datetime.utcnow(
                )
                feature_view_proto = existing_feature_view.to_proto()
                feature_view_proto.spec.project = project
                del self.cached_registry_proto.feature_views[idx]
                self.cached_registry_proto.feature_views.append(
                    feature_view_proto)
                if commit:
                    self.commit()
                return

        raise FeatureViewNotFoundException(feature_view.name, project)
Exemplo n.º 7
0
def _group_refs(
    feature_refs: List[str], all_feature_views: List[FeatureView]
) -> List[Tuple[FeatureView, List[str]]]:
    """ Get list of feature views and corresponding feature names based on feature references"""

    # view name to view proto
    view_index = {view.name: view for view in all_feature_views}

    # view name to feature names
    views_features = defaultdict(list)

    for ref in feature_refs:
        view_name, feat_name = ref.split(":")
        if view_name not in view_index:
            raise FeatureViewNotFoundException(view_name)
        views_features[view_name].append(feat_name)

    result = []
    for view_name, feature_names in views_features.items():
        result.append((view_index[view_name], feature_names))
    return result