Skip to content

Commit 1475373

Browse files
authored
chore: Feature view as property instead to remove duplicate source of truth (feast-dev#3403)
* Feature view as property instead or duplicate source or truth Signed-off-by: gbmarc1 <[email protected]> * fix: test with new schema as property Signed-off-by: gbmarc1 <[email protected]> * lint: fix lint error Signed-off-by: gbmarc1 <[email protected]> Signed-off-by: gbmarc1 <[email protected]>
1 parent 5a83c6e commit 1475373

File tree

2 files changed

+16
-13
lines changed

2 files changed

+16
-13
lines changed

sdk/python/feast/feature_view.py

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,6 @@ class FeatureView(BaseFeatureView):
8585
ttl: Optional[timedelta]
8686
batch_source: DataSource
8787
stream_source: Optional[DataSource]
88-
schema: List[Field]
8988
entity_columns: List[Field]
9089
features: List[Field]
9190
online: bool
@@ -135,7 +134,7 @@ def __init__(
135134
self.name = name
136135
self.entities = [e.name for e in entities] if entities else [DUMMY_ENTITY_NAME]
137136
self.ttl = ttl
138-
self.schema = schema or []
137+
schema = schema or []
139138

140139
# Initialize data sources.
141140
if (
@@ -169,7 +168,7 @@ def __init__(
169168
"A feature view should not have entities that share a join key."
170169
)
171170

172-
for field in self.schema:
171+
for field in schema:
173172
if field.name in join_keys:
174173
self.entity_columns.append(field)
175174

@@ -190,7 +189,7 @@ def __init__(
190189
features.append(field)
191190

192191
# TODO(felixwang9817): Add more robust validation of features.
193-
cols = [field.name for field in self.schema]
192+
cols = [field.name for field in schema]
194193
for col in cols:
195194
if (
196195
self.batch_source.field_mapping is not None
@@ -258,6 +257,10 @@ def join_keys(self) -> List[str]:
258257
"""Returns a list of all the join keys."""
259258
return [entity.name for entity in self.entity_columns]
260259

260+
@property
261+
def schema(self) -> List[Field]:
262+
return self.entity_columns + self.features
263+
261264
def ensure_valid(self):
262265
"""
263266
Validates the state of this feature view locally.

sdk/python/tests/unit/infra/test_inference_unit_tests.py

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -244,8 +244,8 @@ def test_feature_view_inference_on_entity_value_types():
244244
),
245245
)
246246

247-
# The schema is only used as a parameter, as is therefore not updated during inference.
248-
assert len(feature_view_1.schema) == 1
247+
# The schema must be entity and features
248+
assert len(feature_view_1.schema) == 2
249249

250250
# Since there is already a feature specified, additional features are not inferred.
251251
assert len(feature_view_1.features) == 1
@@ -314,15 +314,15 @@ def test_feature_view_inference_on_entity_columns(simple_dataset_1):
314314
),
315315
)
316316

317-
# The schema is only used as a parameter, as is therefore not updated during inference.
318-
assert len(feature_view_1.schema) == 1
319-
320317
# Since there is already a feature specified, additional features are not inferred.
321318
assert len(feature_view_1.features) == 1
322319

323320
# The single entity column is inferred correctly.
324321
assert len(feature_view_1.entity_columns) == 1
325322

323+
# The schema is a property concatenating features and entity_columns
324+
assert len(feature_view_1.schema) == 2
325+
326326

327327
def test_feature_view_inference_on_feature_columns(simple_dataset_1):
328328
"""
@@ -349,8 +349,8 @@ def test_feature_view_inference_on_feature_columns(simple_dataset_1):
349349
),
350350
)
351351

352-
# The schema is only used as a parameter, as is therefore not updated during inference.
353-
assert len(feature_view_1.schema) == 1
352+
# The schema is a property concatenating features and entity_columns
353+
assert len(feature_view_1.schema) == 4
354354

355355
# All three feature columns are inferred correctly.
356356
assert len(feature_view_1.features) == 3
@@ -407,9 +407,9 @@ def test_update_feature_services_with_inferred_features(simple_dataset_1):
407407
}
408408
)
409409

410-
assert len(feature_view_1.schema) == 0
410+
assert len(feature_view_1.schema) == 4
411411
assert len(feature_view_1.features) == 3
412-
assert len(feature_view_2.schema) == 0
412+
assert len(feature_view_2.schema) == 4
413413
assert len(feature_view_2.features) == 3
414414
assert len(feature_service.feature_view_projections[0].features) == 1
415415
assert len(feature_service.feature_view_projections[1].features) == 3

0 commit comments

Comments
 (0)