Skip to content

Commit

Permalink
Continue FeatureService and FeatureViewProjection cleanup
Browse files Browse the repository at this point in the history
Signed-off-by: Felix Wang <wangfelix98@gmail.com>
  • Loading branch information
felixwang9817 committed Feb 18, 2022
1 parent b746439 commit aeb1a46
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 15 deletions.
19 changes: 11 additions & 8 deletions sdk/python/feast/feature_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,10 @@
FeatureService as FeatureServiceProto,
)
from feast.protos.feast.core.FeatureService_pb2 import (
FeatureServiceMeta,
FeatureServiceSpec,
FeatureServiceMeta as FeatureServiceMetaProto,
)
from feast.protos.feast.core.FeatureService_pb2 import (
FeatureServiceSpec as FeatureServiceSpecProto,
)
from feast.usage import log_exceptions

Expand All @@ -28,7 +30,8 @@ class FeatureService:
projections, representing the features in the feature service.
description: A human-readable description.
tags: A dictionary of key-value pairs to store arbitrary metadata.
owner: The owner of the feature service.
owner: The owner of the feature service, typically the email of the primary
maintainer.
created_timestamp: The time when the feature service was created.
last_updated_timestamp: The time when the feature service was last updated.
"""
Expand Down Expand Up @@ -163,15 +166,15 @@ def last_updated_timestamp(self) -> Optional[datetime]:
def last_updated_timestamp(self, last_updated_timestamp: datetime):
self._last_updated_timestamp = last_updated_timestamp

@staticmethod
def from_proto(feature_service_proto: FeatureServiceProto):
@classmethod
def from_proto(cls, feature_service_proto: FeatureServiceProto):
"""
Converts a FeatureServiceProto to a FeatureService object.
Args:
feature_service_proto: A protobuf representation of a FeatureService.
"""
fs = FeatureService(
fs = cls(
name=feature_service_proto.spec.name,
features=[],
tags=dict(feature_service_proto.spec.tags),
Expand Down Expand Up @@ -203,13 +206,13 @@ def to_proto(self) -> FeatureServiceProto:
Returns:
A FeatureServiceProto protobuf.
"""
meta = FeatureServiceMeta()
meta = FeatureServiceMetaProto()
if self.created_timestamp:
meta.created_timestamp.FromDatetime(self.created_timestamp)
if self.last_updated_timestamp:
meta.last_updated_timestamp.FromDatetime(self.last_updated_timestamp)

spec = FeatureServiceSpec(
spec = FeatureServiceSpecProto(
name=self.name,
features=[
projection.to_proto() for projection in self.feature_view_projections
Expand Down
17 changes: 10 additions & 7 deletions sdk/python/feast/feature_view_projection.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from typing import Dict, List
from typing import Dict, List, Optional

from attr import dataclass

Expand All @@ -11,19 +11,20 @@
@dataclass
class FeatureViewProjection:
"""
A feature view projection represents a set of features from a single feature view.
A feature view projection represents a selection of one or more features from a
single feature view.
Attributes:
name: The unique name of the feature view projection.
name: The unique name of the feature view from which this projection is created.
name_alias: An optional alias for the name.
features: The list of features represented by the feature view projection.
join_key_map: A map to modify join key columns during retrieval of this feature
view projection.
"""

name: str
name_alias: str = ""
features: List[Feature] = []
name_alias: Optional[str]
features: List[Feature]
join_key_map: Dict[str, str] = {}

def name_to_use(self):
Expand All @@ -32,7 +33,7 @@ def name_to_use(self):
def to_proto(self) -> FeatureViewProjectionProto:
feature_reference_proto = FeatureViewProjectionProto(
feature_view_name=self.name,
feature_view_name_alias=self.name_alias,
feature_view_name_alias=self.name_alias or "",
join_key_map=self.join_key_map,
)
for feature in self.features:
Expand All @@ -56,5 +57,7 @@ def from_proto(proto: FeatureViewProjectionProto):
@staticmethod
def from_definition(feature_grouping):
return FeatureViewProjection(
name=feature_grouping.name, features=feature_grouping.features,
name=feature_grouping.name,
name_alias=None,
features=feature_grouping.features,
)

0 comments on commit aeb1a46

Please sign in to comment.