Skip to content

Commit

Permalink
fix: Add changes to Feature View Pydantic model to support timestamps (
Browse files Browse the repository at this point in the history
…#86)

* Add changes to Pydantic model to support timestamps

* Fix lint error

* Fix lint errors
  • Loading branch information
msistla96 authored Feb 28, 2024
1 parent 5e7271d commit a848003
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,8 @@ class FeatureViewModel(BaseFeatureViewModel):
tags: Optional[Dict[str, str]]
owner: str
materialization_intervals: List[Tuple[datetime, datetime]] = []
created_timestamp: Optional[datetime]
last_updated_timestamp: Optional[datetime]

def to_feature_view(self) -> FeatureView:
"""
Expand Down Expand Up @@ -107,6 +109,8 @@ def to_feature_view(self) -> FeatureView:
owner=self.owner,
)
feature_view.materialization_intervals = self.materialization_intervals
feature_view.created_timestamp = self.created_timestamp
feature_view.last_updated_timestamp = self.last_updated_timestamp

return feature_view

Expand Down Expand Up @@ -160,6 +164,8 @@ def from_feature_view(
tags=feature_view.tags if feature_view.tags else None,
owner=feature_view.owner,
materialization_intervals=feature_view.materialization_intervals,
created_timestamp=feature_view.created_timestamp,
last_updated_timestamp=feature_view.last_updated_timestamp,
)


Expand Down Expand Up @@ -214,6 +220,8 @@ class OnDemandFeatureViewModel(BaseFeatureViewModel):
description: str
tags: Dict[str, str]
owner: str
created_timestamp: Optional[datetime] = None
last_updated_timestamp: Optional[datetime] = None

def to_feature_view(self) -> OnDemandFeatureView:
source_request_sources = dict()
Expand All @@ -231,7 +239,7 @@ def to_feature_view(self) -> OnDemandFeatureView:
key
] = feature_view_projection.to_feature_view_projection()

return OnDemandFeatureView(
odfv = OnDemandFeatureView(
name=self.name,
schema=[sch.to_field() for sch in self.features],
sources=list(source_feature_view_projections.values())
Expand All @@ -242,6 +250,9 @@ def to_feature_view(self) -> OnDemandFeatureView:
tags=self.tags,
owner=self.owner,
)
odfv.created_timestamp = self.created_timestamp
odfv.last_updated_timestamp = self.last_updated_timestamp
return odfv

@classmethod
def from_feature_view(
Expand Down Expand Up @@ -283,4 +294,6 @@ def from_feature_view(
description=on_demand_feature_view.description,
tags=on_demand_feature_view.tags,
owner=on_demand_feature_view.owner,
created_timestamp=on_demand_feature_view.created_timestamp,
last_updated_timestamp=on_demand_feature_view.last_updated_timestamp,
)
25 changes: 25 additions & 0 deletions sdk/python/tests/unit/test_pydantic_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -314,6 +314,15 @@ def test_idempotent_featureview_conversion():
feature_view_model = FeatureViewModel.from_feature_view(feature_view)
feature_view_b = feature_view_model.to_feature_view()
assert feature_view == feature_view_b
assert feature_view_model.created_timestamp == feature_view.created_timestamp
assert (
feature_view_model.last_updated_timestamp == feature_view.last_updated_timestamp
)
assert feature_view_b.created_timestamp == feature_view_model.created_timestamp
assert (
feature_view_b.last_updated_timestamp
== feature_view_model.last_updated_timestamp
)

spark_source = SparkSource(
name="sparky_sparky_boom_man",
Expand Down Expand Up @@ -386,6 +395,15 @@ def test_idempotent_featureview_with_streaming_source_conversion():
feature_view_model = FeatureViewModel.from_feature_view(feature_view)
feature_view_b = feature_view_model.to_feature_view()
assert feature_view == feature_view_b
assert feature_view_model.created_timestamp == feature_view.created_timestamp
assert (
feature_view_model.last_updated_timestamp == feature_view.last_updated_timestamp
)
assert feature_view_b.created_timestamp == feature_view_model.created_timestamp
assert (
feature_view_b.last_updated_timestamp
== feature_view_model.last_updated_timestamp
)

spark_source = SparkSource(
name="sparky_sparky_boom_man",
Expand Down Expand Up @@ -595,6 +613,13 @@ def calculate_distance_demo_go(features_df: pd.DataFrame) -> pd.DataFrame:
pydantic_obj = OnDemandFeatureViewModel.from_feature_view(python_obj)
converted_python_obj = pydantic_obj.to_feature_view()
assert python_obj == converted_python_obj
assert pydantic_obj.created_timestamp == python_obj.created_timestamp
assert pydantic_obj.last_updated_timestamp == python_obj.last_updated_timestamp
assert converted_python_obj.created_timestamp == pydantic_obj.created_timestamp
assert (
converted_python_obj.last_updated_timestamp
== pydantic_obj.last_updated_timestamp
)

feast_proto = converted_python_obj.to_proto()
python_obj_from_proto = OnDemandFeatureView.from_proto(feast_proto)
Expand Down

0 comments on commit a848003

Please sign in to comment.