FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

fix: Serve aliased on demand feature views in feature services · feast-dev/feast@933b68c · GitHub

Repository navigation

Commit 933b68c

Browse files
committed
fix: Serve aliased on demand feature views in feature services
An ODFV added to a FeatureService with with_name() produces feature refs under the alias, but the online transform lookup was keyed by the ODFV's registered name. The transform was skipped and its features were silently missing from get_online_features responses. Key the lookup by the projection alias when one is set. Signed-off-by: breken-ai <312387581+breken-ai@users.noreply.github.com>
1 parent 3667772 commit 933b68c

2 files changed

Lines changed: 64 additions & 1 deletion

File tree

‎sdk/python/feast/utils.py‎

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -834,7 +834,12 @@ def _augment_response_with_on_demand_transforms(
834834
"""
835835
from feast.online_response import OnlineResponse
836836

837-
requested_odfv_map = {odfv.name: odfv for odfv in requested_on_demand_feature_views}
837+
# Feature refs name an ODFV by its alias when it was added to a
838+
# FeatureService with ``with_name``, so key the lookup the same way.
839+
requested_odfv_map = {
840+
(odfv.projection.name_alias if odfv.projection else None) or odfv.name: odfv
841+
for odfv in requested_on_demand_feature_views
842+
}
838843
requested_odfv_feature_names = requested_odfv_map.keys()
839844

840845
odfv_feature_refs = defaultdict(list)

‎sdk/python/tests/unit/test_on_demand_pandas_transformation.py‎

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88

99
from feast import (
1010
Entity,
11+
FeatureService,
1112
FeatureStore,
1213
FeatureView,
1314
FileSource,
@@ -597,3 +598,60 @@ def aliased_guard(inputs: pd.DataFrame) -> pd.DataFrame:
597598
# the aliased-but-declared source must survive; the unrelated FV stays hidden
598599
assert response["saw_declared"] == [True]
599600
assert response["saw_undeclared"] == [False]
601+
602+
603+
@pytest.mark.parametrize("mode", ["pandas", "python"])
604+
def test_feature_service_serves_aliased_odfv_features(mode):
605+
"""An ODFV added to a FeatureService under ``with_name`` must still be
606+
computed. Its feature refs use the alias, so the transform lookup has to be
607+
keyed by the alias too, not only by the ODFV's registered name."""
608+
with tempfile.TemporaryDirectory() as data_dir:
609+
store, driver, src, fv1, fv2, driver_df = _two_fv_store(data_dir)
610+
611+
if mode == "pandas":
612+
613+
@on_demand_feature_view(
614+
sources=[fv1],
615+
schema=[Field(name="conv_rate_x10", dtype=Float64)],
616+
mode="pandas",
617+
)
618+
def scaled(inputs: pd.DataFrame) -> pd.DataFrame:
619+
out = pd.DataFrame()
620+
out["conv_rate_x10"] = inputs["conv_rate"] * 10
621+
return out
622+
623+
else:
624+
625+
@on_demand_feature_view(
626+
sources=[fv1],
627+
schema=[Field(name="conv_rate_x10", dtype=Float64)],
628+
mode="python",
629+
)
630+
def scaled(inputs: dict) -> dict:
631+
return {"conv_rate_x10": [v * 10 for v in inputs["conv_rate"]]}
632+
633+
service = FeatureService(
634+
name="aliased_service",
635+
features=[fv1, scaled.with_name("scaled_alias")],
636+
)
637+
store.apply([driver, src, fv1, scaled, service])
638+
store.write_to_online_store(feature_view_name="fv1", df=driver_df)
639+
640+
response = store.get_online_features(
641+
entity_rows=[{"driver_id": 1001}],
642+
features=store.get_feature_service("aliased_service"),
643+
).to_dict()
644+
assert response["conv_rate_x10"] == [
645+
pytest.approx(response["conv_rate"][0] * 10)
646+
]
647+
648+
if mode != "pandas":
649+
return
650+
response = store.get_online_features(
651+
entity_rows=[{"driver_id": 1001}],
652+
features=store.get_feature_service("aliased_service"),
653+
full_feature_names=True,
654+
).to_dict()
655+
assert response["scaled_alias__conv_rate_x10"] == [
656+
pytest.approx(response["fv1__conv_rate"][0] * 10)
657+
]

0 commit comments

Comments
 (0)

Back | FazBrowse Home | New Git URL