Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add InfraDiff class for feast plan #2190

Merged
merged 3 commits into from
Jan 5, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions protos/feast/core/Registry.proto
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import "feast/core/Entity.proto";
import "feast/core/FeatureService.proto";
import "feast/core/FeatureTable.proto";
import "feast/core/FeatureView.proto";
import "feast/core/InfraObject.proto";
import "feast/core/OnDemandFeatureView.proto";
import "feast/core/RequestFeatureView.proto";
import "google/protobuf/timestamp.proto";
Expand All @@ -36,6 +37,7 @@ message Registry {
repeated OnDemandFeatureView on_demand_feature_views = 8;
repeated RequestFeatureView request_feature_views = 9;
repeated FeatureService feature_services = 7;
Infra infra = 10;

string registry_schema_version = 3; // to support migrations; incremented when schema is changed
string version_id = 4; // version id, random string generated on each update of the data; now used only for debugging purposes
Expand Down
17 changes: 1 addition & 16 deletions sdk/python/feast/diff/FcoDiff.py
Original file line number Diff line number Diff line change
@@ -1,29 +1,14 @@
from dataclasses import dataclass
from enum import Enum
from typing import Any, Iterable, List, Set, Tuple, TypeVar

from feast.base_feature_view import BaseFeatureView
from feast.diff.property_diff import PropertyDiff, TransitionType
from feast.entity import Entity
from feast.feature_service import FeatureService
from feast.protos.feast.core.Entity_pb2 import Entity as EntityProto
from feast.protos.feast.core.FeatureView_pb2 import FeatureView as FeatureViewProto


@dataclass
class PropertyDiff:
property_name: str
val_existing: str
val_declared: str


class TransitionType(Enum):
UNKNOWN = 0
CREATE = 1
DELETE = 2
UPDATE = 3
UNCHANGED = 4


@dataclass
class FcoDiff:
name: str
Expand Down
28 changes: 28 additions & 0 deletions sdk/python/feast/diff/infra_diff.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
from dataclasses import dataclass
from typing import Any, List

from feast.diff.property_diff import PropertyDiff, TransitionType


@dataclass
class InfraObjectDiff:
name: str
infra_object_type: str
current_fco: Any
new_fco: Any
fco_property_diffs: List[PropertyDiff]
transition_type: TransitionType


@dataclass
class InfraDiff:
infra_object_diffs: List[InfraObjectDiff]

def __init__(self):
self.infra_object_diffs = []

def update(self):
pass

def to_string(self):
pass
17 changes: 17 additions & 0 deletions sdk/python/feast/diff/property_diff.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
from dataclasses import dataclass
from enum import Enum


@dataclass
class PropertyDiff:
property_name: str
val_existing: str
val_declared: str


class TransitionType(Enum):
UNKNOWN = 0
CREATE = 1
DELETE = 2
UPDATE = 3
UNCHANGED = 4
31 changes: 31 additions & 0 deletions sdk/python/feast/registry.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
)
from feast.feature_service import FeatureService
from feast.feature_view import FeatureView
from feast.infra.infra_object import Infra
from feast.on_demand_feature_view import OnDemandFeatureView
from feast.protos.feast.core.Registry_pb2 import Registry as RegistryProto
from feast.registry_store import NoopRegistryStore
Expand Down Expand Up @@ -222,6 +223,36 @@ def _initialize_registry(self):
registry_proto.registry_schema_version = REGISTRY_SCHEMA_VERSION
self._registry_store.update_registry_proto(registry_proto)

def update_infra(self, infra: Infra, project: str, commit: bool = True):
"""
Updates the stored Infra object.

Args:
infra: The new Infra object to be stored.
project: Feast project that the Infra object refers to
commit: Whether the change should be persisted immediately
"""
self._prepare_registry_for_changes()
assert self.cached_registry_proto

self.cached_registry_proto.infra.CopyFrom(infra.to_proto())
if commit:
self.commit()

def get_infra(self, project: str, allow_cache: bool = False) -> Infra:
"""
Retrieves the stored Infra object.

Args:
project: Feast project that the Infra object refers to
allow_cache: Whether to allow returning this entity from a cached registry

Returns:
The stored Infra object.
"""
registry_proto = self._get_registry_proto(allow_cache=allow_cache)
return Infra.from_proto(registry_proto.infra)

def apply_entity(self, entity: Entity, project: str, commit: bool = True):
"""
Registers a single entity with Feast
Expand Down