-
Notifications
You must be signed in to change notification settings - Fork 996
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
Refactor Environment class and DataSourceCreator API, and use fixtures for datasets and data sources #1790
Merged
feast-ci-bot
merged 53 commits into
feast-dev:master
from
achals:achal/integration-test-fixups
Sep 1, 2021
Merged
Refactor Environment class and DataSourceCreator API, and use fixtures for datasets and data sources #1790
Changes from all commits
Commits
Show all changes
53 commits
Select commit
Hold shift + click to select a range
789d7a1
Fix API cruft from DataSourceCreator
achals 8b7eab5
Remove the need for get_prefixed_table_name
achals 0cc21ab
major refactor
achals 6ddd5b0
move start time
achals a700745
Remove one dimension of variation to be added in later
achals c25b6cb
Fix default
achals a3e4473
Fixups
achals 3f632fd
Fixups
achals 9aeea86
Fix up tests
achals 84cbefd
Add retries to execute_redshift_statement_async
achals fe180eb
Add retries to execute_redshift_statement_async
achals 0cd08d2
refactoooor
achals 4701183
remove retries
achals 4cde284
Remove provider variation since they don't really play a big role
achals 974bb0b
Session scoped cache for test datasets and skipping older tests whose…
achals dbbd6fb
make format
achals 473b630
make format
achals 95982e2
remove import
achals fc1b4ee
merge from master
achals df9596b
fix merge
achals fc46edb
Use an enum for the stopping procedure instead of the bools
achals 0daaff0
Fix refs
achals ef6a6b3
fix step
achals d63691d
WIP fixes
achals 3d75977
Fix for feature inferencing
achals 1abbaa8
C901 '_python_value_to_proto_value' is too complex :(
achals 21996b7
Split out construct_test_repo and construct_universal_test_repo
achals 4541561
remove import
achals 2f20b5c
add unsafe_hash
achals 6cc32b5
Update testrepoconfig
achals 68f2997
Update testrepoconfig
achals a73868d
Remove kwargs from construct_universal_test_environment
achals ff9d49d
Remove unneeded method
achals b95c3ee
Docs
achals 3e5aada
Kill skipped tests
achals b6abcaa
reorder
achals 9580654
add todo
achals 171a1ef
Split universal vs non data_source_cache
achals de9d8aa
make format
achals 6454775
WIP fixtures
achals 3fbb2e4
WIP Trying fixtures more effectively
achals 2961d58
fix refs
achals 1739815
Fix refs
achals fe14ba3
Fix refs
achals 43d8e27
Fix refs
achals 58c75b0
fix historical tests
achals 8b5ba5a
renames
achals c445f53
CR updates
achals e0ccd9b
use the actual ref to data source creators
achals 4d4efad
merge from master
achals a510ca6
format
achals 6c10502
unused imports'
achals ff1fb81
Add ids for pytest params
achals 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 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 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 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 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 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 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 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
192 changes: 192 additions & 0 deletions
192
sdk/python/tests/integration/feature_repos/repo_configuration.py
This file contains 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,192 @@ | ||
import tempfile | ||
import uuid | ||
from contextlib import contextmanager | ||
from dataclasses import dataclass, field | ||
from datetime import datetime, timedelta | ||
from pathlib import Path | ||
from typing import Any, Dict, List, Optional, Type, Union | ||
|
||
import pandas as pd | ||
|
||
from feast import FeatureStore, FeatureView, RepoConfig, driver_test_data | ||
from feast.data_source import DataSource | ||
from tests.integration.feature_repos.universal.data_source_creator import ( | ||
DataSourceCreator, | ||
) | ||
from tests.integration.feature_repos.universal.data_sources.bigquery import ( | ||
BigQueryDataSourceCreator, | ||
) | ||
from tests.integration.feature_repos.universal.data_sources.file import ( | ||
FileDataSourceCreator, | ||
) | ||
from tests.integration.feature_repos.universal.data_sources.redshift import ( | ||
RedshiftDataSourceCreator, | ||
) | ||
from tests.integration.feature_repos.universal.feature_views import ( | ||
create_customer_daily_profile_feature_view, | ||
create_driver_hourly_stats_feature_view, | ||
) | ||
|
||
|
||
@dataclass(frozen=True, repr=True) | ||
class IntegrationTestRepoConfig: | ||
""" | ||
This class should hold all possible parameters that may need to be varied by individual tests. | ||
""" | ||
|
||
provider: str = "local" | ||
online_store: Union[str, Dict] = "sqlite" | ||
|
||
offline_store_creator: Type[DataSourceCreator] = FileDataSourceCreator | ||
|
||
full_feature_names: bool = True | ||
infer_event_timestamp_col: bool = True | ||
infer_features: bool = False | ||
|
||
|
||
DYNAMO_CONFIG = {"type": "dynamodb", "region": "us-west-2"} | ||
REDIS_CONFIG = {"type": "redis", "connection_string": "localhost:6379,db=0"} | ||
FULL_REPO_CONFIGS: List[IntegrationTestRepoConfig] = [ | ||
# Local configurations | ||
IntegrationTestRepoConfig(), | ||
IntegrationTestRepoConfig(online_store=REDIS_CONFIG), | ||
# GCP configurations | ||
IntegrationTestRepoConfig( | ||
provider="gcp", | ||
offline_store_creator=BigQueryDataSourceCreator, | ||
online_store="datastore", | ||
), | ||
IntegrationTestRepoConfig( | ||
provider="gcp", | ||
offline_store_creator=BigQueryDataSourceCreator, | ||
online_store=REDIS_CONFIG, | ||
), | ||
# AWS configurations | ||
IntegrationTestRepoConfig( | ||
provider="aws", | ||
offline_store_creator=RedshiftDataSourceCreator, | ||
online_store=DYNAMO_CONFIG, | ||
), | ||
IntegrationTestRepoConfig( | ||
provider="aws", | ||
offline_store_creator=RedshiftDataSourceCreator, | ||
online_store=REDIS_CONFIG, | ||
), | ||
] | ||
|
||
|
||
def construct_universal_entities() -> Dict[str, List[Any]]: | ||
return {"customer": list(range(1001, 1110)), "driver": list(range(5001, 5110))} | ||
|
||
|
||
def construct_universal_datasets( | ||
entities: Dict[str, List[Any]], start_time: datetime, end_time: datetime | ||
) -> Dict[str, pd.DataFrame]: | ||
customer_df = driver_test_data.create_customer_daily_profile_df( | ||
entities["customer"], start_time, end_time | ||
) | ||
driver_df = driver_test_data.create_driver_hourly_stats_df( | ||
entities["driver"], start_time, end_time | ||
) | ||
orders_df = driver_test_data.create_orders_df( | ||
customers=entities["customer"], | ||
drivers=entities["driver"], | ||
start_date=end_time - timedelta(days=365), | ||
end_date=end_time + timedelta(days=365), | ||
order_count=1000, | ||
) | ||
|
||
return {"customer": customer_df, "driver": driver_df, "orders": orders_df} | ||
|
||
|
||
def construct_universal_data_sources( | ||
datasets: Dict[str, pd.DataFrame], data_source_creator: DataSourceCreator | ||
) -> Dict[str, DataSource]: | ||
customer_ds = data_source_creator.create_data_source( | ||
datasets["customer"], | ||
destination_name="customer_profile", | ||
event_timestamp_column="event_timestamp", | ||
created_timestamp_column="created", | ||
) | ||
driver_ds = data_source_creator.create_data_source( | ||
datasets["driver"], | ||
destination_name="driver_hourly", | ||
event_timestamp_column="event_timestamp", | ||
created_timestamp_column="created", | ||
) | ||
orders_ds = data_source_creator.create_data_source( | ||
datasets["orders"], | ||
destination_name="orders", | ||
event_timestamp_column="event_timestamp", | ||
created_timestamp_column="created", | ||
) | ||
return {"customer": customer_ds, "driver": driver_ds, "orders": orders_ds} | ||
|
||
|
||
def construct_universal_feature_views( | ||
data_sources: Dict[str, DataSource], | ||
) -> Dict[str, FeatureView]: | ||
return { | ||
"customer": create_customer_daily_profile_feature_view( | ||
data_sources["customer"] | ||
), | ||
"driver": create_driver_hourly_stats_feature_view(data_sources["driver"]), | ||
} | ||
|
||
|
||
@dataclass | ||
class Environment: | ||
name: str | ||
test_repo_config: IntegrationTestRepoConfig | ||
feature_store: FeatureStore | ||
data_source_creator: DataSourceCreator | ||
|
||
end_date: datetime = field( | ||
default=datetime.now().replace(microsecond=0, second=0, minute=0) | ||
) | ||
|
||
def __post_init__(self): | ||
self.start_date: datetime = self.end_date - timedelta(days=7) | ||
|
||
|
||
def table_name_from_data_source(ds: DataSource) -> Optional[str]: | ||
if hasattr(ds, "table_ref"): | ||
return ds.table_ref | ||
elif hasattr(ds, "table"): | ||
return ds.table | ||
return None | ||
|
||
|
||
@contextmanager | ||
def construct_test_environment( | ||
test_repo_config: IntegrationTestRepoConfig, | ||
test_suite_name: str = "integration_test", | ||
) -> Environment: | ||
project = f"{test_suite_name}_{str(uuid.uuid4()).replace('-', '')[:8]}" | ||
|
||
offline_creator: DataSourceCreator = test_repo_config.offline_store_creator(project) | ||
|
||
offline_store_config = offline_creator.create_offline_store_config() | ||
online_store = test_repo_config.online_store | ||
|
||
with tempfile.TemporaryDirectory() as repo_dir_name: | ||
config = RepoConfig( | ||
registry=str(Path(repo_dir_name) / "registry.db"), | ||
project=project, | ||
provider=test_repo_config.provider, | ||
offline_store=offline_store_config, | ||
online_store=online_store, | ||
repo_path=repo_dir_name, | ||
) | ||
fs = FeatureStore(config=config) | ||
environment = Environment( | ||
name=project, | ||
test_repo_config=test_repo_config, | ||
feature_store=fs, | ||
data_source_creator=offline_creator, | ||
) | ||
|
||
try: | ||
yield environment | ||
finally: | ||
fs.teardown() |
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.
do we want to not exclude the original names of the columns then?
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.
Those are already excluded in a section above this one.