Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Temp
Signed-off-by: Felix Wang <wangfelix98@gmail.com>
  • Loading branch information
felixwang9817 committed Aug 17, 2022
commit 40d7965a752fd673c194156945c004af6b1961c2
7 changes: 7 additions & 0 deletions sdk/python/feast/errors.py
Original file line number Diff line number Diff line change
Expand Up @@ -310,6 +310,13 @@ def __init__(self, expected_column_name: str):
)


class FeatureViewMissingDuringFeatureServiceInference(Exception):
def __init__(self, feature_view_name: str, feature_service_name: str):
super().__init__(
f"Missing {feature_view_name} feature view during inference for {feature_service_name} feature service."
)


class InvalidEntityType(Exception):
def __init__(self, entity_type: type):
super().__init__(
Expand Down
62 changes: 35 additions & 27 deletions sdk/python/feast/feature_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
from typeguard import typechecked

from feast.base_feature_view import BaseFeatureView
from feast.errors import FeatureViewMissingDuringFeatureServiceInference
from feast.feature_logging import LoggingConfig
from feast.feature_view import FeatureView
from feast.feature_view_projection import FeatureViewProjection
Expand Down Expand Up @@ -85,28 +86,30 @@ def __init__(
if isinstance(feature_grouping, BaseFeatureView):
self.feature_view_projections.append(feature_grouping.projection)

def infer_features(self, fvs_to_update: Optional[Dict[str, FeatureView]] = None):
def infer_features(self, fvs_to_update: Dict[str, FeatureView]):
"""
Infers the features for the projections of this feature service, and updates this feature
service in place.

This method is necessary since feature services may rely on feature views which require
feature inference.

Args:
fvs_to_update: A mapping of feature view names to corresponding feature views that
contains all the feature views necessary to run inference.
"""
for feature_grouping in self._features:
if isinstance(feature_grouping, BaseFeatureView):
projection = feature_grouping.projection

if fvs_to_update and feature_grouping.name in fvs_to_update:
# There are three situations to be handled. First, the projection specifies
# desired features, in which case we should select those desired features.
# Second, the projection does not specify any desired features but has
# already selected features, in which case nothing needs to be done. And
# third, the projection does not specify any desired features but has not
# yet selected features (since the original feature view did not yet have
# features), in which case we should select all possible inferred features.
if projection.desired_features:
# First case, so we select the specific desired features.


if projection.desired_features:
# The projection wants to select a specific set of inferred features.
# Example: FeatureService(features=[fv[["inferred_feature"]]]), where
# 'fv' is a feature view that was defined without a schema.
if feature_grouping.name in fvs_to_update:
# Validate that the selected features have actually been inferred.
desired_features = set(projection.desired_features)
actual_features = set(
[
Expand All @@ -116,27 +119,32 @@ def infer_features(self, fvs_to_update: Optional[Dict[str, FeatureView]] = None)
)
assert desired_features.issubset(actual_features)

# We need to set the features for the projection at this point so we ensure we're starting with
# an empty list.
# Extract the selected features and add them to the projection.
projection.features = []
for f in fvs_to_update[feature_grouping.name].features:
if f.name in desired_features:
projection.features.append(f)
elif not projection.desired_features and projection.features:
# Second cass, so nothing needs to be done. In case something went wrong
# during feature inference, we check that the selected features still exist.
actual_features = set(
[
f.name
for f in fvs_to_update[feature_grouping.name].features
]
)
assert projection.features.issubset(actual_features)
else:
# Third case, so all inferred features will be selected.
projection.features = fvs_to_update[
feature_grouping.name
].features
raise FeatureViewMissingDuringFeatureServiceInference(
Comment thread
adchia marked this conversation as resolved.
feature_view_name=feature_grouping.name,
feature_service_name=self.name,
)

continue

if projection.features:
# The projection has already selected features from a feature view with a
# known schema, so no action needs to be taken.
# Example: FeatureService(features=[fv[["existing_feature"]]]), where
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This also applies if the user is selecting from a fv with a known schema, but doesn't select features right?

# 'existing_feature' was defined as part of the schema of 'fv'.
continue

# The projection wants to select all possible inferred features.
# Example: FeatureService(features=[fv]), where 'fv' is a feature view that
# was defined without a schema.
projection.features = fvs_to_update[
feature_grouping.name
].features
else:
raise ValueError(
f"The feature service {self.name} has been provided with an invalid type "
Expand Down