Skip to content

Commit

Permalink
fix: Update field api to add tag parameter corresponding to labels in…
Browse files Browse the repository at this point in the history
… 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>
  • Loading branch information
kevjumba committed Apr 28, 2022
1 parent c391216 commit 40962fc
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 18 deletions.
16 changes: 8 additions & 8 deletions java/serving/src/test/java/feast/serving/util/DataGenerator.java
Expand Up @@ -126,11 +126,11 @@ public static EntityProto.EntitySpecV2 createEntitySpecV2(
}

public static FeatureProto.FeatureSpecV2 createFeatureSpecV2(
String name, ValueProto.ValueType.Enum valueType, Map<String, String> labels) {
String name, ValueProto.ValueType.Enum valueType, Map<String, String> tags) {
return FeatureProto.FeatureSpecV2.newBuilder()
.setName(name)
.setValueType(valueType)
.putAllLabels(labels)
.putAllTags(tags)
.build();
}

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

return FeatureTableSpec.newBuilder()
.setName(name)
Expand All @@ -152,7 +152,7 @@ public static FeatureTableSpec createFeatureTableSpec(
FeatureSpecV2.newBuilder()
.setName(entry.getKey())
.setValueType(entry.getValue())
.putAllLabels(labels)
.putAllTags(tags)
.build())
.collect(Collectors.toList()))
.setMaxAge(Duration.newBuilder().setSeconds(3600).build())
Expand All @@ -169,7 +169,7 @@ public static FeatureTableSpec createFeatureTableSpec(
.setUri("/dev/null")
.build())
.build())
.putAllLabels(labels)
.putAllLabels(tags)
.build();
}

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

return FeatureTableSpec.newBuilder()
.setName(name)
Expand All @@ -190,11 +190,11 @@ public static FeatureTableSpec createFeatureTableSpec(
FeatureSpecV2.newBuilder()
.setName(entry.getKey())
.setValueType(entry.getValue())
.putAllLabels(labels)
.putAllTags(tags)
.build())
.collect(Collectors.toList()))
.setMaxAge(Duration.newBuilder().setSeconds(maxAgeSecs).build())
.putAllLabels(labels)
.putAllLabels(tags)
.build();
}

Expand Down
4 changes: 2 additions & 2 deletions protos/feast/core/Feature.proto
Expand Up @@ -31,6 +31,6 @@ message FeatureSpecV2 {
// Value type of the feature. Not updatable.
feast.types.ValueType.Enum value_type = 2;

// Labels for user defined metadata on a feature
map<string,string> labels = 3;
// Tags for user defined metadata on a feature
map<string,string> tags = 3;
}
4 changes: 2 additions & 2 deletions sdk/python/feast/feature.py
Expand Up @@ -91,7 +91,7 @@ def to_proto(self) -> FeatureSpecProto:
value_type = ValueTypeProto.Enum.Value(self.dtype.name)

return FeatureSpecProto(
name=self.name, value_type=value_type, labels=self.labels,
name=self.name, value_type=value_type, tags=self.labels,
)

@classmethod
Expand All @@ -106,7 +106,7 @@ def from_proto(cls, feature_proto: FeatureSpecProto):
feature = cls(
name=feature_proto.name,
dtype=ValueType(feature_proto.value_type),
labels=dict(feature_proto.labels),
labels=dict(feature_proto.tags),
)

return feature
28 changes: 22 additions & 6 deletions sdk/python/feast/field.py
Expand Up @@ -12,6 +12,8 @@
# See the License for the specific language governing permissions and
# limitations under the License.

from typing import Dict, Optional

from feast.feature import Feature
from feast.protos.feast.core.Feature_pb2 import FeatureSpecV2 as FieldProto
from feast.types import FeastType, from_value_type
Expand All @@ -25,26 +27,34 @@ class Field:
Attributes:
name: The name of the field.
dtype: The type of the field, such as string or float.
tags: User-defined metadata in dictionary form.
"""

name: str
dtype: FeastType
tags: Dict[str, str]

def __init__(
self, *, name: str, dtype: FeastType,
self, *, name: str, dtype: FeastType, tags: Optional[Dict[str, str]] = None,
):
"""
Creates a Field object.
Args:
name: The name of the field.
dtype: The type of the field, such as string or float.
tags (optional): User-defined metadata in dictionary form.
"""
self.name = name
self.dtype = dtype
self.tags = tags or {}

def __eq__(self, other):
if self.name != other.name or self.dtype != other.dtype:
if (
self.name != other.name
or self.dtype != other.dtype
or self.tags != other.tags
):
return False
return True

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

def __str__(self):
return f"Field(name={self.name}, dtype={self.dtype})"
return f"Field(name={self.name}, dtype={self.dtype}, tags={self.tags})"

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

@classmethod
def from_proto(cls, field_proto: FieldProto):
Expand All @@ -74,7 +84,11 @@ def from_proto(cls, field_proto: FieldProto):
field_proto: FieldProto protobuf object
"""
value_type = ValueType(field_proto.value_type)
return cls(name=field_proto.name, dtype=from_value_type(value_type=value_type))
return cls(
name=field_proto.name,
dtype=from_value_type(value_type=value_type),
tags=dict(field_proto.tags),
)

@classmethod
def from_feature(cls, feature: Feature):
Expand All @@ -84,4 +98,6 @@ def from_feature(cls, feature: Feature):
Args:
feature: Feature object to convert.
"""
return cls(name=feature.name, dtype=from_value_type(feature.dtype))
return cls(
name=feature.name, dtype=from_value_type(feature.dtype), tags=feature.labels
)

0 comments on commit 40962fc

Please sign in to comment.