Skip to content

Commit

Permalink
chore: Remove unnecessary methods from FeatureView (#2443)
Browse files Browse the repository at this point in the history
* Remove unnecessary methods from FeatureView

Signed-off-by: Felix Wang <[email protected]>

* Fix comment

Signed-off-by: Felix Wang <[email protected]>
  • Loading branch information
felixwang9817 authored Mar 24, 2022
1 parent 7d1efd5 commit bce718e
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 80 deletions.
40 changes: 15 additions & 25 deletions sdk/python/feast/base_feature_view.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@ class BaseFeatureView(ABC):
tags: A dictionary of key-value pairs to store arbitrary metadata.
owner: The owner of the base feature view, typically the email of the primary
maintainer.
projection: The feature view projection to be applied to this base feature view
at retrieval time.
projection: The feature view projection storing modifications to be applied to
this base feature view at retrieval time.
created_timestamp (optional): The time when the base feature view was created.
last_updated_timestamp (optional): The time when the base feature view was last
updated.
Expand Down Expand Up @@ -152,15 +152,11 @@ def ensure_valid(self):

def with_name(self, name: str):
"""
Renames this feature view by returning a copy of this feature view with an alias
set for the feature view name. This rename operation is only used as part of query
operations and will not modify the underlying FeatureView.
Returns a renamed copy of this base feature view. This renamed copy should only be
used for query operations and will not modify the underlying base feature view.
Args:
name: Name to assign to the FeatureView copy.
Returns:
A copy of this FeatureView with the name replaced with the 'name' input.
name: The name to assign to the copy.
"""
cp = self.__copy__()
cp.projection.name_alias = name
Expand All @@ -169,15 +165,13 @@ def with_name(self, name: str):

def set_projection(self, feature_view_projection: FeatureViewProjection) -> None:
"""
Setter for the projection object held by this FeatureView. A projection is an
object that stores the modifications to a FeatureView that is applied to the FeatureView
when the FeatureView is used such as during feature_store.get_historical_features.
This method also performs checks to ensure the projection is consistent with this
FeatureView before doing the set.
Sets the feature view projection of this base feature view to the given projection.
Args:
feature_view_projection: The FeatureViewProjection object to set this FeatureView's
'projection' field to.
feature_view_projection: The feature view projection to be set.
Raises:
ValueError: The name or features of the projection do not match.
"""
if feature_view_projection.name != self.name:
raise ValueError(
Expand All @@ -197,18 +191,14 @@ def set_projection(self, feature_view_projection: FeatureViewProjection) -> None

def with_projection(self, feature_view_projection: FeatureViewProjection):
"""
Sets the feature view projection by returning a copy of this on-demand feature view
with its projection set to the given projection. A projection is an
object that stores the modifications to a feature view that is used during
query operations.
Returns a copy of this base feature view with the feature view projection set to
the given projection.
Args:
feature_view_projection: The FeatureViewProjection object to link to this
OnDemandFeatureView.
feature_view_projection: The feature view projection to assign to the copy.
Returns:
A copy of this OnDemandFeatureView with its projection replaced with the
'feature_view_projection' argument.
Raises:
ValueError: The name or features of the projection do not match.
"""
if feature_view_projection.name != self.name:
raise ValueError(
Expand Down
56 changes: 1 addition & 55 deletions sdk/python/feast/feature_view.py
Original file line number Diff line number Diff line change
Expand Up @@ -213,36 +213,16 @@ def ensure_valid(self):
def proto_class(self) -> Type[FeatureViewProto]:
return FeatureViewProto

def with_name(self, name: str):
"""
Renames this feature view by returning a copy of this feature view with an alias
set for the feature view name. This rename operation is only used as part of query
operations and will not modify the underlying FeatureView.
Args:
name: Name to assign to the FeatureView copy.
Returns:
A copy of this FeatureView with the name replaced with the 'name' input.
"""
cp = self.__copy__()
cp.projection.name_alias = name

return cp

def with_join_key_map(self, join_key_map: Dict[str, str]):
"""
Sets the join_key_map by returning a copy of this feature view with that field set.
Returns a copy of this feature view with the join key map set to the given map.
This join_key mapping operation is only used as part of query operations and will
not modify the underlying FeatureView.
Args:
join_key_map: A map of join keys in which the left is the join_key that
corresponds with the feature data and the right corresponds with the entity data.
Returns:
A copy of this FeatureView with the join_key_map replaced with the 'join_key_map' input.
Examples:
Join a location feature data table to both the origin column and destination
column of the entity data.
Expand All @@ -268,40 +248,6 @@ def with_join_key_map(self, join_key_map: Dict[str, str]):

return cp

def with_projection(self, feature_view_projection: FeatureViewProjection):
"""
Sets the feature view projection by returning a copy of this feature view
with its projection set to the given projection. A projection is an
object that stores the modifications to a feature view that is used during
query operations.
Args:
feature_view_projection: The FeatureViewProjection object to link to this
OnDemandFeatureView.
Returns:
A copy of this FeatureView with its projection replaced with the 'feature_view_projection'
argument.
"""
if feature_view_projection.name != self.name:
raise ValueError(
f"The projection for the {self.name} FeatureView cannot be applied because it differs in name. "
f"The projection is named {feature_view_projection.name} and the name indicates which "
"FeatureView the projection is for."
)

for feature in feature_view_projection.features:
if feature not in self.features:
raise ValueError(
f"The projection for {self.name} cannot be applied because it contains {feature.name} which the "
"FeatureView doesn't have."
)

cp = self.__copy__()
cp.projection = feature_view_projection

return cp

def to_proto(self) -> FeatureViewProto:
"""
Converts a feature view object to its protobuf representation.
Expand Down

0 comments on commit bce718e

Please sign in to comment.