-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Expand file tree
/
Copy pathe2e_test_validation.py
More file actions
242 lines (216 loc) · 7.75 KB
/
e2e_test_validation.py
File metadata and controls
242 lines (216 loc) · 7.75 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
import math
import os
import time
from datetime import datetime, timedelta, timezone
from pathlib import Path
from typing import Dict, List, Optional, Union
import pandas as pd
import yaml
from feast import FeatureStore, FeatureView, RepoConfig
from feast.utils import _utc_now
from tests.universal.feature_repos.integration_test_repo_config import (
IntegrationTestRepoConfig,
)
from tests.universal.feature_repos.universal.data_source_creator import (
DataSourceCreator,
)
from tests.universal.feature_repos.universal.data_sources.file import (
FileDataSourceCreator,
FileParquetDatasetSourceCreator,
)
def validate_offline_online_store_consistency(
fs: FeatureStore, fv: FeatureView, split_dt: datetime
) -> None:
now = _utc_now()
full_feature_names = True
check_offline_store: bool = True
# Run materialize()
# use both tz-naive & tz-aware timestamps to test that they're both correctly handled
start_date = (now - timedelta(hours=5)).replace(tzinfo=timezone.utc)
end_date = split_dt
fs.materialize(feature_views=[fv.name], start_date=start_date, end_date=end_date)
time.sleep(10)
# check result of materialize()
_check_offline_and_online_features(
fs=fs,
fv=fv,
driver_id=1,
event_timestamp=end_date,
expected_value=0.3,
full_feature_names=full_feature_names,
check_offline_store=check_offline_store,
)
_check_offline_and_online_features(
fs=fs,
fv=fv,
driver_id=2,
event_timestamp=end_date,
expected_value=None,
full_feature_names=full_feature_names,
check_offline_store=check_offline_store,
)
# check prior value for materialize_incremental()
_check_offline_and_online_features(
fs=fs,
fv=fv,
driver_id=3,
event_timestamp=end_date,
expected_value=4,
full_feature_names=full_feature_names,
check_offline_store=check_offline_store,
)
# run materialize_incremental()
fs.materialize_incremental(feature_views=[fv.name], end_date=now)
updated_fv = fs.registry.get_feature_view(fv.name, fs.project)
# Check if materialization_intervals was updated by the registry
assert (
len(updated_fv.materialization_intervals) == 2
and updated_fv.materialization_intervals[0][0] == start_date
and updated_fv.materialization_intervals[0][1] == end_date
and updated_fv.materialization_intervals[1][0] == end_date
and updated_fv.materialization_intervals[1][1]
== now.replace(tzinfo=timezone.utc)
)
# check result of materialize_incremental()
_check_offline_and_online_features(
fs=fs,
fv=fv,
driver_id=3,
event_timestamp=now,
expected_value=5,
full_feature_names=full_feature_names,
check_offline_store=check_offline_store,
)
def _check_offline_and_online_features(
fs: FeatureStore,
fv: FeatureView,
driver_id: int,
event_timestamp: datetime,
expected_value: Optional[float],
full_feature_names: bool,
check_offline_store: bool = True,
) -> None:
# Check online store
response_dict = fs.get_online_features(
[f"{fv.name}:value"],
[{"driver_id": driver_id}],
full_feature_names=full_feature_names,
).to_dict()
# Wait for materialization to occur
if not response_dict[f"{fv.name}__value"][0]:
# Deal with flake with a retry
time.sleep(10)
response_dict = fs.get_online_features(
[f"{fv.name}:value"],
[{"driver_id": driver_id}],
full_feature_names=full_feature_names,
).to_dict()
if full_feature_names:
if expected_value:
assert response_dict[f"{fv.name}__value"][0], f"Response: {response_dict}"
assert abs(response_dict[f"{fv.name}__value"][0] - expected_value) < 1e-6, (
f"Response: {response_dict}, Expected: {expected_value}"
)
else:
assert response_dict[f"{fv.name}__value"][0] is None
else:
if expected_value:
assert response_dict["value"][0], f"Response: {response_dict}"
assert abs(response_dict["value"][0] - expected_value) < 1e-6, (
f"Response: {response_dict}, Expected: {expected_value}"
)
else:
assert response_dict["value"][0] is None
# Check offline store
if check_offline_store:
df = fs.get_historical_features(
entity_df=pd.DataFrame.from_dict(
{"driver_id": [driver_id], "event_timestamp": [event_timestamp]}
),
features=[f"{fv.name}:value"],
full_feature_names=full_feature_names,
).to_df()
if full_feature_names:
if expected_value:
assert (
abs(
df.to_dict(orient="list")[f"{fv.name}__value"][0]
- expected_value
)
< 1e-6
)
else:
assert not df.to_dict(orient="list")[f"{fv.name}__value"] or math.isnan(
df.to_dict(orient="list")[f"{fv.name}__value"][0]
)
else:
if expected_value:
assert (
abs(df.to_dict(orient="list")["value"][0] - expected_value) < 1e-6
)
else:
assert not df.to_dict(orient="list")["value"] or math.isnan(
df.to_dict(orient="list")["value"][0]
)
def make_feature_store_yaml(
project,
repo_dir_name: Path,
offline_creator: DataSourceCreator,
provider: str,
online_store: Optional[Union[str, Dict]],
):
offline_store_config = offline_creator.create_offline_store_config()
config = RepoConfig(
registry=str(Path(repo_dir_name) / "registry.db"),
project=project,
provider=provider,
offline_store=offline_store_config,
online_store=online_store,
repo_path=str(Path(repo_dir_name)),
entity_key_serialization_version=3,
)
config_dict = config.model_dump(by_alias=True)
if (
isinstance(config_dict["online_store"], dict)
and "redis_type" in config_dict["online_store"]
):
if str(config_dict["online_store"]["redis_type"]) == "RedisType.redis_cluster":
config_dict["online_store"]["redis_type"] = "redis_cluster"
elif str(config_dict["online_store"]["redis_type"]) == "RedisType.redis":
config_dict["online_store"]["redis_type"] = "redis"
config_dict["repo_path"] = str(config_dict["repo_path"])
return yaml.safe_dump(config_dict)
NULLABLE_ONLINE_STORE_CONFIGS: List[IntegrationTestRepoConfig] = [
IntegrationTestRepoConfig(
provider="local",
offline_store_creator=FileDataSourceCreator,
online_store=None,
),
IntegrationTestRepoConfig(
provider="local",
offline_store_creator=FileParquetDatasetSourceCreator,
online_store=None,
),
]
# Only test if this is NOT a local test
if os.getenv("FEAST_IS_LOCAL_TEST", "False") != "True":
from tests.universal.feature_repos.universal.data_sources.bigquery import (
BigQueryDataSourceCreator,
)
from tests.universal.feature_repos.universal.data_sources.redshift import (
RedshiftDataSourceCreator,
)
NULLABLE_ONLINE_STORE_CONFIGS.extend(
[
IntegrationTestRepoConfig(
provider="gcp",
offline_store_creator=BigQueryDataSourceCreator,
online_store=None,
),
IntegrationTestRepoConfig(
provider="aws",
offline_store_creator=RedshiftDataSourceCreator,
online_store=None,
),
]
)