Skip to content

Commit ec9c4fd

Browse files
jklegarwoop
andauthored
Add entity join key and fix entity references (feast-dev#1429)
* Add entity join key Signed-off-by: Jacob Klegar <jacob@tecton.ai> * Fix test Signed-off-by: Jacob Klegar <jacob@tecton.ai> * Fix more tests Signed-off-by: Jacob Klegar <jacob@tecton.ai> * Simplify online retrieval code Signed-off-by: Willem Pienaar <git@willem.co> * Fix linting Signed-off-by: Willem Pienaar <git@willem.co> Co-authored-by: Willem Pienaar <git@willem.co>
1 parent f371c2d commit ec9c4fd

File tree

14 files changed

+326
-256
lines changed

14 files changed

+326
-256
lines changed

protos/feast/core/Entity.proto

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,9 @@ message EntitySpecV2 {
4444
// Description of the entity.
4545
string description = 3;
4646

47+
// Join key for the entity (i.e. name of the column the entity maps to).
48+
string join_key = 4;
49+
4750
// User defined metadata
4851
map<string,string> labels = 8;
4952
}

protos/feast/types/EntityKey.proto

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,6 @@ option java_outer_classname = "EntityKeyProto";
2525
option go_package = "github.com/feast-dev/feast/sdk/go/protos/feast/types";
2626

2727
message EntityKey {
28-
repeated string entity_names = 1;
28+
repeated string join_keys = 1;
2929
repeated feast.types.Value entity_values = 2;
3030
}

sdk/python/feast/entity.py

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,11 +36,17 @@ def __init__(
3636
name: str,
3737
value_type: ValueType,
3838
description: str = "",
39+
join_key: Optional[str] = None,
3940
labels: Optional[MutableMapping[str, str]] = None,
4041
):
4142
self._name = name
4243
self._description = description
4344
self._value_type = value_type
45+
if join_key:
46+
self._join_key = join_key
47+
else:
48+
self._join_key = name
49+
4450
if labels is None:
4551
self._labels = dict() # type: MutableMapping[str, str]
4652
else:
@@ -58,6 +64,7 @@ def __eq__(self, other):
5864
or self.name != other.name
5965
or self.description != other.description
6066
or self.value_type != other.value_type
67+
or self.join_key != other.join_key
6168
):
6269
return False
6370

@@ -94,6 +101,20 @@ def description(self, description):
94101
"""
95102
self._description = description
96103

104+
@property
105+
def join_key(self):
106+
"""
107+
Returns the join key of this entity
108+
"""
109+
return self._join_key
110+
111+
@join_key.setter
112+
def join_key(self, join_key):
113+
"""
114+
Sets the join key of this entity
115+
"""
116+
self._join_key = join_key
117+
97118
@property
98119
def value_type(self) -> ValueType:
99120
"""
@@ -197,6 +218,7 @@ def from_proto(cls, entity_proto: EntityV2Proto):
197218
description=entity_proto.spec.description,
198219
value_type=ValueType(entity_proto.spec.value_type),
199220
labels=entity_proto.spec.labels,
221+
join_key=entity_proto.spec.join_key,
200222
)
201223

202224
entity._created_timestamp = entity_proto.meta.created_timestamp
@@ -222,6 +244,7 @@ def to_proto(self) -> EntityV2Proto:
222244
description=self.description,
223245
value_type=self.value_type.value,
224246
labels=self.labels,
247+
join_key=self.join_key,
225248
)
226249

227250
return EntityV2Proto(spec=spec, meta=meta)
@@ -266,6 +289,7 @@ def to_spec_proto(self) -> EntitySpecProto:
266289
description=self.description,
267290
value_type=self.value_type.value,
268291
labels=self.labels,
292+
join_key=self.join_key,
269293
)
270294

271295
return spec
@@ -282,5 +306,6 @@ def _update_from_entity(self, entity):
282306
self.description = entity.description
283307
self.value_type = entity.value_type
284308
self.labels = entity.labels
309+
self.join_key = entity.join_key
285310
self._created_timestamp = entity.created_timestamp
286311
self._last_updated_timestamp = entity.last_updated_timestamp

0 commit comments

Comments
 (0)