Skip to content

Commit

Permalink
Compute property-level diffs for repo objects
Browse files Browse the repository at this point in the history
Signed-off-by: Achal Shah <[email protected]>
  • Loading branch information
achals committed Dec 16, 2021
1 parent ce243a4 commit c4f9c52
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 7 deletions.
27 changes: 27 additions & 0 deletions sdk/python/feast/diff/FcoDiff.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,3 +75,30 @@ def tag_proto_objects_for_keep_delete_add(
objs_to_delete = [e for e in existing_objs if e.spec.name not in desired_obj_names]

return objs_to_keep, objs_to_delete, objs_to_add


FIELDS_TO_IGNORE = {"project"}


def diff_between(current: U, new: U, object_type: str) -> FcoDiff:
assert current.DESCRIPTOR.full_name == new.DESCRIPTOR.full_name
property_diffs = []
transition: TransitionType
if current.spec == new.spec:
transition = TransitionType.UNCHANGED
else:
transition = TransitionType.UPDATE
for _field in current.spec.DESCRIPTOR.fields:
if _field.name in FIELDS_TO_IGNORE:
continue
if getattr(current.spec, _field.name) != getattr(new.spec, _field.name):
property_diffs.append(
PropertyDiff(
_field.name,
getattr(current.spec, _field.name),
getattr(new.spec, _field.name),
)
)
return FcoDiff(
new.spec.name, object_type, current, new, property_diffs, transition,
)
15 changes: 8 additions & 7 deletions sdk/python/feast/registry.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
FcoDiff,
RegistryDiff,
TransitionType,
diff_between,
tag_proto_objects_for_keep_delete_add,
)
from feast.entity import Entity
Expand Down Expand Up @@ -197,14 +198,14 @@ def diff_between(
)
)
for e in objects_to_keep:
current_obj_proto = [
_e
for _e in getattr(current_registry, object_type)
if _e.spec.name == e.spec.name
][0]
diff.add_fco_diff(
FcoDiff(
e.spec.name,
attribute_to_object_type_str[object_type],
e,
e,
[],
TransitionType.UNCHANGED,
diff_between(
current_obj_proto, e, attribute_to_object_type_str[object_type]
)
)

Expand Down
7 changes: 7 additions & 0 deletions sdk/python/feast/repo_operations.py
Original file line number Diff line number Diff line change
Expand Up @@ -269,6 +269,7 @@ def log_cli_output(diff, views_to_delete, views_to_keep):
TransitionType.CREATE: ("Created", Fore.GREEN),
TransitionType.DELETE: ("Deleted", Fore.RED),
TransitionType.UNCHANGED: ("Unchanged", Fore.LIGHTBLUE_EX),
TransitionType.UPDATE: ("Updated", Fore.YELLOW),
}
for fco_diff in diff.fco_diffs:
if fco_diff.name == DUMMY_ENTITY_NAME:
Expand All @@ -277,6 +278,12 @@ def log_cli_output(diff, views_to_delete, views_to_keep):
click.echo(
f"{action} {fco_diff.fco_type} {Style.BRIGHT + color}{fco_diff.name}{Style.RESET_ALL}"
)
if fco_diff.transition_type == TransitionType.UPDATE:
for _p in fco_diff.fco_property_diffs:
click.echo(
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}"
)

views_to_keep_in_infra = [
view for view in views_to_keep if isinstance(view, FeatureView)
]
Expand Down

0 comments on commit c4f9c52

Please sign in to comment.