Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: Deprecate value type #2611

Merged
merged 17 commits into from
May 4, 2022
Merged
Show file tree
Hide file tree
Changes from 9 commits
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
4 changes: 2 additions & 2 deletions examples/java-demo/feature_repo/driver_repo.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,14 @@
from google.protobuf.duration_pb2 import Duration
from feast.field import Field

from feast import Entity, Feature, BatchFeatureView, FileSource, ValueType
from feast import Entity, Feature, BatchFeatureView, FileSource

driver_hourly_stats = FileSource(
path="data/driver_stats_with_string.parquet",
timestamp_field="event_timestamp",
created_timestamp_column="created",
)
driver = Entity(name="driver_id", value_type=ValueType.INT64, description="driver id",)
driver = Entity(name="driver_id", description="driver id",)
driver_hourly_stats_view = BatchFeatureView(
name="driver_hourly_stats",
entities=["driver_id"],
Expand Down
4 changes: 2 additions & 2 deletions go/embedded/online_features.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ func (s *OnlineFeatureService) GetEntityTypesMap(featureRefs []string) (map[stri
}
for _, entityName := range view.Entities {
entity := entitiesByName[entityName]
joinKeyTypes[entity.JoinKey] = int32(entity.ValueType.Number())
joinKeyTypes[entity.JoinKey] = int32(view.GetEntityType(entity.JoinKey).Number())
}
}

Expand Down Expand Up @@ -117,7 +117,7 @@ func (s *OnlineFeatureService) GetEntityTypesMapByFeatureService(featureServiceN
}
for _, entityName := range view.Entities {
pyalex marked this conversation as resolved.
Show resolved Hide resolved
entity := entitiesByName[entityName]
joinKeyTypes[entity.JoinKey] = int32(entity.ValueType.Number())
joinKeyTypes[entity.JoinKey] = int32(view.GetEntityType(entity.JoinKey).Number())
}
}

