From 9646f031f0f853c4f6793c55d553035cf6b0c45c Mon Sep 17 00:00:00 2001 From: Francisco Arceo Date: Fri, 4 Oct 2024 22:23:34 -0400 Subject: [PATCH] chore: Adding additional dummy entity field test (#4602) Signed-off-by: Francisco Javier Arceo --- sdk/python/feast/feature_view.py | 4 ++ .../test_on_demand_python_transformation.py | 40 +++++++++++++++++-- 2 files changed, 40 insertions(+), 4 deletions(-) diff --git a/sdk/python/feast/feature_view.py b/sdk/python/feast/feature_view.py index 33ea761158..4aeb9a9c1d 100644 --- a/sdk/python/feast/feature_view.py +++ b/sdk/python/feast/feature_view.py @@ -49,6 +49,10 @@ name=DUMMY_ENTITY_NAME, join_keys=[DUMMY_ENTITY_ID], ) +DUMMY_ENTITY_FIELD = Field( + name=DUMMY_ENTITY_ID, + dtype=from_value_type(ValueType.STRING), +) @typechecked diff --git a/sdk/python/tests/unit/test_on_demand_python_transformation.py b/sdk/python/tests/unit/test_on_demand_python_transformation.py index ff7ad494ca..b994ea8042 100644 --- a/sdk/python/tests/unit/test_on_demand_python_transformation.py +++ b/sdk/python/tests/unit/test_on_demand_python_transformation.py @@ -17,10 +17,20 @@ RequestSource, ) from feast.driver_test_data import create_driver_hourly_stats_df +from feast.feature_view import DUMMY_ENTITY_FIELD from feast.field import Field from feast.infra.online_stores.sqlite import SqliteOnlineStoreConfig from feast.on_demand_feature_view import on_demand_feature_view -from feast.types import Array, Bool, Float32, Float64, Int64, String +from feast.types import ( + Array, + Bool, + Float32, + Float64, + Int64, + String, + ValueType, + from_value_type, +) class TestOnDemandPythonTransformation(unittest.TestCase): @@ -51,7 +61,9 @@ def setUp(self): path=driver_stats_path, allow_truncated_timestamps=True ) - driver = Entity(name="driver", join_keys=["driver_id"]) + driver = Entity( + name="driver", join_keys=["driver_id"], value_type=ValueType.INT64 + ) driver_stats_source = FileSource( name="driver_hourly_stats_source", @@ -73,6 +85,19 @@ def setUp(self): source=driver_stats_source, ) + driver_stats_entity_less_fv = FeatureView( + name="driver_hourly_stats_no_entity", + entities=[], + ttl=timedelta(days=0), + schema=[ + Field(name="conv_rate", dtype=Float32), + Field(name="acc_rate", dtype=Float32), + Field(name="avg_daily_trips", dtype=Int64), + ], + online=True, + source=driver_stats_source, + ) + @on_demand_feature_view( sources=[driver_stats_fv], schema=[Field(name="conv_rate_plus_acc_pandas", dtype=Float64)], @@ -151,6 +176,7 @@ def python_singleton_view(inputs: dict[str, Any]) -> dict[str, Any]: pandas_view, python_view, python_singleton_view, + driver_stats_entity_less_fv, ] ) @@ -162,13 +188,19 @@ def python_singleton_view(inputs: dict[str, Any]) -> dict[str, Any]: pandas_view, python_view, python_demo_view, + driver_stats_entity_less_fv, ] ) self.store.write_to_online_store( feature_view_name="driver_hourly_stats", df=driver_df ) - assert len(self.store.list_all_feature_views()) == 4 - assert len(self.store.list_feature_views()) == 1 + assert driver_stats_fv.entity_columns == [ + Field(name=driver.join_key, dtype=from_value_type(driver.value_type)) + ] + assert driver_stats_entity_less_fv.entity_columns == [DUMMY_ENTITY_FIELD] + + assert len(self.store.list_all_feature_views()) == 5 + assert len(self.store.list_feature_views()) == 2 assert len(self.store.list_on_demand_feature_views()) == 3 assert len(self.store.list_stream_feature_views()) == 0