-
Notifications
You must be signed in to change notification settings - Fork 1.2k
feat: Hybrid offline store #5510
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 3 commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
c738a8e
add hybrid offline store
HaoXuAI b765b5e
add hybrid offline store
HaoXuAI fd695e8
fix source type
HaoXuAI 02b2cdb
update doc
HaoXuAI bc379f5
update doc
HaoXuAI d338885
update doc
HaoXuAI 5af1cf2
update doc
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
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
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
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
203 changes: 203 additions & 0 deletions
203
sdk/python/feast/infra/offline_stores/hybrid_offline_store.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,203 @@ | ||
from datetime import datetime | ||
from pathlib import Path | ||
from typing import Any, Callable, Dict, Iterable, List, Optional, Tuple, Union | ||
|
||
import pandas as pd | ||
import pyarrow | ||
|
||
from feast import FeatureView, RepoConfig | ||
from feast.data_source import _DATA_SOURCE_FOR_OFFLINE_STORE, DataSource | ||
from feast.errors import FeastOfflineStoreInvalidName | ||
from feast.feature_logging import LoggingConfig, LoggingSource | ||
from feast.infra.offline_stores.offline_store import OfflineStore, RetrievalJob | ||
from feast.infra.offline_stores.offline_utils import get_offline_store_from_config | ||
from feast.infra.registry.base_registry import BaseRegistry | ||
from feast.protos.feast.core.DataSource_pb2 import DataSource as DataSourceProto | ||
from feast.repo_config import ( | ||
FeastConfigBaseModel, | ||
get_offline_config_from_type, | ||
get_offline_store_type, | ||
) | ||
|
||
|
||
class HybridOfflineStoreConfig(FeastConfigBaseModel): | ||
type: str = "hybrid_offline_store.HybridOfflineStore" | ||
|
||
class OfflineStoresWithConfig(FeastConfigBaseModel): | ||
type: str | ||
conf: Dict[str, Any] | ||
|
||
offline_stores: Optional[List[OfflineStoresWithConfig]] | ||
|
||
|
||
class HybridOfflineStore(OfflineStore): | ||
_instance: Optional["HybridOfflineStore"] = None | ||
_initialized: bool | ||
offline_stores: Dict[str, OfflineStore] | ||
|
||
def __new__(cls): | ||
if cls._instance is None: | ||
cls._instance = super(HybridOfflineStore, cls).__new__(cls) | ||
cls._instance._initialized = False | ||
cls._instance.offline_stores = {} | ||
return cls._instance | ||
|
||
def _initialize_offline_stores(self, config: RepoConfig): | ||
if self._initialized: | ||
return | ||
for store_cfg in getattr(config.offline_store, "offline_stores", []): | ||
try: | ||
offline_store_type = get_offline_store_type(store_cfg.type) | ||
config_cls = get_offline_config_from_type(store_cfg.type) | ||
config_instance = config_cls(**store_cfg.conf) | ||
store = get_offline_store_from_config(config_instance) | ||
self.offline_stores[offline_store_type] = store | ||
except FeastOfflineStoreInvalidName as e: | ||
raise FeastOfflineStoreInvalidName( | ||
f"Failed to initialize Hybrid offline store {store_cfg.type}: {e}" | ||
) | ||
self._initialized = True | ||
|
||
def get_source_key_from_type( | ||
self, source_type: DataSourceProto.SourceType.ValueType | ||
) -> Optional[str]: | ||
if source_type not in list(_DATA_SOURCE_FOR_OFFLINE_STORE.keys()): | ||
raise ValueError( | ||
f"Unsupported DataSource type for HybridOfflineStore: {source_type}." | ||
f"Supported types are: {list(_DATA_SOURCE_FOR_OFFLINE_STORE.keys())}" | ||
) | ||
return _DATA_SOURCE_FOR_OFFLINE_STORE.get(source_type, None) | ||
|
||
def _get_offline_store_for_feature_view( | ||
self, feature_view: FeatureView, config: RepoConfig | ||
) -> OfflineStore: | ||
self._initialize_offline_stores(config) | ||
source_type = feature_view.batch_source.source_type() | ||
store_key = self.get_source_key_from_type(source_type) | ||
if store_key is None: | ||
raise ValueError( | ||
f"Unsupported FeatureView batch_source type: {source_type}" | ||
) | ||
return self.offline_stores[store_key] | ||
|
||
def _get_offline_store_for_source( | ||
self, data_source: DataSource, config: RepoConfig | ||
) -> OfflineStore: | ||
self._initialize_offline_stores(config) | ||
source_type = data_source.source_type() | ||
store_key = self.get_source_key_from_type(source_type) | ||
if store_key is None: | ||
raise ValueError(f"Unsupported DataSource type: {source_type}") | ||
return self.offline_stores[store_key] | ||
|
||
@staticmethod | ||
def get_historical_features( | ||
config: RepoConfig, | ||
feature_views: List[FeatureView], | ||
feature_refs: List[str], | ||
entity_df: Union[pd.DataFrame, str], | ||
registry: BaseRegistry, | ||
project: str, | ||
full_feature_names: bool = False, | ||
) -> RetrievalJob: | ||
store = HybridOfflineStore()._get_offline_store_for_feature_view( | ||
feature_views[0], config | ||
) | ||
return store.get_historical_features( | ||
config, | ||
feature_views, | ||
feature_refs, | ||
entity_df, | ||
registry, | ||
project, | ||
full_feature_names, | ||
) | ||
|
||
@staticmethod | ||
def pull_latest_from_table_or_query( | ||
config: RepoConfig, | ||
data_source: DataSource, | ||
join_key_columns: List[str], | ||
feature_name_columns: List[str], | ||
timestamp_field: str, | ||
created_timestamp_column: Optional[str], | ||
start_date: datetime, | ||
end_date: datetime, | ||
) -> RetrievalJob: | ||
store = HybridOfflineStore()._get_offline_store_for_source(data_source, config) | ||
return store.pull_latest_from_table_or_query( | ||
config, | ||
data_source, | ||
join_key_columns, | ||
feature_name_columns, | ||
timestamp_field, | ||
created_timestamp_column, | ||
start_date, | ||
end_date, | ||
) | ||
|
||
@staticmethod | ||
def pull_all_from_table_or_query( | ||
config: RepoConfig, | ||
data_source: DataSource, | ||
join_key_columns: List[str], | ||
feature_name_columns: List[str], | ||
timestamp_field: str, | ||
created_timestamp_column: Optional[str] = None, | ||
start_date: Optional[datetime] = None, | ||
end_date: Optional[datetime] = None, | ||
) -> RetrievalJob: | ||
store = HybridOfflineStore()._get_offline_store_for_source(data_source, config) | ||
return store.pull_all_from_table_or_query( | ||
config, | ||
data_source, | ||
join_key_columns, | ||
feature_name_columns, | ||
timestamp_field, | ||
created_timestamp_column, | ||
start_date, | ||
end_date, | ||
) | ||
|
||
@staticmethod | ||
def write_logged_features( | ||
config: RepoConfig, | ||
data: Union[pyarrow.Table, Path], | ||
source: LoggingSource, | ||
logging_config: LoggingConfig, | ||
registry: BaseRegistry, | ||
): | ||
raise NotImplementedError( | ||
"HybridOfflineStore does not support write_logged_features. " | ||
"Please use the specific offline store for logging." | ||
) | ||
|
||
@staticmethod | ||
def offline_write_batch( | ||
config: RepoConfig, | ||
feature_view: FeatureView, | ||
table: pyarrow.Table, | ||
progress: Optional[Callable[[int], Any]], | ||
): | ||
store = HybridOfflineStore()._get_offline_store_for_feature_view( | ||
feature_view, config | ||
) | ||
return store.offline_write_batch(config, feature_view, table, progress) | ||
|
||
def validate_data_source( | ||
self, | ||
config: RepoConfig, | ||
data_source: DataSource, | ||
): | ||
store = self._get_offline_store_for_source(data_source, config) | ||
return store.validate_data_source(config, data_source) | ||
|
||
def get_table_column_names_and_types_from_data_source( | ||
self, | ||
config: RepoConfig, | ||
data_source: DataSource, | ||
) -> Iterable[Tuple[str, str]]: | ||
store = self._get_offline_store_for_source(data_source, config) | ||
return store.get_table_column_names_and_types_from_data_source( | ||
config, data_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
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
Oops, something went wrong.
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.
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.
why not just add all of this now ? is the scope large?
Uh oh!
There was an error while loading. Please reload this page.
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.
yeah it will have to update the protobuf and someother places, which will do it in next PR