Skip to content

Commit 6c09bc4

Browse files
Add InfraDiff class for feast plan (feast-dev#2190)
* Add InfraDiff and InfraObjectDiff classes Signed-off-by: Felix Wang <[email protected]> * Add support for Infra objects in the registry Signed-off-by: Felix Wang <[email protected]> * Rename utils to property_diff Signed-off-by: Felix Wang <[email protected]>
1 parent e8e4972 commit 6c09bc4

File tree

5 files changed

+79
-16
lines changed

5 files changed

+79
-16
lines changed

protos/feast/core/Registry.proto

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ import "feast/core/Entity.proto";
2525
import "feast/core/FeatureService.proto";
2626
import "feast/core/FeatureTable.proto";
2727
import "feast/core/FeatureView.proto";
28+
import "feast/core/InfraObject.proto";
2829
import "feast/core/OnDemandFeatureView.proto";
2930
import "feast/core/RequestFeatureView.proto";
3031
import "google/protobuf/timestamp.proto";
@@ -36,6 +37,7 @@ message Registry {
3637
repeated OnDemandFeatureView on_demand_feature_views = 8;
3738
repeated RequestFeatureView request_feature_views = 9;
3839
repeated FeatureService feature_services = 7;
40+
Infra infra = 10;
3941

4042
string registry_schema_version = 3; // to support migrations; incremented when schema is changed
4143
string version_id = 4; // version id, random string generated on each update of the data; now used only for debugging purposes

sdk/python/feast/diff/FcoDiff.py

Lines changed: 1 addition & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,14 @@
11
from dataclasses import dataclass
2-
from enum import Enum
32
from typing import Any, Iterable, List, Set, Tuple, TypeVar
43

54
from feast.base_feature_view import BaseFeatureView
5+
from feast.diff.property_diff import PropertyDiff, TransitionType
66
from feast.entity import Entity
77
from feast.feature_service import FeatureService
88
from feast.protos.feast.core.Entity_pb2 import Entity as EntityProto
99
from feast.protos.feast.core.FeatureView_pb2 import FeatureView as FeatureViewProto
1010

1111

12-
@dataclass
13-
class PropertyDiff:
14-
property_name: str
15-
val_existing: str
16-
val_declared: str
17-
18-
19-
class TransitionType(Enum):
20-
UNKNOWN = 0
21-
CREATE = 1
22-
DELETE = 2
23-
UPDATE = 3
24-
UNCHANGED = 4
25-
26-
2712
@dataclass
2813
class FcoDiff:
2914
name: str
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
from dataclasses import dataclass
2+
from typing import Any, List
3+
4+
from feast.diff.property_diff import PropertyDiff, TransitionType
5+
6+
7+
@dataclass
8+
class InfraObjectDiff:
9+
name: str
10+
infra_object_type: str
11+
current_fco: Any
12+
new_fco: Any
13+
fco_property_diffs: List[PropertyDiff]
14+
transition_type: TransitionType
15+
16+
17+
@dataclass
18+
class InfraDiff:
19+
infra_object_diffs: List[InfraObjectDiff]
20+
21+
def __init__(self):
22+
self.infra_object_diffs = []
23+
24+
def update(self):
25+
pass
26+
27+
def to_string(self):
28+
pass
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
from dataclasses import dataclass
2+
from enum import Enum
3+
4+
5+
@dataclass
6+
class PropertyDiff:
7+
property_name: str
8+
val_existing: str
9+
val_declared: str
10+
11+
12+
class TransitionType(Enum):
13+
UNKNOWN = 0
14+
CREATE = 1
15+
DELETE = 2
16+
UPDATE = 3
17+
UNCHANGED = 4

sdk/python/feast/registry.py

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@
4242
)
4343
from feast.feature_service import FeatureService
4444
from feast.feature_view import FeatureView
45+
from feast.infra.infra_object import Infra
4546
from feast.on_demand_feature_view import OnDemandFeatureView
4647
from feast.protos.feast.core.Registry_pb2 import Registry as RegistryProto
4748
from feast.registry_store import NoopRegistryStore
@@ -222,6 +223,36 @@ def _initialize_registry(self):
222223
registry_proto.registry_schema_version = REGISTRY_SCHEMA_VERSION
223224
self._registry_store.update_registry_proto(registry_proto)
224225

226+
def update_infra(self, infra: Infra, project: str, commit: bool = True):
227+
"""
228+
Updates the stored Infra object.
229+
230+
Args:
231+
infra: The new Infra object to be stored.
232+
project: Feast project that the Infra object refers to
233+
commit: Whether the change should be persisted immediately
234+
"""
235+
self._prepare_registry_for_changes()
236+
assert self.cached_registry_proto
237+
238+
self.cached_registry_proto.infra.CopyFrom(infra.to_proto())
239+
if commit:
240+
self.commit()
241+
242+
def get_infra(self, project: str, allow_cache: bool = False) -> Infra:
243+
"""
244+
Retrieves the stored Infra object.
245+
246+
Args:
247+
project: Feast project that the Infra object refers to
248+
allow_cache: Whether to allow returning this entity from a cached registry
249+
250+
Returns:
251+
The stored Infra object.
252+
"""
253+
registry_proto = self._get_registry_proto(allow_cache=allow_cache)
254+
return Infra.from_proto(registry_proto.infra)
255+
225256
def apply_entity(self, entity: Entity, project: str, commit: bool = True):
226257
"""
227258
Registers a single entity with Feast

0 commit comments

Comments
 (0)