diff --git a/sdk/python/feast/feature_table.py b/sdk/python/feast/feature_table.py index 9962b9fbc5..5d32dcc114 100644 --- a/sdk/python/feast/feature_table.py +++ b/sdk/python/feast/feature_table.py @@ -206,6 +206,12 @@ def last_updated_timestamp(self): """ return self._last_updated_timestamp + def add_feature(self, feature: Feature): + """ + Adds a new feature to the feature table. + """ + self.features.append(feature) + def is_valid(self): """ Validates the state of a feature table locally. Raises an exception diff --git a/sdk/python/tests/test_feature_table.py b/sdk/python/tests/test_feature_table.py index 858704bd7c..2994569a61 100644 --- a/sdk/python/tests/test_feature_table.py +++ b/sdk/python/tests/test_feature_table.py @@ -53,9 +53,9 @@ def server(self): def client(self, server): return Client(core_url=f"localhost:{free_port}") - def test_feature_table_import_export_yaml(self): - - batch_source = FileSource( + @pytest.fixture + def batch_source(self): + return FileSource( field_mapping={ "ride_distance": "ride_distance", "ride_duration": "ride_duration", @@ -67,6 +67,8 @@ def test_feature_table_import_export_yaml(self): date_partition_column="date_partition_col", ) + def test_feature_table_import_export_yaml(self, batch_source): + stream_source = KafkaSource( field_mapping={ "ride_distance": "ride_distance", @@ -99,3 +101,28 @@ def test_feature_table_import_export_yaml(self): # Ensure equality is upheld to original feature table assert test_feature_table == actual_feature_table_from_string + + def test_add_feature(self, batch_source): + + test_feature_table = FeatureTable( + name="car_driver", + features=[ + Feature(name="ride_distance", dtype=ValueType.FLOAT), + Feature(name="ride_duration", dtype=ValueType.STRING), + ], + entities=["car_driver_entity"], + labels={"team": "matchmaking"}, + batch_source=batch_source, + ) + + test_feature_table.add_feature( + Feature(name="new_ride_distance", dtype=ValueType.FLOAT) + ) + + features = test_feature_table.features + assert ( + len(features) == 3 + and features[0].name == "ride_distance" + and features[1].name == "ride_duration" + and features[2].name == "new_ride_distance" + )