Skip to content

Commit 1cfc25c

Browse files
authored
Compute property-level diffs for repo objects (feast-dev#2156)
* Compute property-level diffs for repo objects Signed-off-by: Achal Shah <achals@gmail.com> * Fix inference Signed-off-by: Achal Shah <achals@gmail.com>
1 parent 3cd9678 commit 1cfc25c

3 files changed

Lines changed: 40 additions & 7 deletions

File tree

sdk/python/feast/diff/FcoDiff.py

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,3 +75,28 @@ def tag_proto_objects_for_keep_delete_add(
7575
objs_to_delete = [e for e in existing_objs if e.spec.name not in desired_obj_names]
7676

7777
return objs_to_keep, objs_to_delete, objs_to_add
78+
79+
80+
FIELDS_TO_IGNORE = {"project"}
81+
82+
83+
def diff_between(current: U, new: U, object_type: str) -> FcoDiff:
84+
assert current.DESCRIPTOR.full_name == new.DESCRIPTOR.full_name
85+
property_diffs = []
86+
transition: TransitionType = TransitionType.UNCHANGED
87+
if current.spec != new.spec:
88+
for _field in current.spec.DESCRIPTOR.fields:
89+
if _field.name in FIELDS_TO_IGNORE:
90+
continue
91+
if getattr(current.spec, _field.name) != getattr(new.spec, _field.name):
92+
transition = TransitionType.UPDATE
93+
property_diffs.append(
94+
PropertyDiff(
95+
_field.name,
96+
getattr(current.spec, _field.name),
97+
getattr(new.spec, _field.name),
98+
)
99+
)
100+
return FcoDiff(
101+
new.spec.name, object_type, current, new, property_diffs, transition,
102+
)

sdk/python/feast/registry.py

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
FcoDiff,
2929
RegistryDiff,
3030
TransitionType,
31+
diff_between,
3132
tag_proto_objects_for_keep_delete_add,
3233
)
3334
from feast.entity import Entity
@@ -197,14 +198,14 @@ def diff_between(
197198
)
198199
)
199200
for e in objects_to_keep:
201+
current_obj_proto = [
202+
_e
203+
for _e in getattr(current_registry, object_type)
204+
if _e.spec.name == e.spec.name
205+
][0]
200206
diff.add_fco_diff(
201-
FcoDiff(
202-
e.spec.name,
203-
attribute_to_object_type_str[object_type],
204-
e,
205-
e,
206-
[],
207-
TransitionType.UNCHANGED,
207+
diff_between(
208+
current_obj_proto, e, attribute_to_object_type_str[object_type]
208209
)
209210
)
210211

sdk/python/feast/repo_operations.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -269,6 +269,7 @@ def log_cli_output(diff, views_to_delete, views_to_keep):
269269
TransitionType.CREATE: ("Created", Fore.GREEN),
270270
TransitionType.DELETE: ("Deleted", Fore.RED),
271271
TransitionType.UNCHANGED: ("Unchanged", Fore.LIGHTBLUE_EX),
272+
TransitionType.UPDATE: ("Updated", Fore.YELLOW),
272273
}
273274
for fco_diff in diff.fco_diffs:
274275
if fco_diff.name == DUMMY_ENTITY_NAME:
@@ -277,6 +278,12 @@ def log_cli_output(diff, views_to_delete, views_to_keep):
277278
click.echo(
278279
f"{action} {fco_diff.fco_type} {Style.BRIGHT + color}{fco_diff.name}{Style.RESET_ALL}"
279280
)
281+
if fco_diff.transition_type == TransitionType.UPDATE:
282+
for _p in fco_diff.fco_property_diffs:
283+
click.echo(
284+
f"\t{_p.property_name}: {Style.BRIGHT + color}{_p.val_existing}{Style.RESET_ALL} -> {Style.BRIGHT + Fore.LIGHTGREEN_EX}{_p.val_declared}{Style.RESET_ALL}"
285+
)
286+
280287
views_to_keep_in_infra = [
281288
view for view in views_to_keep if isinstance(view, FeatureView)
282289
]

0 commit comments

Comments
 (0)