-
Notifications
You must be signed in to change notification settings - Fork 1.5k
feat: Optional input_schema for ODFV (#6308) #6312
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
nquinn408
merged 9 commits into
feast-dev:master
from
nquinn408:odfv-optional-input-schema
Apr 23, 2026
Merged
Changes from 1 commit
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
56b0620
feat: Optional input_schema for ODFV (#6308)
nickquinn408 19f4b55
Feedback and fixes
nickquinn408 8139c07
Remove output and switch use name
nickquinn408 baefe1b
Switch window to time_window
nickquinn408 49bc668
Removing changes on Aggregation
nickquinn408 490341c
Update sdk/python/tests/unit/test_on_demand_feature_view_input_schema.py
nquinn408 9b57112
Feedback
nickquinn408 81448ce
Update sdk/python/feast/on_demand_feature_view.py
nquinn408 d683424
fix linter
nickquinn408 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next
Next commit
feat: Optional input_schema for ODFV (#6308)
Signed-off-by: Nick Quinn <nicholas_quinn@apple.com>
- Loading branch information
commit 56b0620e9b9c852f9dbe8d14bccde82dd0e202de
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
165 changes: 165 additions & 0 deletions
165
sdk/python/tests/unit/test_on_demand_feature_view_input_schema.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,165 @@ | ||
| # Copyright 2025 The Feast Authors | ||
| # | ||
| # Licensed under the Apache License, Version 2.0 (the "License"); | ||
| # you may not use this file except in compliance with the License. | ||
| # You may obtain a copy of the License at | ||
| # | ||
| # https://www.apache.org/licenses/LICENSE-2.0 | ||
| # | ||
| # Unless required by applicable law or agreed to in writing, software | ||
| # distributed under the License is distributed on an "AS IS" BASIS, | ||
| # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| # See the License for the specific language governing permissions and | ||
| # limitations under the License. | ||
|
|
||
| """Tests for OnDemandFeatureView input_schema support.""" | ||
|
|
||
| import copy | ||
| from datetime import timedelta | ||
|
|
||
| import pandas as pd | ||
| import pytest | ||
|
|
||
| from feast import Entity, Field | ||
| from feast.aggregation import Aggregation | ||
| from feast.on_demand_feature_view import OnDemandFeatureView, on_demand_feature_view | ||
| from feast.types import Float64, Int64 | ||
| from feast.value_type import ValueType | ||
|
|
||
| user = Entity(name="user", join_keys=["user_id"], value_type=ValueType.INT64) | ||
|
|
||
|
|
||
| def test_decorator_with_input_schema(): | ||
| """The @on_demand_feature_view decorator supports input_schema without sources.""" | ||
|
|
||
| @on_demand_feature_view( | ||
| input_schema=[ | ||
| Field(name="txn_amount", dtype=Float64), | ||
| ], | ||
| schema=[ | ||
| Field(name="txn_count", dtype=Int64), | ||
| Field(name="total_txn_amount", dtype=Float64), | ||
| Field(name="avg_txn_amount", dtype=Float64), | ||
| ], | ||
| aggregations=[ | ||
| Aggregation( | ||
| column="txn_amount", | ||
| function="count", | ||
| output="txn_count", | ||
| window=timedelta(days=30), | ||
| ), | ||
| Aggregation( | ||
| column="txn_amount", | ||
| function="sum", | ||
| output="total_txn_amount", | ||
| window=timedelta(days=30), | ||
| ), | ||
| Aggregation( | ||
| column="txn_amount", | ||
| function="mean", | ||
| output="avg_txn_amount", | ||
| window=timedelta(days=30), | ||
| ), | ||
| ], | ||
| entities=[user], | ||
| ) | ||
| def compute_txn_stats(df: pd.DataFrame) -> pd.DataFrame: | ||
| return df | ||
|
|
||
| assert isinstance(compute_txn_stats, OnDemandFeatureView) | ||
| assert compute_txn_stats.name == "compute_txn_stats" | ||
| assert compute_txn_stats.input_schema == [Field(name="txn_amount", dtype=Float64)] | ||
| assert len(compute_txn_stats.aggregations) == 3 | ||
| assert len(compute_txn_stats.features) == 3 | ||
|
|
||
| # The internal sentinel RequestSource should be present | ||
| sentinel_name = f"{OnDemandFeatureView._INPUT_SCHEMA_SOURCE_PREFIX}compute_txn_stats" | ||
| assert sentinel_name in compute_txn_stats.source_request_sources | ||
|
|
||
| # sources (user-visible) should be empty | ||
| assert compute_txn_stats.sources == [] | ||
|
|
||
|
|
||
| def test_aggregation_aliases(): | ||
| """Aggregation accepts 'output' alias for 'name' and 'window' alias for 'time_window'.""" | ||
| agg = Aggregation( | ||
| column="txn_amount", | ||
| function="sum", | ||
| output="total_txn_amount", | ||
| window=timedelta(days=30), | ||
| ) | ||
| assert agg.name == "total_txn_amount" | ||
| assert agg.time_window == timedelta(days=30) | ||
|
|
||
|
|
||
| def test_input_schema_proto_roundtrip(): | ||
| """An ODFV with input_schema survives a to_proto / from_proto round-trip.""" | ||
|
|
||
| @on_demand_feature_view( | ||
| input_schema=[ | ||
| Field(name="txn_amount", dtype=Float64), | ||
| ], | ||
| schema=[ | ||
| Field(name="total_txn_amount", dtype=Float64), | ||
| ], | ||
| aggregations=[ | ||
| Aggregation( | ||
| column="txn_amount", | ||
| function="sum", | ||
| output="total_txn_amount", | ||
| window=timedelta(days=30), | ||
| ), | ||
| ], | ||
| entities=[user], | ||
| ) | ||
| def txn_view(df: pd.DataFrame) -> pd.DataFrame: | ||
| return df | ||
|
|
||
| proto = txn_view.to_proto() | ||
| restored = OnDemandFeatureView.from_proto(proto) | ||
|
|
||
| assert restored.input_schema == txn_view.input_schema | ||
| assert restored.aggregations == txn_view.aggregations | ||
| sentinel_name = f"{OnDemandFeatureView._INPUT_SCHEMA_SOURCE_PREFIX}txn_view" | ||
| assert sentinel_name in restored.source_request_sources | ||
|
|
||
|
|
||
| def test_input_schema_copy(): | ||
| """__copy__ preserves input_schema and aggregations.""" | ||
|
|
||
| @on_demand_feature_view( | ||
| input_schema=[ | ||
| Field(name="txn_amount", dtype=Float64), | ||
| ], | ||
| schema=[ | ||
| Field(name="total_txn_amount", dtype=Float64), | ||
| ], | ||
| aggregations=[ | ||
| Aggregation(column="txn_amount", function="sum", output="total_txn_amount"), | ||
| ], | ||
| entities=[user], | ||
| ) | ||
| def copy_view(df: pd.DataFrame) -> pd.DataFrame: | ||
| return df | ||
|
|
||
| cloned = copy.copy(copy_view) | ||
| assert cloned.input_schema == copy_view.input_schema | ||
| assert cloned.aggregations == copy_view.aggregations | ||
| sentinel_name = f"{OnDemandFeatureView._INPUT_SCHEMA_SOURCE_PREFIX}copy_view" | ||
| assert sentinel_name in cloned.source_request_sources | ||
|
|
||
|
|
||
| def test_sources_required_without_input_schema(): | ||
| """Constructor raises if neither sources nor input_schema is provided.""" | ||
| with pytest.raises( | ||
| (ValueError, TypeError), | ||
|
nquinn408 marked this conversation as resolved.
Outdated
|
||
| ): | ||
|
|
||
| def dummy(df): | ||
| return df | ||
|
|
||
| OnDemandFeatureView( | ||
| name="bad_view", | ||
| schema=[Field(name="out", dtype=Float64)], | ||
| udf=dummy, | ||
| ) | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.