| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent 3667772 commit 933b68c
2 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -834,7 +834,12 @@ def _augment_response_with_on_demand_transforms( | |||
| 834 | 834 | """ | |
| 835 | 835 | from feast.online_response import OnlineResponse | |
| 836 | 836 | ||
| 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 | + } | ||
| 838 | 843 | requested_odfv_feature_names = requested_odfv_map.keys() | |
| 839 | 844 | ||
| 840 | 845 | odfv_feature_refs = defaultdict(list) | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -8,6 +8,7 @@ | |||
| 8 | 8 | ||
| 9 | 9 | from feast import ( | |
| 10 | 10 | Entity, | |
| 11 | + FeatureService, | ||
| 11 | 12 | FeatureStore, | |
| 12 | 13 | FeatureView, | |
| 13 | 14 | FileSource, | |
@@ -597,3 +598,60 @@ def aliased_guard(inputs: pd.DataFrame) -> pd.DataFrame: | |||
| 597 | 598 | # the aliased-but-declared source must survive; the unrelated FV stays hidden | |
| 598 | 599 | assert response["saw_declared"] == [True] | |
| 599 | 600 | 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 | + ] | ||
| Back | FazBrowse Home | New Git URL |
0 commit comments