Skip to content

Commit 40962fc

Browse files
committed
fix: Update field api to add tag parameter corresponding to labels in Feature. (#2610)
* Fix tags Signed-off-by: Kevin Zhang <kzhang@tecton.ai> * Fix lint Signed-off-by: Kevin Zhang <kzhang@tecton.ai> * Fix lint Signed-off-by: Kevin Zhang <kzhang@tecton.ai> * Fix lint Signed-off-by: Kevin Zhang <kzhang@tecton.ai> * Convert field to use optional kw args Signed-off-by: Kevin Zhang <kzhang@tecton.ai> * fix Signed-off-by: Kevin Zhang <kzhang@tecton.ai> * Fix Signed-off-by: Kevin Zhang <kzhang@tecton.ai> * Fix Signed-off-by: Kevin Zhang <kzhang@tecton.ai> * Fix Signed-off-by: Kevin Zhang <kzhang@tecton.ai> * Fix Signed-off-by: Kevin Zhang <kzhang@tecton.ai> * Fix lint Signed-off-by: Kevin Zhang <kzhang@tecton.ai> * Fix java tests Signed-off-by: Kevin Zhang <kzhang@tecton.ai>
1 parent c391216 commit 40962fc

File tree

4 files changed

+34
-18
lines changed

4 files changed

+34
-18
lines changed

java/serving/src/test/java/feast/serving/util/DataGenerator.java

+8-8
Original file line numberDiff line numberDiff line change
@@ -126,11 +126,11 @@ public static EntityProto.EntitySpecV2 createEntitySpecV2(
126126
}
127127

128128
public static FeatureProto.FeatureSpecV2 createFeatureSpecV2(
129-
String name, ValueProto.ValueType.Enum valueType, Map<String, String> labels) {
129+
String name, ValueProto.ValueType.Enum valueType, Map<String, String> tags) {
130130
return FeatureProto.FeatureSpecV2.newBuilder()
131131
.setName(name)
132132
.setValueType(valueType)
133-
.putAllLabels(labels)
133+
.putAllTags(tags)
134134
.build();
135135
}
136136

@@ -140,7 +140,7 @@ public static FeatureTableSpec createFeatureTableSpec(
140140
List<String> entities,
141141
Map<String, ValueProto.ValueType.Enum> features,
142142
int maxAgeSecs,
143-
Map<String, String> labels) {
143+
Map<String, String> tags) {
144144

145145
return FeatureTableSpec.newBuilder()
146146
.setName(name)
@@ -152,7 +152,7 @@ public static FeatureTableSpec createFeatureTableSpec(
152152
FeatureSpecV2.newBuilder()
153153
.setName(entry.getKey())
154154
.setValueType(entry.getValue())
155-
.putAllLabels(labels)
155+
.putAllTags(tags)
156156
.build())
157157
.collect(Collectors.toList()))
158158
.setMaxAge(Duration.newBuilder().setSeconds(3600).build())
@@ -169,7 +169,7 @@ public static FeatureTableSpec createFeatureTableSpec(
169169
.setUri("/dev/null")
170170
.build())
171171
.build())
172-
.putAllLabels(labels)
172+
.putAllLabels(tags)
173173
.build();
174174
}
175175

@@ -178,7 +178,7 @@ public static FeatureTableSpec createFeatureTableSpec(
178178
List<String> entities,
179179
ImmutableMap<String, ValueProto.ValueType.Enum> features,
180180
int maxAgeSecs,
181-
Map<String, String> labels) {
181+
Map<String, String> tags) {
182182

183183
return FeatureTableSpec.newBuilder()
184184
.setName(name)
@@ -190,11 +190,11 @@ public static FeatureTableSpec createFeatureTableSpec(
190190
FeatureSpecV2.newBuilder()
191191
.setName(entry.getKey())
192192
.setValueType(entry.getValue())
193-
.putAllLabels(labels)
193+
.putAllTags(tags)
194194
.build())
195195
.collect(Collectors.toList()))
196196
.setMaxAge(Duration.newBuilder().setSeconds(maxAgeSecs).build())
197-
.putAllLabels(labels)
197+
.putAllLabels(tags)
198198
.build();
199199
}
200200

protos/feast/core/Feature.proto

