forked from feast-dev/feast
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_cli_apply_duplicates.py
More file actions
188 lines (158 loc) · 6.49 KB
/
Copy pathtest_cli_apply_duplicates.py
File metadata and controls
188 lines (158 loc) · 6.49 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
import tempfile
from pathlib import Path
from textwrap import dedent
from tests.utils.cli_repo_creator import CliRunner, get_example_repo
def test_cli_apply_duplicated_featureview_names() -> None:
run_simple_apply_test(
example_repo_file_name="example_feature_repo_with_duplicated_featureview_names.py",
expected_error=b"Please ensure that all feature view names are case-insensitively unique",
)
def test_cli_apply_duplicate_data_source_names() -> None:
run_simple_apply_test(
example_repo_file_name="example_repo_duplicate_data_source_names.py",
expected_error=b"Multiple data sources share the same case-insensitive name",
)
def run_simple_apply_test(example_repo_file_name: str, expected_error: bytes):
with tempfile.TemporaryDirectory() as repo_dir_name, tempfile.TemporaryDirectory() as data_dir_name:
runner = CliRunner()
# Construct an example repo in a temporary dir
repo_path = Path(repo_dir_name)
data_path = Path(data_dir_name)
repo_config = repo_path / "feature_store.yaml"
repo_config.write_text(
dedent(
f"""
project: foo
registry: {data_path / "registry.db"}
provider: local
online_store:
path: {data_path / "online_store.db"}
"""
)
)
repo_example = repo_path / "example.py"
repo_example.write_text(get_example_repo(example_repo_file_name))
rc, output = runner.run_with_output(["apply"], cwd=repo_path)
assert rc != 0 and expected_error in output
def test_cli_apply_imported_featureview() -> None:
"""
Tests that applying a feature view imported from a separate Python file is successful.
"""
with tempfile.TemporaryDirectory() as repo_dir_name, tempfile.TemporaryDirectory() as data_dir_name:
runner = CliRunner()
# Construct an example repo in a temporary dir
repo_path = Path(repo_dir_name)
data_path = Path(data_dir_name)
repo_config = repo_path / "feature_store.yaml"
repo_config.write_text(
dedent(
f"""
project: foo
registry: {data_path / "registry.db"}
provider: local
online_store:
path: {data_path / "online_store.db"}
"""
)
)
# Import feature view from an existing file so it exists in two files.
repo_example = repo_path / "example.py"
repo_example.write_text(
get_example_repo("example_feature_repo_with_driver_stats_feature_view.py")
)
repo_example_2 = repo_path / "example_2.py"
repo_example_2.write_text(
"from example import driver_hourly_stats_view\n"
"from feast import FeatureService\n"
"a_feature_service = FeatureService(\n"
" name='driver_locations_service',\n"
" features=[driver_hourly_stats_view],\n"
")\n"
)
rc, output = runner.run_with_output(["apply"], cwd=repo_path)
assert rc == 0
assert b"Created feature service driver_locations_service" in output
def test_cli_apply_imported_featureview_with_duplication() -> None:
"""
Tests that applying feature views with duplicated names is not possible, even if one of the
duplicated feature views is imported from another file.
"""
with tempfile.TemporaryDirectory() as repo_dir_name, tempfile.TemporaryDirectory() as data_dir_name:
runner = CliRunner()
# Construct an example repo in a temporary dir
repo_path = Path(repo_dir_name)
data_path = Path(data_dir_name)
repo_config = repo_path / "feature_store.yaml"
repo_config.write_text(
dedent(
f"""
project: foo
registry: {data_path / "registry.db"}
provider: local
online_store:
path: {data_path / "online_store.db"}
"""
)
)
# Import feature view with duplicated name to try breaking the deduplication logic.
repo_example = repo_path / "example.py"
repo_example.write_text(
get_example_repo("example_feature_repo_with_driver_stats_feature_view.py")
)
repo_example_2 = repo_path / "example_2.py"
repo_example_2.write_text(
"from datetime import timedelta\n"
"from example import driver, driver_hourly_stats, driver_hourly_stats_view\n"
"from feast import FeatureService, FeatureView\n"
"a_feature_service = FeatureService(\n"
" name='driver_locations_service',\n"
" features=[driver_hourly_stats_view],\n"
")\n"
"driver_hourly_stats_view_2 = FeatureView(\n"
" name='driver_hourly_stats',\n"
" entities=[driver],\n"
" ttl=timedelta(days=1),\n"
" online=True,\n"
" source=driver_hourly_stats,\n"
" tags={'dummy': 'true'})\n"
)
rc, output = runner.run_with_output(["apply"], cwd=repo_path)
assert rc != 0
assert (
b"More than one feature view with name driver_hourly_stats found." in output
)
def test_cli_apply_duplicated_featureview_names_multiple_py_files() -> None:
"""
Test apply feature views with duplicated names from multiple py files in a feature repo using CLI
"""
with tempfile.TemporaryDirectory() as repo_dir_name, tempfile.TemporaryDirectory() as data_dir_name:
runner = CliRunner()
# Construct an example repo in a temporary dir
repo_path = Path(repo_dir_name)
data_path = Path(data_dir_name)
repo_config = repo_path / "feature_store.yaml"
repo_config.write_text(
dedent(
f"""
project: foo
registry: {data_path / "registry.db"}
provider: local
online_store:
path: {data_path / "online_store.db"}
"""
)
)
# Create multiple py files containing the same feature view name
for i in range(3):
repo_example = repo_path / f"example{i}.py"
repo_example.write_text(
get_example_repo(
"example_feature_repo_with_driver_stats_feature_view.py"
)
)
rc, output = runner.run_with_output(["apply"], cwd=repo_path)
assert (
rc != 0
and b"Please ensure that all feature view names are case-insensitively unique"
in output
)