-
Notifications
You must be signed in to change notification settings - Fork 1.2k
feat: Create stream and batch feature view abstractions #2559
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 3 commits into
feast-dev:master
from
achals:achal/stream-feature-view
Apr 18, 2022
Merged
Changes from all commits
Commits
Show all changes
3 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 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,58 @@ | ||
| from datetime import timedelta | ||
| from typing import Dict, List, Optional, Union | ||
|
|
||
| from feast.data_source import DataSource | ||
| from feast.entity import Entity | ||
| from feast.feature_view import FeatureView | ||
| from feast.field import Field | ||
| from feast.protos.feast.core.DataSource_pb2 import DataSource as DataSourceProto | ||
|
|
||
| SUPPORTED_BATCH_SOURCES = { | ||
| "BigQuerySource", | ||
| "FileSource", | ||
| "RedshiftSource", | ||
| "SnowflakeSource", | ||
| "SparkSource", | ||
| "TrinoSource", | ||
| } | ||
|
|
||
|
|
||
| class BatchFeatureView(FeatureView): | ||
| def __init__( | ||
| self, | ||
| *, | ||
| name: Optional[str] = None, | ||
| entities: Optional[Union[List[Entity], List[str]]] = None, | ||
| ttl: Optional[timedelta] = None, | ||
| tags: Optional[Dict[str, str]] = None, | ||
| online: bool = True, | ||
| description: str = "", | ||
| owner: str = "", | ||
| schema: Optional[List[Field]] = None, | ||
| source: Optional[DataSource] = None, | ||
| ): | ||
|
|
||
| if source is None: | ||
| raise ValueError("Feature views need a source specified") | ||
| if ( | ||
| type(source).__name__ not in SUPPORTED_BATCH_SOURCES | ||
| and source.to_proto().type != DataSourceProto.SourceType.CUSTOM_SOURCE | ||
| ): | ||
| raise ValueError( | ||
| f"Batch feature views need a batch source, expected one of {SUPPORTED_BATCH_SOURCES} " | ||
| f"or CUSTOM_SOURCE, got {type(source).__name__}: {source.name} instead " | ||
| ) | ||
|
|
||
| super().__init__( | ||
| name=name, | ||
| entities=entities, | ||
| ttl=ttl, | ||
| batch_source=None, | ||
| stream_source=None, | ||
| tags=tags, | ||
| online=online, | ||
| description=description, | ||
| owner=owner, | ||
| schema=schema, | ||
| source=source, | ||
| ) | ||
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,54 @@ | ||
| from datetime import timedelta | ||
| from typing import Dict, List, Optional, Union | ||
|
|
||
| from feast.data_source import DataSource | ||
| from feast.entity import Entity | ||
| from feast.feature_view import FeatureView | ||
| from feast.field import Field | ||
| from feast.protos.feast.core.DataSource_pb2 import DataSource as DataSourceProto | ||
|
|
||
| SUPPORTED_STREAM_SOURCES = { | ||
| "KafkaSource", | ||
| "KinesisSource", | ||
| } | ||
|
|
||
|
|
||
| class StreamFeatureView(FeatureView): | ||
| def __init__( | ||
| self, | ||
| *, | ||
| name: Optional[str] = None, | ||
| entities: Optional[Union[List[Entity], List[str]]] = None, | ||
| ttl: Optional[timedelta] = None, | ||
| tags: Optional[Dict[str, str]] = None, | ||
| online: bool = True, | ||
| description: str = "", | ||
| owner: str = "", | ||
| schema: Optional[List[Field]] = None, | ||
| source: Optional[DataSource] = None, | ||
| ): | ||
|
|
||
| if source is None: | ||
| raise ValueError("Feature views need a source specified") | ||
| if ( | ||
| type(source).__name__ not in SUPPORTED_STREAM_SOURCES | ||
| and source.to_proto().type != DataSourceProto.SourceType.CUSTOM_SOURCE | ||
| ): | ||
| raise ValueError( | ||
| f"Stream feature views need a stream source, expected one of {SUPPORTED_STREAM_SOURCES} " | ||
| f"or CUSTOM_SOURCE, got {type(source).__name__}: {source.name} instead " | ||
| ) | ||
|
|
||
| super().__init__( | ||
| name=name, | ||
| entities=entities, | ||
| ttl=ttl, | ||
| batch_source=None, | ||
| stream_source=None, | ||
| tags=tags, | ||
| online=online, | ||
| description=description, | ||
| owner=owner, | ||
| schema=schema, | ||
| source=source, | ||
| ) |
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,70 @@ | ||
| from datetime import timedelta | ||
|
|
||
| import pytest | ||
|
|
||
| from feast.batch_feature_view import BatchFeatureView | ||
| from feast.data_format import AvroFormat | ||
| from feast.data_source import KafkaSource | ||
| from feast.infra.offline_stores.file_source import FileSource | ||
| from feast.stream_feature_view import StreamFeatureView | ||
|
|
||
|
|
||
| def test_create_batch_feature_view(): | ||
| batch_source = FileSource(path="some path") | ||
| BatchFeatureView( | ||
| name="test batch feature view", | ||
| entities=[], | ||
| ttl=timedelta(days=30), | ||
| source=batch_source, | ||
| ) | ||
|
|
||
| with pytest.raises(ValueError): | ||
| BatchFeatureView( | ||
| name="test batch feature view", entities=[], ttl=timedelta(days=30) | ||
| ) | ||
|
|
||
| stream_source = KafkaSource( | ||
| name="kafka", | ||
| event_timestamp_column="", | ||
| bootstrap_servers="", | ||
| message_format=AvroFormat(""), | ||
| topic="topic", | ||
| batch_source=FileSource(path="some path"), | ||
| ) | ||
| with pytest.raises(ValueError): | ||
| BatchFeatureView( | ||
| name="test batch feature view", | ||
| entities=[], | ||
| ttl=timedelta(days=30), | ||
| source=stream_source, | ||
| ) | ||
|
|
||
|
|
||
| def test_create_stream_feature_view(): | ||
| stream_source = KafkaSource( | ||
| name="kafka", | ||
| event_timestamp_column="", | ||
| bootstrap_servers="", | ||
| message_format=AvroFormat(""), | ||
| topic="topic", | ||
| batch_source=FileSource(path="some path"), | ||
| ) | ||
| StreamFeatureView( | ||
| name="test batch feature view", | ||
| entities=[], | ||
| ttl=timedelta(days=30), | ||
| source=stream_source, | ||
| ) | ||
|
|
||
| with pytest.raises(ValueError): | ||
| StreamFeatureView( | ||
| name="test batch feature view", entities=[], ttl=timedelta(days=30) | ||
| ) | ||
|
|
||
| with pytest.raises(ValueError): | ||
| StreamFeatureView( | ||
| name="test batch feature view", | ||
| entities=[], | ||
| ttl=timedelta(days=30), | ||
| source=FileSource(path="some path"), | ||
| ) |
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.