|
1 | | -from feast.data_source import BigQuerySource, DataSource, FileSource |
2 | | -from feast.errors import FeastOfflineStoreUnsupportedDataSource |
| 1 | +import importlib |
| 2 | +from typing import Any |
| 3 | + |
| 4 | +from feast import errors |
3 | 5 | from feast.infra.offline_stores.offline_store import OfflineStore |
4 | | -from feast.repo_config import ( |
5 | | - BigQueryOfflineStoreConfig, |
6 | | - FileOfflineStoreConfig, |
7 | | - OfflineStoreConfig, |
8 | | -) |
9 | 6 |
|
10 | 7 |
|
11 | | -def get_offline_store_from_config( |
12 | | - offline_store_config: OfflineStoreConfig, |
13 | | -) -> OfflineStore: |
| 8 | +def get_offline_store_from_config(offline_store_config: Any,) -> OfflineStore: |
14 | 9 | """Get the offline store from offline store config""" |
15 | 10 |
|
16 | | - if isinstance(offline_store_config, FileOfflineStoreConfig): |
17 | | - from feast.infra.offline_stores.file import FileOfflineStore |
18 | | - |
19 | | - return FileOfflineStore() |
20 | | - elif isinstance(offline_store_config, BigQueryOfflineStoreConfig): |
21 | | - from feast.infra.offline_stores.bigquery import BigQueryOfflineStore |
22 | | - |
23 | | - return BigQueryOfflineStore() |
24 | | - |
25 | | - raise ValueError(f"Unsupported offline store config '{offline_store_config}'") |
26 | | - |
27 | | - |
28 | | -def assert_offline_store_supports_data_source( |
29 | | - offline_store_config: OfflineStoreConfig, data_source: DataSource |
30 | | -): |
31 | | - if ( |
32 | | - isinstance(offline_store_config, FileOfflineStoreConfig) |
33 | | - and isinstance(data_source, FileSource) |
34 | | - ) or ( |
35 | | - isinstance(offline_store_config, BigQueryOfflineStoreConfig) |
36 | | - and isinstance(data_source, BigQuerySource) |
37 | | - ): |
38 | | - return |
39 | | - raise FeastOfflineStoreUnsupportedDataSource( |
40 | | - offline_store_config.type, data_source.__class__.__name__ |
41 | | - ) |
| 11 | + module_name = offline_store_config.__module__ |
| 12 | + qualified_name = type(offline_store_config).__name__ |
| 13 | + store_class_name = qualified_name.replace("Config", "") |
| 14 | + try: |
| 15 | + module = importlib.import_module(module_name) |
| 16 | + except Exception as e: |
| 17 | + # The original exception can be anything - either module not found, |
| 18 | + # or any other kind of error happening during the module import time. |
| 19 | + # So we should include the original error as well in the stack trace. |
| 20 | + raise errors.FeastModuleImportError(module_name, "OfflineStore") from e |
| 21 | + |
| 22 | + # Try getting the provider class definition |
| 23 | + try: |
| 24 | + offline_store_class = getattr(module, store_class_name) |
| 25 | + except AttributeError: |
| 26 | + # This can only be one type of error, when class_name attribute does not exist in the module |
| 27 | + # So we don't have to include the original exception here |
| 28 | + raise errors.FeastClassImportError( |
| 29 | + module_name, store_class_name, class_type="OfflineStore" |
| 30 | + ) from None |
| 31 | + return offline_store_class() |
0 commit comments