Skip to content

Commit bc2cb77

Browse files
committed
Add methods to offline/online stores to specify supported upstream sources
Signed-off-by: Achal Shah <achals@gmail.com>
1 parent 2013c04 commit bc2cb77

8 files changed

Lines changed: 53 additions & 11 deletions

File tree

‎sdk/python/feast/infra/offline_stores/bigquery.py‎

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
_get_requested_feature_views_to_features_dict,
2323
)
2424
from feast.registry import Registry
25-
from feast.repo_config import FeastConfigBaseModel, RepoConfig
25+
from feast.repo_config import FeastOfflineStoreConfigBaseModel, RepoConfig
2626

2727
try:
2828
from google.api_core.exceptions import NotFound
@@ -36,7 +36,7 @@
3636
raise FeastExtrasDependencyImportError("gcp", str(e))
3737

3838

39-
class BigQueryOfflineStoreConfig(FeastConfigBaseModel):
39+
class BigQueryOfflineStoreConfig(FeastOfflineStoreConfigBaseModel):
4040
""" Offline store config for GCP BigQuery """
4141

4242
type: Literal["bigquery"] = "bigquery"
@@ -48,8 +48,12 @@ class BigQueryOfflineStoreConfig(FeastConfigBaseModel):
4848
project_id: Optional[StrictStr] = None
4949
""" (optional) GCP project name used for the BigQuery offline store """
5050

51+
def supports_data_source(self, data_source: DataSource) -> bool:
52+
return isinstance(data_source, BigQuerySource)
53+
5154

5255
class BigQueryOfflineStore(OfflineStore):
56+
5357
@staticmethod
5458
def pull_latest_from_table_or_query(
5559
data_source: DataSource,

‎sdk/python/feast/infra/offline_stores/file.py‎

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,15 +16,18 @@
1616
_run_field_mapping,
1717
)
1818
from feast.registry import Registry
19-
from feast.repo_config import FeastConfigBaseModel, RepoConfig
19+
from feast.repo_config import FeastOfflineStoreConfigBaseModel, RepoConfig
2020

2121

22-
class FileOfflineStoreConfig(FeastConfigBaseModel):
22+
class FileOfflineStoreConfig(FeastOfflineStoreConfigBaseModel):
2323
""" Offline store config for local (file-based) store """
2424

2525
type: Literal["file"] = "file"
2626
""" Offline store type selector"""
2727

28+
def supports_data_source(self, data_source: DataSource) -> bool:
29+
return isinstance(data_source, FileSource)
30+
2831

2932
class FileRetrievalJob(RetrievalJob):
3033
def __init__(self, evaluation_function: Callable):

‎sdk/python/feast/infra/offline_stores/offline_store.py‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,3 +68,4 @@ def get_historical_features(
6868
project: str,
6969
) -> RetrievalJob:
7070
pass
71+

‎sdk/python/feast/infra/online_stores/datastore.py‎

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
from feast.infra.online_stores.online_store import OnlineStore
2727
from feast.protos.feast.types.EntityKey_pb2 import EntityKey as EntityKeyProto
2828
from feast.protos.feast.types.Value_pb2 import Value as ValueProto
29-
from feast.repo_config import FeastConfigBaseModel, RepoConfig
29+
from feast.repo_config import RepoConfig, FeastOnlineStoreConfigBaseModel
3030

3131
try:
3232
from google.auth.exceptions import DefaultCredentialsError
@@ -42,7 +42,7 @@
4242
]
4343

4444

45-
class DatastoreOnlineStoreConfig(FeastConfigBaseModel):
45+
class DatastoreOnlineStoreConfig(FeastOnlineStoreConfigBaseModel):
4646
""" Online store config for GCP Datastore """
4747

4848
type: Literal["datastore"] = "datastore"
@@ -60,6 +60,11 @@ class DatastoreOnlineStoreConfig(FeastConfigBaseModel):
6060
write_batch_size: Optional[PositiveInt] = 50
6161
""" (optional) Amount of feature rows per batch being written into Datastore"""
6262

63+
def supports_offline_store(self, offline_store: Any) -> bool:
64+
# We're defaulting to supporting all offline stores for now.
65+
return offline_store.type == "bigquery"
66+
67+
6368

