Repository navigation
Entity value_type inference for Feature Repo registration #1538
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
feast-ci-bot
merged 9 commits into
feast-dev:master
from
mavysavydav:entityValueTypeInference
Jun 2, 2021
Merged
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
7a487dc
Added inferencing of Entity values types & corresponding test
mavysavydav 6d58084
Updated example_feature_repo_with_inference.py
mavysavydav 307fae1
Fixed lint issue introduced by previous commit
mavysavydav 697304d
Optimized infer_entity_value_type_from_feature_views
mavysavydav 3bb9524
Added entity data type inferencing to feature_store.py and organized …
mavysavydav 25dae14
Made error messages more descriptive and improved its structuring
mavysavydav 9e99e90
Removed s comments by using conftest file
mavysavydav 79e1c72
Renamed variables for clarity and added clarifying comments
mavysavydav 6dc6104
changed file name from inference_helpers.py to inference.py
mavysavydav 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 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,56 @@ | ||
| from typing import List | ||
|
|
||
| from feast import Entity | ||
| from feast.feature_view import FeatureView | ||
| from feast.value_type import ValueType | ||
|
|
||
|
|
||
| def infer_entity_value_type_from_feature_views( | ||
| entities: List[Entity], feature_views: List[FeatureView] | ||
| ) -> List[Entity]: | ||
| """ | ||
| Infer entity value type by examining schema of feature view input sources | ||
| """ | ||
| incomplete_entities = { | ||
| entity.name: entity | ||
| for entity in entities | ||
| if entity.value_type == ValueType.UNKNOWN | ||
| } | ||
| incomplete_entities_keys = incomplete_entities.keys() | ||
|
|
||
| for view in feature_views: | ||
| if not (incomplete_entities_keys & set(view.entities)): | ||
| continue # skip if view doesn't contain any entities that need inference | ||
|
|
||
| col_names_and_types = view.input.get_table_column_names_and_types() | ||
| for entity_name in view.entities: | ||
| if entity_name in incomplete_entities: | ||
| # get entity information from information extracted from the view input source | ||
| extracted_entity_name_type_pairs = list( | ||
| filter(lambda tup: tup[0] == entity_name, col_names_and_types) | ||
| ) | ||
| if len(extracted_entity_name_type_pairs) == 0: | ||
| # Doesn't mention inference error because would also be an error without inferencing | ||
| raise ValueError( | ||
| f"""No column in the input source for the {view.name} feature view matches | ||
| its entity's name.""" | ||
| ) | ||
|
|
||
| entity = incomplete_entities[entity_name] | ||
| inferred_value_type = view.input.source_datatype_to_feast_value_type()( | ||
| extracted_entity_name_type_pairs[0][1] | ||
| ) | ||
|
|
||
| if ( | ||
| entity.value_type != ValueType.UNKNOWN | ||
| and entity.value_type != inferred_value_type | ||
| ) or (len(extracted_entity_name_type_pairs) > 1): | ||
| raise ValueError( | ||
| f"""Entity value_type inference failed for {entity_name} entity. | ||
| Multiple viable matches. Please explicitly specify the entity value_type | ||
| for this entity.""" | ||
| ) | ||
|
|
||
| entity.value_type = inferred_value_type | ||
|
|
||
| return entities |
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
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,49 @@ | ||
| import pytest | ||
| from utils.data_source_utils import ( | ||
| prep_file_source, | ||
| simple_bq_source_using_query_arg, | ||
| simple_bq_source_using_table_ref_arg, | ||
| ) | ||
|
|
||
| from feast import Entity, ValueType | ||
| from feast.feature_view import FeatureView | ||
| from feast.inference import infer_entity_value_type_from_feature_views | ||
|
|
||
|
|
||
| @pytest.mark.integration | ||
| def test_data_source_ts_col_inference_success(simple_dataset_1): | ||
| with prep_file_source(df=simple_dataset_1) as file_source: | ||
| actual_file_source = file_source.event_timestamp_column | ||
| actual_bq_1 = simple_bq_source_using_table_ref_arg( | ||
| simple_dataset_1 | ||
| ).event_timestamp_column | ||
| actual_bq_2 = simple_bq_source_using_query_arg( | ||
| simple_dataset_1 | ||
| ).event_timestamp_column | ||
| expected = "ts_1" | ||
|
|
||
| assert expected == actual_file_source == actual_bq_1 == actual_bq_2 | ||
|
|
||
|
|
||
| def test_infer_entity_value_type_from_feature_views(simple_dataset_1, simple_dataset_2): | ||
| with prep_file_source( | ||
| df=simple_dataset_1, event_timestamp_column="ts_1" | ||
| ) as file_source, prep_file_source( | ||
| df=simple_dataset_2, event_timestamp_column="ts_1" | ||
| ) as file_source_2: | ||
|
|
||
| fv1 = FeatureView(name="fv1", entities=["id"], input=file_source, ttl=None,) | ||
| fv2 = FeatureView(name="fv2", entities=["id"], input=file_source_2, ttl=None,) | ||
|
|
||
| actual_1 = infer_entity_value_type_from_feature_views( | ||
| [Entity(name="id")], [fv1] | ||
| ) | ||
| actual_2 = infer_entity_value_type_from_feature_views( | ||
| [Entity(name="id")], [fv2] | ||
| ) | ||
| assert actual_1 == [Entity(name="id", value_type=ValueType.INT64)] | ||
| assert actual_2 == [Entity(name="id", value_type=ValueType.STRING)] | ||
|
|
||
| with pytest.raises(ValueError): | ||
| # two viable data types | ||
| infer_entity_value_type_from_feature_views([Entity(name="id")], [fv1, fv2]) |
23 changes: 0 additions & 23 deletions
23
...on/tests/fixtures/data_source_fixtures.py → sdk/python/tests/utils/data_source_utils.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
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.