Expand Down
2 changes: 1 addition & 1 deletion go/internal/feast/featurestore.go
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ func (fs *FeatureStore) GetOnlineFeatures(
if entitylessCase {
dummyEntityColumn := &prototypes.RepeatedValue{Val: make([]*prototypes.Value, numRows)}
for index := 0; index < numRows; index++ {
dummyEntityColumn.Val[index] = &model.DUMMY_ENTITY
dummyEntityColumn.Val[index] = &model.DUMMY_ENTITY_VALUE
}
joinKeyToEntityValues[model.DUMMY_ENTITY_ID] = dummyEntityColumn
}
Expand Down
12 changes: 5 additions & 7 deletions go/internal/feast/model/entity.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,16 @@ package model

import (
"github.com/feast-dev/feast/go/protos/feast/core"
"github.com/feast-dev/feast/go/protos/feast/types"
)

type Entity struct {
Name string
ValueType types.ValueType_Enum
JoinKey string
Name string
JoinKey string
}

func NewEntityFromProto(proto *core.Entity) *Entity {
return &Entity{Name: proto.Spec.Name,
ValueType: proto.Spec.ValueType,
JoinKey: proto.Spec.JoinKey,
return &Entity{
Name: proto.Spec.Name,
JoinKey: proto.Spec.JoinKey,
}
}
33 changes: 24 additions & 9 deletions go/internal/feast/model/featureview.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,13 @@ const (
DUMMY_ENTITY_VAL = ""
)

var DUMMY_ENTITY types.Value = types.Value{Val: &types.Value_StringVal{StringVal: DUMMY_ENTITY_VAL}}
var DUMMY_ENTITY_VALUE types.Value = types.Value{Val: &types.Value_StringVal{StringVal: DUMMY_ENTITY_VAL}}

type FeatureView struct {
Base *BaseFeatureView
Ttl *durationpb.Duration
Entities []string
Base *BaseFeatureView
Ttl *durationpb.Duration
Entities []string
pyalex marked this conversation as resolved.
Show resolved Hide resolved
EntityColumns []*Feature
pyalex marked this conversation as resolved.
Show resolved Hide resolved
}

func NewFeatureViewFromProto(proto *core.FeatureView) *FeatureView {
Expand All @@ -30,23 +31,37 @@ func NewFeatureViewFromProto(proto *core.FeatureView) *FeatureView {
} else {
featureView.Entities = proto.Spec.Entities
}
entityColumns := make([]*Feature, len(proto.Spec.EntityColumns))
for i, entityColumn := range proto.Spec.EntityColumns {
entityColumns[i] = NewFeatureFromProto(entityColumn)
}
featureView.EntityColumns = entityColumns
return featureView
}

func (fs *FeatureView) NewFeatureViewFromBase(base *BaseFeatureView) *FeatureView {
ttl := durationpb.Duration{Seconds: fs.Ttl.Seconds, Nanos: fs.Ttl.Nanos}
func (fv *FeatureView) NewFeatureViewFromBase(base *BaseFeatureView) *FeatureView {
ttl := durationpb.Duration{Seconds: fv.Ttl.Seconds, Nanos: fv.Ttl.Nanos}
featureView := &FeatureView{Base: base,
Ttl: &ttl,
Entities: fs.Entities,
Entities: fv.Entities,
}
return featureView
}

func (fs *FeatureView) HasEntity(lookup string) bool {
for _, entityName := range fs.Entities {
func (fv *FeatureView) HasEntity(lookup string) bool {
pyalex marked this conversation as resolved.
Show resolved Hide resolved
for _, entityName := range fv.Entities {
if entityName == lookup {
return true
}
}
return false
}

func (fv *FeatureView) GetEntityType(lookup string) types.ValueType_Enum {
pyalex marked this conversation as resolved.
Show resolved Hide resolved
for _, entityColumn := range fv.EntityColumns {
if entityColumn.Name == lookup {
return entityColumn.Dtype
}
}
return types.ValueType_INVALID
}
2 changes: 1 addition & 1 deletion go/internal/feast/server/logging/featureserviceschema.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ func generateSchema(featureService *model.FeatureService, entityMap map[string]*
}

joinKeysSet[joinKey] = nil
entityJoinKeyToType[joinKey] = entity.ValueType
entityJoinKeyToType[joinKey] = fv.GetEntityType(entity.JoinKey)
}
} else if odFv, ok := odFvMap[featureViewName]; ok {
for _, f := range featureProjection.Features {
Expand Down
10 changes: 7 additions & 3 deletions go/internal/feast/server/logging/featureserviceschema_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -145,8 +145,12 @@ func InitializeFeatureRepoVariablesForTest() (*model.FeatureService, []*model.En
[]*model.Feature{f1, f2},
projection1,
)
featureView1 := test.CreateFeatureView(baseFeatureView1, nil, []string{"driver_id"})
entity1 := test.CreateNewEntity("driver_id", types.ValueType_INT64, "driver_id")
entity1 := test.CreateNewEntity("driver_id", "driver_id")
entitycolumn1 := test.CreateNewFeature(
"driver_id",
types.ValueType_INT64,
)
featureView1 := test.CreateFeatureView(baseFeatureView1, nil, []string{"driver_id"}, []*model.Feature{entitycolumn1})
f3 := test.CreateNewFeature(
"int32",
types.ValueType_INT32,
Expand All @@ -166,7 +170,7 @@ func InitializeFeatureRepoVariablesForTest() (*model.FeatureService, []*model.En
[]*model.Feature{f3, f4},
projection2,
)
featureView2 := test.CreateFeatureView(baseFeatureView2, nil, []string{"driver_id"})
featureView2 := test.CreateFeatureView(baseFeatureView2, nil, []string{"driver_id"}, []*model.Feature{entitycolumn1})

f5 := test.CreateNewFeature(
"odfv_f1",
Expand Down
16 changes: 8 additions & 8 deletions go/internal/test/go_integration_test_utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -201,11 +201,10 @@ func CreateBaseFeatureView(name string, features []*model.Feature, projection *m
}
}

func CreateNewEntity(name string, valueType types.ValueType_Enum, joinKey string) *model.Entity {
func CreateNewEntity(name string, joinKey string) *model.Entity {
return &model.Entity{
Name: name,
ValueType: valueType,
JoinKey: joinKey,
Name: name,
JoinKey: joinKey,
}
}

Expand Down Expand Up @@ -233,10 +232,11 @@ func CreateNewFeatureViewProjection(name string, nameAlias string, features []*m
}
}

func CreateFeatureView(base *model.BaseFeatureView, ttl *durationpb.Duration, entities []string) *model.FeatureView {
func CreateFeatureView(base *model.BaseFeatureView, ttl *durationpb.Duration, entities []string, entityColumns []*model.Feature) *model.FeatureView {
return &model.FeatureView{
Base: base,
Ttl: ttl,
Entities: entities,
Base: base,
Ttl: ttl,
Entities: entities,
EntityColumns: entityColumns,
}
}
10 changes: 6 additions & 4 deletions protos/feast/core/FeatureView.proto
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ message FeatureView {
FeatureViewMeta meta = 2;
}

// Next available id: 12
// Next available id: 13
// TODO(adchia): refactor common fields from this and ODFV into separate metadata proto
message FeatureViewSpec {
// Name of the feature view. Must be unique. Not updated.
Expand All @@ -44,13 +44,15 @@ message FeatureViewSpec {
// Name of Feast project that this feature view belongs to.
string project = 2;

// List names of entities to associate with the Features defined in this
// Feature View. Not updatable.
// List of names of entities associated with this feature view.
repeated string entities = 3;

// List of specifications for each field defined as part of this feature view.
// List of specifications for each feature defined as part of this feature view.
repeated FeatureSpecV2 features = 4;

// List of specifications for each entity defined as part of this feature view.
repeated FeatureSpecV2 entity_columns = 12;

// Description of the feature view.
string description = 10;

Expand Down
30 changes: 24 additions & 6 deletions sdk/python/feast/entity.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ class Entity:

Attributes:
name: The unique name of the entity.
value_type: The type of the entity, such as string or float.
value_type (deprecated): The type of the entity, such as string or float.
join_key: A property that uniquely identifies different entities within the
collection. The join_key property is typically used for joining entities
with their associated features. If not specified, defaults to the name.
Expand Down Expand Up @@ -60,7 +60,7 @@ def __init__(
self,
*args,
name: Optional[str] = None,
value_type: ValueType = ValueType.UNKNOWN,
value_type: Optional[ValueType] = None,
description: str = "",
join_key: Optional[str] = None,
tags: Optional[Dict[str, str]] = None,
Expand All @@ -72,7 +72,7 @@ def __init__(

Args:
name: The unique name of the entity.
value_type: The type of the entity, such as string or float.
value_type (deprecated): The type of the entity, such as string or float.
description: A human-readable description.
join_key (deprecated): A property that uniquely identifies different entities within the
collection. The join_key property is typically used for joining entities
Expand Down Expand Up @@ -104,8 +104,23 @@ def __init__(
if not self.name:
raise ValueError("Name needs to be specified")

self.value_type = value_type
if value_type:
warnings.warn(
(
"The `value_type` parameter is being deprecated. Instead, the type of an entity "
"should be specified as a Field in the schema of a feature view. Feast 0.22 and "
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

0.23? since we may be releasing a new minor version soon.

"onwards will not support the `value_type` parameter. The `entities` parameter of "
"feature views should also be changed to a List[Entity] instead of a List[str]; if "
"this is not done, entity columns will be mistakenly interpreted as feature columns."
),
DeprecationWarning,
)
self.value_type = value_type or ValueType.UNKNOWN

# For now, both the `join_key` and `join_keys` attributes are set correctly,
# so both are usable.
# TODO(felixwang9817): Remove the usage of `join_key` throughout the codebase
# when the usage of `join_key` as a parameter is removed.
if join_key:
warnings.warn(
(
Expand All @@ -125,6 +140,8 @@ def __init__(
self.join_key = join_keys[0]
else:
self.join_key = join_key if join_key else self.name
if not self.join_keys:
self.join_keys = [self.join_key]
self.description = description
self.tags = tags if tags is not None else {}
self.owner = owner
Expand Down Expand Up @@ -153,6 +170,9 @@ def __eq__(self, other):
def __str__(self):
return str(MessageToJson(self.to_proto()))

def __lt__(self, other):
return self.name < other.name

def is_valid(self):
"""
Validates the state of this entity locally.
Expand All @@ -179,7 +199,6 @@ def from_proto(cls, entity_proto: EntityProto):
"""
entity = cls(
name=entity_proto.spec.name,
value_type=ValueType(entity_proto.spec.value_type),
join_key=entity_proto.spec.join_key,
description=entity_proto.spec.description,
tags=entity_proto.spec.tags,
Expand Down Expand Up @@ -210,7 +229,6 @@ def to_proto(self) -> EntityProto:

spec = EntitySpecProto(
name=self.name,
value_type=self.value_type.value,
pyalex marked this conversation as resolved.
Show resolved Hide resolved
join_key=self.join_key,
description=self.description,
tags=self.tags,
Expand Down
12 changes: 8 additions & 4 deletions sdk/python/feast/feature_logging.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
from feast.protos.feast.core.FeatureService_pb2 import (
LoggingConfig as LoggingConfigProto,
)
from feast.types import from_value_type

if TYPE_CHECKING:
from feast import FeatureService
Expand Down Expand Up @@ -87,9 +86,14 @@ def get_schema(self, registry: "Registry") -> pa.Schema:
join_key = projection.join_key_map.get(
entity.join_key, entity.join_key
)
fields[join_key] = FEAST_TYPE_TO_ARROW_TYPE[
from_value_type(entity.value_type)
]
entity_columns = list(
pyalex marked this conversation as resolved.
Show resolved Hide resolved
filter(
lambda x: x.name == join_key, feature_view.entity_columns
)
)
assert len(entity_columns) == 1
entity_column = entity_columns[0]
fields[join_key] = FEAST_TYPE_TO_ARROW_TYPE[entity_column.dtype]

# system columns
fields[REQUEST_ID_FIELD] = pa.string()
Expand Down
Loading