Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Next Next commit
Fix tags
Signed-off-by: Kevin Zhang <kzhang@tecton.ai>
  • Loading branch information
kevjumba committed Apr 25, 2022
commit 8e10875eab0bbfa47d09ca807c13cbfa42f7e10a
3 changes: 3 additions & 0 deletions protos/feast/types/Field.proto
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,7 @@ option go_package = "github.com/feast-dev/feast/go/protos/feast/types";
message Field {
string name = 1;
feast.types.ValueType.Enum value = 2;

// User defined metadata
map<string,string> tags = 3;
Comment thread
felixwang9817 marked this conversation as resolved.
Outdated
}
22 changes: 15 additions & 7 deletions sdk/python/feast/field.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@
# See the License for the specific language governing permissions and
# limitations under the License.

from typing import Dict, Optional

from attr import field

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,31 +29,35 @@ 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

def __hash__(self):
return hash((self.name, hash(self.dtype)))
return hash((self.name, hash(self.dtype), hash(self.tags)))
Comment thread
felixwang9817 marked this conversation as resolved.
Outdated

def __lt__(self, other):
return self.name < other.name
Expand All @@ -58,12 +66,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 +82,7 @@ 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=field_proto.tags)

@classmethod
def from_feature(cls, feature: Feature):
Expand All @@ -84,4 +92,4 @@ 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)