6469
class DatastoreOnlineStore(OnlineStore):
6570
"""

‎sdk/python/feast/infra/online_stores/redis.py‎

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
from feast.infra.online_stores.online_store import OnlineStore
2626
from feast.protos.feast.types.EntityKey_pb2 import EntityKey as EntityKeyProto
2727
from feast.protos.feast.types.Value_pb2 import Value as ValueProto
28-
from feast.repo_config import FeastConfigBaseModel
28+
from feast.repo_config import FeastOnlineStoreConfigBaseModel, FeastOfflineStoreConfigBaseModel
2929

3030
try:
3131
from redis import Redis
@@ -43,7 +43,7 @@ class RedisType(str, Enum):
4343
redis_cluster = "redis_cluster"
4444

4545

46-
class RedisOnlineStoreConfig(FeastConfigBaseModel):
46+
class RedisOnlineStoreConfig(FeastOnlineStoreConfigBaseModel):
4747
"""Online store config for Redis store"""
4848

4949
type: Literal["redis"] = "redis"
@@ -56,6 +56,10 @@ class RedisOnlineStoreConfig(FeastConfigBaseModel):
5656
"""Connection string containing the host, port, and configuration parameters for Redis
5757
format: host:port,parameter1,parameter2 eg. redis:6379,db=0 """
5858

59+
def supports_offline_store(self, offline_store: Any) -> bool:
60+
# We're defaulting to supporting all offline stores for now.
61+
return True
62+
5963

6064
class RedisOnlineStore(OnlineStore):
6165
_client: Optional[Union[Redis, RedisCluster]] = None

‎sdk/python/feast/infra/online_stores/sqlite.py‎

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,10 @@
2828
from feast.infra.online_stores.online_store import OnlineStore
2929
from feast.protos.feast.types.EntityKey_pb2 import EntityKey as EntityKeyProto
3030
from feast.protos.feast.types.Value_pb2 import Value as ValueProto
31-
from feast.repo_config import FeastConfigBaseModel, RepoConfig
31+
from feast.repo_config import RepoConfig, FeastOnlineStoreConfigBaseModel
3232

3333

34-
class SqliteOnlineStoreConfig(FeastConfigBaseModel):
34+
class SqliteOnlineStoreConfig(FeastOnlineStoreConfigBaseModel):
3535
""" Online store config for local (SQLite-based) store """
3636

3737
type: Literal[
@@ -42,6 +42,10 @@ class SqliteOnlineStoreConfig(FeastConfigBaseModel):
4242
path: StrictStr = "data/online.db"
4343
""" (optional) Path to sqlite db """
4444

45+
def supports_offline_store(self, offline_store: Any) -> bool:
46+
return offline_store.type == "file"
47+
48+
4549

4650
class SqliteOnlineStore(OnlineStore):
4751
"""

‎sdk/python/feast/repo_config.py‎

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
1+
from abc import abstractmethod
12
from pathlib import Path
23
from typing import Any
34

45
import yaml
6+
from feast.data_source import DataSource
57
from pydantic import BaseModel, StrictInt, StrictStr, ValidationError, root_validator
68
from pydantic.error_wrappers import ErrorWrapper
79
from pydantic.typing import Dict, Optional, Union
@@ -32,13 +34,29 @@ class Config:
3234
extra = "allow"
3335

3436

35-
class FeastConfigBaseModel(BaseModel):
37+
class FeastOfflineStoreConfigBaseModel(BaseModel):
3638
""" Feast Pydantic Configuration Class """
3739

3840
class Config:
3941
arbitrary_types_allowed = True
4042
extra = "forbid"
4143

44+
@abstractmethod
45+
def supports_data_source(self, data_source: DataSource) -> bool:
46+
...
47+
48+
49+
class FeastOnlineStoreConfigBaseModel(BaseModel):
50+
""" Feast Pydantic Configuration Class """
51+
52+
class Config:
53+
arbitrary_types_allowed = True
54+
extra = "forbid"
55+
56+
@abstractmethod
57+
def supports_offline_store(self, offline_store: Any) -> bool:
58+
...
59+
4260

4361
class RegistryConfig(FeastBaseModel):
4462
""" Metadata Store Configuration. Configuration that relates to reading from and writing to the Feast registry."""

‎sdk/python/feast/repo_operations.py‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -155,8 +155,11 @@ def apply_total(repo_config: RepoConfig, repo_path: Path):
155155

156156
# Make sure the data source used by this feature view is supported by Feast
157157
for data_source in data_sources:
158+
assert repo_config.offline_store.supports_data_source(data_source)
158159
data_source.validate()
159160

161+
assert repo_config.online_store.supports_offline_store(repo_config.offline_store)
162+
160163
update_data_sources_with_inferred_event_timestamp_col(data_sources)
161164
for view in repo.feature_views:
162165
view.infer_features_from_input_source()

0 commit comments

Comments
 (0)