-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Expand file tree
/
Copy pathtest_registry_diff.py
More file actions
195 lines (172 loc) · 6.8 KB
/
test_registry_diff.py
File metadata and controls
195 lines (172 loc) · 6.8 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
import pandas as pd
from feast import Field, PushSource
from feast.diff.registry_diff import (
diff_registry_objects,
tag_objects_for_keep_delete_update_add,
)
from feast.entity import Entity
from feast.feast_object import ALL_RESOURCE_TYPES
from feast.feature_view import FeatureView
from feast.on_demand_feature_view import on_demand_feature_view
from feast.permissions.action import AuthzedAction
from feast.permissions.permission import Permission
from feast.permissions.policy import RoleBasedPolicy
from feast.types import String
from tests.utils.data_source_test_creator import prep_file_source
def test_tag_objects_for_keep_delete_update_add(simple_dataset_1):
with prep_file_source(df=simple_dataset_1, timestamp_field="ts_1") as file_source:
entity = Entity(name="id", join_keys=["id"])
to_delete = FeatureView(
name="to_delete",
entities=[entity],
source=file_source,
)
unchanged_fv = FeatureView(
name="fv1",
entities=[entity],
source=file_source,
)
pre_changed = FeatureView(
name="fv2",
entities=[entity],
source=file_source,
tags={"when": "before"},
)
post_changed = FeatureView(
name="fv2",
entities=[entity],
source=file_source,
tags={"when": "after"},
)
to_add = FeatureView(
name="to_add",
entities=[entity],
source=file_source,
)
keep, delete, update, add = tag_objects_for_keep_delete_update_add(
[unchanged_fv, pre_changed, to_delete], [unchanged_fv, post_changed, to_add]
)
assert len(list(keep)) == 2
assert unchanged_fv in keep
assert pre_changed in keep
assert post_changed not in keep
assert len(list(delete)) == 1
assert to_delete in delete
assert len(list(update)) == 2
assert unchanged_fv in update
assert post_changed in update
assert pre_changed not in update
assert len(list(add)) == 1
assert to_add in add
def test_diff_registry_objects_feature_views(simple_dataset_1):
with prep_file_source(df=simple_dataset_1, timestamp_field="ts_1") as file_source:
entity = Entity(name="id", join_keys=["id"])
pre_changed = FeatureView(
name="fv2",
entities=[entity],
source=file_source,
tags={"when": "before"},
)
post_changed = FeatureView(
name="fv2",
entities=[entity],
source=file_source,
tags={"when": "after"},
)
feast_object_diffs = diff_registry_objects(
pre_changed, pre_changed, "feature view"
)
assert len(feast_object_diffs.feast_object_property_diffs) == 0
feast_object_diffs = diff_registry_objects(
pre_changed, post_changed, "feature view"
)
assert len(feast_object_diffs.feast_object_property_diffs) == 1
assert feast_object_diffs.feast_object_property_diffs[0].property_name == "tags"
assert feast_object_diffs.feast_object_property_diffs[0].val_existing == {
"when": "before"
}
assert feast_object_diffs.feast_object_property_diffs[0].val_declared == {
"when": "after"
}
def test_diff_odfv(simple_dataset_1):
with prep_file_source(df=simple_dataset_1, timestamp_field="ts_1") as file_source:
entity = Entity(name="id", join_keys=["id"])
fv = FeatureView(
name="fv2",
entities=[entity],
source=file_source,
tags={"when": "before"},
)
@on_demand_feature_view(
sources=[fv],
schema=[Field(name="first_char", dtype=String)],
)
def pre_changed(inputs: pd.DataFrame) -> pd.DataFrame:
df = pd.DataFrame()
df["first_char"] = inputs["string_col"].str[:1].astype("string")
return df
@on_demand_feature_view(
sources=[fv],
schema=[Field(name="first_char", dtype=String)],
)
def post_changed(inputs: pd.DataFrame) -> pd.DataFrame:
df = pd.DataFrame()
df["first_char"] = inputs["string_col"].str[:1].astype("string") + "hi"
return df
feast_object_diffs = diff_registry_objects(
pre_changed, pre_changed, "on demand feature view"
)
assert len(feast_object_diffs.feast_object_property_diffs) == 0
feast_object_diffs = diff_registry_objects(
pre_changed, post_changed, "on demand feature view"
)
# Note that user_defined_function.body is excluded because it always changes (dill is non-deterministic), even
# if no code is changed
assert len(feast_object_diffs.feast_object_property_diffs) == 3
assert feast_object_diffs.feast_object_property_diffs[0].property_name == "name"
# Note we should only now be looking at changes for the feature_transformation field
assert (
feast_object_diffs.feast_object_property_diffs[1].property_name
== "feature_transformation.name"
)
assert (
feast_object_diffs.feast_object_property_diffs[2].property_name
== "feature_transformation.body_text"
)
def test_diff_registry_objects_batch_to_push_source(simple_dataset_1):
with prep_file_source(df=simple_dataset_1, timestamp_field="ts_1") as file_source:
entity = Entity(name="id", join_keys=["id"])
pre_changed = FeatureView(
name="fv2",
entities=[entity],
source=file_source,
)
post_changed = FeatureView(
name="fv2",
entities=[entity],
source=PushSource(name="push_source", batch_source=file_source),
)
feast_object_diffs = diff_registry_objects(
pre_changed, post_changed, "feature view"
)
assert len(feast_object_diffs.feast_object_property_diffs) == 1
assert (
feast_object_diffs.feast_object_property_diffs[0].property_name
== "stream_source"
)
def test_diff_registry_objects_permissions():
pre_changed = Permission(
name="reader",
types=ALL_RESOURCE_TYPES,
policy=RoleBasedPolicy(roles=["reader"]),
actions=[AuthzedAction.DESCRIBE],
)
post_changed = Permission(
name="reader",
types=ALL_RESOURCE_TYPES,
policy=RoleBasedPolicy(roles=["reader"]),
actions=[AuthzedAction.CREATE],
)
feast_object_diffs = diff_registry_objects(pre_changed, post_changed, "permission")
assert len(feast_object_diffs.feast_object_property_diffs) == 1
assert feast_object_diffs.feast_object_property_diffs[0].property_name == "actions"