+2-2
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,6 @@ message FeatureSpecV2 {
3131
// Value type of the feature. Not updatable.
3232
feast.types.ValueType.Enum value_type = 2;
3333

34-
// Labels for user defined metadata on a feature
35-
map<string,string> labels = 3;
34+
// Tags for user defined metadata on a feature
35+
map<string,string> tags = 3;
3636
}

sdk/python/feast/feature.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ def to_proto(self) -> FeatureSpecProto:
9191
value_type = ValueTypeProto.Enum.Value(self.dtype.name)
9292

9393
return FeatureSpecProto(
94-
name=self.name, value_type=value_type, labels=self.labels,
94+
name=self.name, value_type=value_type, tags=self.labels,
9595
)
9696

9797
@classmethod
@@ -106,7 +106,7 @@ def from_proto(cls, feature_proto: FeatureSpecProto):
106106
feature = cls(
107107
name=feature_proto.name,
108108
dtype=ValueType(feature_proto.value_type),
109-
labels=dict(feature_proto.labels),
109+
labels=dict(feature_proto.tags),
110110
)
111111

112112
return feature

sdk/python/feast/field.py

+22-6
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@
1212
# See the License for the specific language governing permissions and
1313
# limitations under the License.
1414

15+
from typing import Dict, Optional
16+
1517
from feast.feature import Feature
1618
from feast.protos.feast.core.Feature_pb2 import FeatureSpecV2 as FieldProto
1719
from feast.types import FeastType, from_value_type
@@ -25,26 +27,34 @@ class Field:
2527
Attributes:
2628
name: The name of the field.
2729
dtype: The type of the field, such as string or float.
30+
tags: User-defined metadata in dictionary form.
2831
"""
2932

3033
name: str
3134
dtype: FeastType
35+
tags: Dict[str, str]
3236

3337
def __init__(
34-
self, *, name: str, dtype: FeastType,
38+
self, *, name: str, dtype: FeastType, tags: Optional[Dict[str, str]] = None,
3539
):
3640
"""
3741
Creates a Field object.
3842
3943
Args:
4044
name: The name of the field.
4145
dtype: The type of the field, such as string or float.
46+
tags (optional): User-defined metadata in dictionary form.
4247
"""
4348
self.name = name
4449
self.dtype = dtype
50+
self.tags = tags or {}
4551

4652
def __eq__(self, other):
47-
if self.name != other.name or self.dtype != other.dtype:
53+
if (
54+
self.name != other.name
55+
or self.dtype != other.dtype
56+
or self.tags != other.tags
57+
):
4858
return False
4959
return True
5060

@@ -58,12 +68,12 @@ def __repr__(self):
5868
return f"{self.name}-{self.dtype}"
5969

6070
def __str__(self):
61-
return f"Field(name={self.name}, dtype={self.dtype})"
71+
return f"Field(name={self.name}, dtype={self.dtype}, tags={self.tags})"
6272

6373
def to_proto(self) -> FieldProto:
6474
"""Converts a Field object to its protobuf representation."""
6575
value_type = self.dtype.to_value_type()
66-
return FieldProto(name=self.name, value_type=value_type.value)
76+
return FieldProto(name=self.name, value_type=value_type.value, tags=self.tags)
6777

6878
@classmethod
6979
def from_proto(cls, field_proto: FieldProto):
@@ -74,7 +84,11 @@ def from_proto(cls, field_proto: FieldProto):
7484
field_proto: FieldProto protobuf object
7585
"""
7686
value_type = ValueType(field_proto.value_type)
77-
return cls(name=field_proto.name, dtype=from_value_type(value_type=value_type))
87+
return cls(
88+
name=field_proto.name,
89+
dtype=from_value_type(value_type=value_type),
90+
tags=dict(field_proto.tags),
91+
)
7892

7993
@classmethod
8094
def from_feature(cls, feature: Feature):
@@ -84,4 +98,6 @@ def from_feature(cls, feature: Feature):
8498
Args:
8599
feature: Feature object to convert.
86100
"""
87-
return cls(name=feature.name, dtype=from_value_type(feature.dtype))
101+
return cls(
102+
name=feature.name, dtype=from_value_type(feature.dtype), tags=feature.labels
103+
)

0 commit comments

Comments
 (0)