Skip to content

Commit 150d2fc

Browse files
Ambient Code Botjyejare
authored andcommitted
Fix ODFV output projection in offline retrieval (feast-dev#6099)
Changes: - Modified RetrievalJob.to_arrow() to filter ODFV outputs based on requested features from metadata, matching online retrieval behavior - Added test_odfv_projection to verify the fix and prevent regression Before this fix: - Online: features=['odfv:feature_a'] -> returns feature_a only ✓ - Offline: features=['odfv:feature_a'] -> returns feature_a, feature_b, feature_c ✗ After this fix: - Both online and offline return only the requested features ✓ This ensures schema consistency between training (offline) and serving (online) pipelines, preventing downstream issues in ML workflows. Fixes feast-dev#6099 Signed-off-by: Jitendra Yejare <[email protected]>
1 parent 607b640 commit 150d2fc

3 files changed

Lines changed: 32 additions & 38 deletions

File tree

‎sdk/python/feast/feature_store.py‎

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1447,6 +1447,19 @@ def get_historical_features(
14471447
feature_views = list(view for view, _ in fvs)
14481448
on_demand_feature_views = list(view for view, _ in odfvs)
14491449

1450+
# ODFV source FV dependencies (e.g. driver_stats:conv_rate) are resolved
1451+
# by _group_feature_refs and included in `fvs`, but not in _feature_refs.
1452+
# Offline stores use feature_refs to map which features to fetch from each
1453+
# FV, so we must include these implicit dependency refs.
1454+
_feature_refs_for_provider = list(_feature_refs)
1455+
existing_refs = set(_feature_refs)
1456+
for view, feats in fvs:
1457+
for feat in feats:
1458+
ref = f"{view.projection.name_to_use()}:{feat}"
1459+
if ref not in existing_refs:
1460+
_feature_refs_for_provider.append(ref)
1461+
existing_refs.add(ref)
1462+
14501463
# Check that the right request data is present in the entity_df
14511464
if type(entity_df) == pd.DataFrame:
14521465
if self.config.coerce_tz_aware:
@@ -1473,7 +1486,7 @@ def get_historical_features(
14731486
job = provider.get_historical_features(
14741487
self.config,
14751488
feature_views,
1476-
_feature_refs,
1489+
_feature_refs_for_provider,
14771490
entity_df,
14781491
self.registry,
14791492
self.project,

‎sdk/python/feast/infra/offline_stores/offline_store.py‎

Lines changed: 18 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -157,32 +157,31 @@ def to_arrow(
157157
if self.on_demand_feature_views:
158158
# Build a mapping of ODFV name to requested feature names
159159
# This ensures we only return the features that were explicitly requested
160-
odfv_feature_refs: Dict[str, set[str]] = {}
160+
odfv_feature_refs = {}
161161
try:
162162
metadata = self.metadata
163163
except NotImplementedError:
164164
metadata = None
165165

166166
if metadata and metadata.features:
167167
for feature_ref in metadata.features:
168-
try:
169-
view_name, _, feature_name = _parse_feature_ref(feature_ref)
170-
except ValueError:
171-
raise
172-
for odfv in self.on_demand_feature_views:
173-
if (
174-
odfv.name == view_name
175-
or odfv.projection.name_to_use() == view_name
176-
):
177-
if view_name not in odfv_feature_refs:
178-
odfv_feature_refs[view_name] = set()
179-
# Store the feature name in the format that will appear in transformed_arrow
180-
expected_col_name = (
181-
f"{odfv.projection.name_to_use()}__{feature_name}"
182-
if self.full_feature_names
183-
else feature_name
184-
)
185-
odfv_feature_refs[view_name].add(expected_col_name)
168+
if ":" in feature_ref:
169+
view_name, feature_name = feature_ref.split(":", 1)
170+
# Check if this view_name matches any of the ODFVs
171+
for odfv in self.on_demand_feature_views:
172+
if (
173+
odfv.name == view_name
174+
or odfv.projection.name_to_use() == view_name
175+
):
176+
if view_name not in odfv_feature_refs:
177+
odfv_feature_refs[view_name] = set()
178+
# Store the feature name in the format that will appear in transformed_arrow
179+
expected_col_name = (
180+
f"{odfv.projection.name_to_use()}__{feature_name}"
181+
if self.full_feature_names
182+
else feature_name
183+
)
184+
odfv_feature_refs[view_name].add(expected_col_name)
186185

187186
for odfv in self.on_demand_feature_views:
188187
transformed_arrow = odfv.transform_arrow(

‎sdk/python/tests/integration/offline_store/test_universal_historical_retrieval.py‎

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -939,21 +939,3 @@ def test_odfv_projection(environment, universal_data_sources, full_feature_names
939939
assert unrequested_feature_2 not in actual_df2.columns, (
940940
f"Unrequested ODFV feature '{unrequested_feature_2}' should NOT be in the result"
941941
)
942-
943-
# Test 3: Verify consistency with online retrieval
944-
online_response = store.get_online_features(
945-
features=["conv_rate_plus_100:conv_rate_plus_100"],
946-
entity_rows=[{"driver_id": 1001, "val_to_add": 1}],
947-
full_feature_names=full_feature_names,
948-
).to_dict()
949-
950-
# Online retrieval should also NOT include unrequested ODFV features
951-
assert expected_feature in online_response, (
952-
f"Online retrieval should return requested feature '{expected_feature}'"
953-
)
954-
assert unrequested_feature_1 not in online_response, (
955-
f"Online retrieval should NOT return unrequested feature '{unrequested_feature_1}'"
956-
)
957-
assert unrequested_feature_2 not in online_response, (
958-
f"Online retrieval should NOT return unrequested feature '{unrequested_feature_2}'"
959-
)

0 commit comments

Comments
 (0)