-
Notifications
You must be signed in to change notification settings - Fork 1.3k
feat: Support aggregation in odfv #5666
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
Merged
Changes from 1 commit
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
a101f0f
add aggregation to odfv
398dbfa
add aggregation to odfv
5ccd4ea
add aggregation to odfv
6a39899
fix linting
62af43f
Merge branch 'master' into aggregation-odfv
HaoXuAI 81466fa
Apply suggestions from code review
HaoXuAI b9541a1
fix linting
2e85113
fix linting
6c7cf7e
Merge branch 'master' into aggregation-odfv
HaoXuAI 41d20bc
update doc
db15d1f
update doc
08d0f2a
Merge branch 'master' into aggregation-odfv
HaoXuAI 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
fix linting
Signed-off-by: hao-xu5 <hxu44@apple.com>
- Loading branch information
Some comments aren't visible on the classic Files Changed page.
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
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
89 changes: 89 additions & 0 deletions
89
sdk/python/tests/unit/test_on_demand_feature_view_aggregation.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,89 @@ | ||
| # 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 aggregations in online serving.""" | ||
|
|
||
| import pyarrow as pa | ||
|
|
||
| from feast.aggregation import Aggregation | ||
| from feast.utils import _apply_aggregations_to_response | ||
|
|
||
|
|
||
| def test_aggregation_python_mode(): | ||
| """Test aggregations in Python mode (dict format).""" | ||
| data = { | ||
| "driver_id": [1, 1, 2, 2], | ||
| "trips": [10, 20, 15, 25], | ||
| } | ||
| aggs = [Aggregation(column="trips", function="sum")] | ||
|
|
||
| result = _apply_aggregations_to_response(data, aggs, ["driver_id"], "python") | ||
|
|
||
| assert result == {"driver_id": [1, 2], "sum_trips": [30, 40]} | ||
|
|
||
|
|
||
| def test_aggregation_pandas_mode(): | ||
| """Test aggregations in Pandas mode (Arrow table format).""" | ||
| table = pa.table( | ||
| { | ||
| "driver_id": [1, 1, 2, 2], | ||
| "trips": [10, 20, 15, 25], | ||
| } | ||
| ) | ||
| aggs = [Aggregation(column="trips", function="sum")] | ||
|
|
||
| result = _apply_aggregations_to_response(table, aggs, ["driver_id"], "pandas") | ||
|
|
||
| assert isinstance(result, pa.Table) | ||
| result_df = result.to_pandas() | ||
| assert list(result_df["driver_id"]) == [1, 2] | ||
| assert list(result_df["sum_trips"]) == [30, 40] | ||
|
|
||
|
|
||
| def test_multiple_aggregations(): | ||
| """Test multiple aggregation functions.""" | ||
| data = { | ||
| "driver_id": [1, 1, 2, 2], | ||
| "trips": [10, 20, 15, 25], | ||
| "revenue": [100.0, 200.0, 150.0, 250.0], | ||
| } | ||
| aggs = [ | ||
| Aggregation(column="trips", function="sum"), | ||
| Aggregation(column="revenue", function="mean"), | ||
| ] | ||
|
|
||
| result = _apply_aggregations_to_response(data, aggs, ["driver_id"], "python") | ||
|
|
||
| assert result["driver_id"] == [1, 2] | ||
| assert result["sum_trips"] == [30, 40] | ||
| assert result["mean_revenue"] == [150.0, 200.0] | ||
|
|
||
|
|
||
| def test_no_aggregations_returns_original(): | ||
| """Test that no aggregations returns original data.""" | ||
| data = {"driver_id": [1, 2], "trips": [10, 20]} | ||
|
|
||
| result = _apply_aggregations_to_response(data, [], ["driver_id"], "python") | ||
|
|
||
| assert result == data | ||
|
|
||
|
|
||
| def test_empty_data_returns_empty(): | ||
| """Test that empty data returns empty result.""" | ||
| data = {"driver_id": [], "trips": []} | ||
| aggs = [Aggregation(column="trips", function="sum")] | ||
|
|
||
| result = _apply_aggregations_to_response(data, aggs, ["driver_id"], "python") | ||
|
|
||
| assert result == data |
Oops, something went wrong.
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.