forked from feast-dev/feast
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathe2e_test_validation.py
More file actions
298 lines (263 loc) · 9.78 KB
/
e2e_test_validation.py
File metadata and controls
298 lines (263 loc) · 9.78 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
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
import math
import os
import time
from datetime import datetime, timedelta
from pathlib import Path
from typing import List, Optional
import pandas as pd
import pytest
import yaml
from pytz import utc
from feast import FeatureStore, FeatureView, FileSource, RepoConfig
from feast.data_format import ParquetFormat
from feast.entity import Entity
from feast.field import Field
from feast.infra.registry.registry import Registry
from feast.types import Array, Bytes, Int64, String
from tests.integration.feature_repos.integration_test_repo_config import (
IntegrationTestRepoConfig,
)
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,
FileParquetDatasetSourceCreator,
)
from tests.integration.feature_repos.universal.data_sources.redshift import (
RedshiftDataSourceCreator,
)
def validate_offline_online_store_consistency(
fs: FeatureStore, fv: FeatureView, split_dt: datetime
) -> None:
now = datetime.utcnow()
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=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)
# 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,
test_repo_config,
repo_dir_name: Path,
offline_creator: DataSourceCreator,
):
offline_store_config = offline_creator.create_offline_store_config()
online_store = test_repo_config.online_store
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=str(Path(repo_dir_name)),
entity_key_serialization_version=2,
)
config_dict = config.dict()
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":
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,
),
]
)
def validate_registry_data_source_apply(test_registry: Registry):
# Create Feature Views
batch_source = FileSource(
name="test_source",
file_format=ParquetFormat(),
path="file://feast/*",
timestamp_field="ts_col",
created_timestamp_column="timestamp",
)
entity = Entity(name="fs1_my_entity_1", join_keys=["test"])
fv1 = FeatureView(
name="my_feature_view_1",
schema=[
Field(name="fs1_my_feature_1", dtype=Int64),
Field(name="fs1_my_feature_2", dtype=String),
Field(name="fs1_my_feature_3", dtype=Array(String)),
Field(name="fs1_my_feature_4", dtype=Array(Bytes)),
],
entities=[entity],
tags={"team": "matchmaking"},
source=batch_source,
ttl=timedelta(minutes=5),
)
project = "project"
# Register data source and feature view
test_registry.apply_data_source(batch_source, project, commit=False)
test_registry.apply_feature_view(fv1, project, commit=True)
registry_feature_views = test_registry.list_feature_views(project)
registry_data_sources = test_registry.list_data_sources(project)
assert len(registry_feature_views) == 1
assert len(registry_data_sources) == 1
registry_feature_view = registry_feature_views[0]
assert registry_feature_view.batch_source == batch_source
registry_data_source = registry_data_sources[0]
assert registry_data_source == batch_source
# Check that change to batch source propagates
batch_source.timestamp_field = "new_ts_col"
test_registry.apply_data_source(batch_source, project, commit=False)
test_registry.apply_feature_view(fv1, project, commit=True)
registry_feature_views = test_registry.list_feature_views(project)
registry_data_sources = test_registry.list_data_sources(project)
assert len(registry_feature_views) == 1
assert len(registry_data_sources) == 1
registry_feature_view = registry_feature_views[0]
assert registry_feature_view.batch_source == batch_source
registry_batch_source = test_registry.list_data_sources(project)[0]
assert registry_batch_source == batch_source
test_registry.teardown()
# Will try to reload registry, which will fail because the file has been deleted
with pytest.raises(FileNotFoundError):
test_registry._get_registry_proto(project=project)