forked from feast-dev/feast
-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Added pydantic model support for Field, FVP, ODFV, Project Meta…
…data and Feature Services (#6) * feat: Added pydantic model support for Field, FeatureViewProjections, OnDemandFeatureViews, Feature Services and Project Metadata --------- Co-authored-by: Bhargav Dodla <[email protected]>
- Loading branch information
1 parent
d99c7a2
commit 1273a12
Showing
16 changed files
with
912 additions
and
158 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
81 changes: 81 additions & 0 deletions
81
sdk/python/feast/expediagroup/pydantic_models/feature_service.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
import sys | ||
from datetime import datetime | ||
from typing import Dict, List, Optional, Union | ||
|
||
from pydantic import BaseModel | ||
from typing_extensions import Self | ||
|
||
from feast.expediagroup.pydantic_models.feature_view_model import ( | ||
FeatureViewModel, | ||
FeatureViewProjectionModel, | ||
OnDemandFeatureViewModel, | ||
) | ||
from feast.feature_service import FeatureService | ||
|
||
|
||
class FeatureServiceModel(BaseModel): | ||
""" | ||
Pydantic model for Feast FeatureService | ||
""" | ||
|
||
name: str | ||
features: List[Union[FeatureViewModel, OnDemandFeatureViewModel]] | ||
feature_view_projections: List[FeatureViewProjectionModel] | ||
description: str | ||
tags: Dict[str, str] | ||
owner: str | ||
created_timestamp: Optional[datetime] | ||
last_updated_timestamp: Optional[datetime] | ||
# TODO: logging_config option is not supported temporarily. | ||
# we will add this fucntionality to FeatureServiceModel in future. | ||
# logging_config: Optional[LoggingConfig] = None | ||
|
||
def to_feature_service(self) -> FeatureService: | ||
fs = FeatureService( | ||
name=self.name, | ||
features=[feature.to_feature_view() for feature in self.features], | ||
description=self.description, | ||
tags=self.tags, | ||
owner=self.owner, | ||
) | ||
|
||
fs.feature_view_projections = [ | ||
feature_view_projection.to_feature_view_projection() | ||
for feature_view_projection in self.feature_view_projections | ||
] | ||
fs.created_timestamp = self.created_timestamp | ||
fs.last_updated_timestamp = self.last_updated_timestamp | ||
|
||
return fs | ||
|
||
@classmethod | ||
def from_feature_service( | ||
cls, | ||
feature_service: FeatureService, | ||
) -> Self: # type: ignore | ||
|
||
features = [] | ||
for feature in feature_service._features: | ||
class_ = getattr( | ||
sys.modules[__name__], | ||
type(feature).__name__ + "Model", | ||
) | ||
features.append(class_.from_feature_view(feature)) | ||
|
||
feature_view_projections = [ | ||
FeatureViewProjectionModel.from_feature_view_projection( | ||
feature_view_projection | ||
) | ||
for feature_view_projection in feature_service.feature_view_projections | ||
] | ||
|
||
return cls( | ||
name=feature_service.name, | ||
features=features, | ||
feature_view_projections=feature_view_projections, | ||
description=feature_service.description, | ||
tags=feature_service.tags, | ||
owner=feature_service.owner, | ||
created_timestamp=feature_service.created_timestamp, | ||
last_updated_timestamp=feature_service.last_updated_timestamp, | ||
) |
Oops, something went wrong.