-
Notifications
You must be signed in to change notification settings - Fork 978
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
Fix offline store (tz-naive & field_mapping issues) #1466
Merged
Merged
Changes from 1 commit
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
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
There are no files selected for viewing
This file contains 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 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 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 |
---|---|---|
|
@@ -83,20 +83,20 @@ def prep_bq_fs_and_fv( | |
event_timestamp_column="ts", | ||
created_timestamp_column="created_ts", | ||
date_partition_column="", | ||
field_mapping={"ts_1": "ts", "id": "driver_ident"}, | ||
field_mapping={"ts_1": "ts", "id": "driver_id"}, | ||
) | ||
|
||
fv = get_feature_view(bigquery_source) | ||
e = Entity( | ||
name="driver_id", | ||
description="id for driver", | ||
join_key="driver_ident", | ||
join_key="driver_id", | ||
value_type=ValueType.INT32, | ||
) | ||
with tempfile.TemporaryDirectory() as repo_dir_name: | ||
config = RepoConfig( | ||
registry=str(Path(repo_dir_name) / "registry.db"), | ||
project=f"test_bq_correctness_{uuid.uuid4()}", | ||
project=f"test_bq_correctness_{str(uuid.uuid4()).replace('-', '')}", | ||
provider="gcp", | ||
) | ||
fs = FeatureStore(config=config) | ||
|
@@ -138,6 +138,31 @@ def prep_local_fs_and_fv() -> Iterator[Tuple[FeatureStore, FeatureView]]: | |
yield fs, fv | ||
|
||
|
||
# Checks that both offline & online store values are as expected | ||
def check_offline_and_online_features( | ||
fs: FeatureStore, | ||
fv: FeatureView, | ||
driver_id: int, | ||
event_timestamp: datetime, | ||
expected_value: float, | ||
) -> None: | ||
# Check online store | ||
response_dict = fs.get_online_features( | ||
[f"{fv.name}:value"], [{"driver_id": driver_id}] | ||
).to_dict() | ||
assert abs(response_dict[f"{fv.name}__value"][0] - expected_value) < 1e-6 | ||
|
||
# Check offline store | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. we do have sdk/python/tests/test_historical_retrieval.py - this works but it may be more natural to cover the field mapping cases there? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Agree |
||
df = fs.get_historical_features( | ||
entity_df=pd.DataFrame.from_dict( | ||
{"driver_id": [driver_id], "event_timestamp": [event_timestamp]} | ||
), | ||
feature_refs=[f"{fv.name}:value"], | ||
).to_df() | ||
|
||
assert abs(df.to_dict()[f"{fv.name}__value"][0] - expected_value) < 1e-6 | ||
|
||
|
||
def run_materialization_test(fs: FeatureStore, fv: FeatureView) -> None: | ||
now = datetime.utcnow() | ||
# Run materialize() | ||
|
@@ -147,27 +172,22 @@ def run_materialization_test(fs: FeatureStore, fv: FeatureView) -> None: | |
fs.materialize(feature_views=[fv.name], start_date=start_date, end_date=end_date) | ||
|
||
# check result of materialize() | ||
response_dict = fs.get_online_features( | ||
[f"{fv.name}:value"], [{"driver_id": 1}] | ||
).to_dict() | ||
assert abs(response_dict[f"{fv.name}__value"][0] - 0.3) < 1e-6 | ||
check_offline_and_online_features( | ||
fs=fs, fv=fv, driver_id=1, event_timestamp=end_date, expected_value=0.3 | ||
) | ||
|
||
# check prior value for materialize_incremental() | ||
response_dict = fs.get_online_features( | ||
[f"{fv.name}:value"], [{"driver_id": 3}] | ||
).to_dict() | ||
assert abs(response_dict[f"{fv.name}__value"][0] - 4) < 1e-6 | ||
check_offline_and_online_features( | ||
fs=fs, fv=fv, driver_id=3, event_timestamp=end_date, expected_value=4 | ||
) | ||
|
||
# run materialize_incremental() | ||
fs.materialize_incremental( | ||
feature_views=[fv.name], end_date=now - timedelta(seconds=0), | ||
) | ||
fs.materialize_incremental(feature_views=[fv.name], end_date=now) | ||
|
||
# check result of materialize_incremental() | ||
response_dict = fs.get_online_features( | ||
[f"{fv.name}:value"], [{"driver_id": 3}] | ||
).to_dict() | ||
assert abs(response_dict[f"{fv.name}__value"][0] - 5) < 1e-6 | ||
check_offline_and_online_features( | ||
fs=fs, fv=fv, driver_id=3, event_timestamp=now, expected_value=5 | ||
) | ||
|
||
|
||
@pytest.mark.integration | ||
|
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this tests that things still work when the join_key is different from the name of the entity (although it should probably be in its own separate test) so can we keep it in?