Skip to content

Commit

Permalink
chore: Deprecate value type (#2611)
Browse files Browse the repository at this point in the history
* Switch `entities` from List[str] to List[Entity]

Signed-off-by: Felix Wang <wangfelix98@gmail.com>

* Remove `value_type` from SDK

Signed-off-by: Felix Wang <wangfelix98@gmail.com>

* Remove `value_type` from tests

Signed-off-by: Felix Wang <wangfelix98@gmail.com>

* Deprecate `value_type` parameter for Entity

Signed-off-by: Felix Wang <wangfelix98@gmail.com>

* Add fields for entities to avoid type inference after removing `value_type`

Signed-off-by: Felix Wang <wangfelix98@gmail.com>

* Fix Go

Signed-off-by: Felix Wang <wangfelix98@gmail.com>

* Fix type inference

Signed-off-by: Felix Wang <wangfelix98@gmail.com>

* Another fix

Signed-off-by: Felix Wang <wangfelix98@gmail.com>

* Another fix

Signed-off-by: Felix Wang <wangfelix98@gmail.com>

* Rename Entities to EntityNames in go

Signed-off-by: Felix Wang <wangfelix98@gmail.com>

* Rename lookup

Signed-off-by: Felix Wang <wangfelix98@gmail.com>

* Rename Feature to Field

Signed-off-by: Felix Wang <wangfelix98@gmail.com>

* Clean up inference

Signed-off-by: Felix Wang <wangfelix98@gmail.com>

* Refactor

Signed-off-by: Felix Wang <wangfelix98@gmail.com>

* Use old `value_type` attribute if it still exists

Signed-off-by: Felix Wang <wangfelix98@gmail.com>

* Refactor

Signed-off-by: Felix Wang <wangfelix98@gmail.com>

* Add TODO

Signed-off-by: Felix Wang <wangfelix98@gmail.com>
  • Loading branch information
felixwang9817 authored May 4, 2022
1 parent cef4d3c commit 737c488
Show file tree
Hide file tree
Showing 55 changed files with 583 additions and 540 deletions.
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
22 changes: 4 additions & 18 deletions go/embedded/online_features.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,12 +80,6 @@ func (s *OnlineFeatureService) GetEntityTypesMap(featureRefs []string) (map[stri
viewNames[viewName] = nil
}

entities, _ := s.fs.ListEntities(true)
entitiesByName := make(map[string]*model.Entity)
for _, entity := range entities {
entitiesByName[entity.Name] = entity
}

joinKeyTypes := make(map[string]int32)

for viewName := range viewNames {
Expand All @@ -94,9 +88,8 @@ func (s *OnlineFeatureService) GetEntityTypesMap(featureRefs []string) (map[stri
// skip on demand feature views
continue
}
for _, entityName := range view.Entities {
entity := entitiesByName[entityName]
joinKeyTypes[entity.JoinKey] = int32(entity.ValueType.Number())
for _, entityColumn := range view.EntityColumns {
joinKeyTypes[entityColumn.Name] = int32(entityColumn.Dtype.Number())
}
}

Expand All @@ -111,21 +104,14 @@ func (s *OnlineFeatureService) GetEntityTypesMapByFeatureService(featureServiceN

joinKeyTypes := make(map[string]int32)

entities, _ := s.fs.ListEntities(true)
entitiesByName := make(map[string]*model.Entity)
for _, entity := range entities {
entitiesByName[entity.Name] = entity
}

for _, projection := range featureService.Projections {
view, err := s.fs.GetFeatureView(projection.Name, true)
if err != nil {
// skip on demand feature views
continue
}
for _, entityName := range view.Entities {
entity := entitiesByName[entityName]
joinKeyTypes[entity.JoinKey] = int32(entity.ValueType.Number())
for _, entityColumn := range view.EntityColumns {
joinKeyTypes[entityColumn.Name] = int32(entityColumn.Dtype.Number())
}
}

Expand Down
4 changes: 2 additions & 2 deletions 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 Expand Up @@ -272,7 +272,7 @@ func (fs *FeatureStore) GetFeatureView(featureViewName string, hideDummyEntity b
return nil, err
}
if fv.HasEntity(model.DUMMY_ENTITY_NAME) && hideDummyEntity {
fv.Entities = []string{}
fv.EntityNames = []string{}
}
return fv, nil
}
Expand Down
8 changes: 4 additions & 4 deletions go/internal/feast/model/basefeatureview.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,15 @@ import (

type BaseFeatureView struct {
Name string
Features []*Feature
Features []*Field
Projection *FeatureViewProjection
}

func NewBaseFeatureView(name string, featureProtos []*core.FeatureSpecV2) *BaseFeatureView {
base := &BaseFeatureView{Name: name}
features := make([]*Feature, len(featureProtos))
features := make([]*Field, len(featureProtos))
for index, featureSpecV2 := range featureProtos {
features[index] = NewFeatureFromProto(featureSpecV2)
features[index] = NewFieldFromProto(featureSpecV2)
}
base.Features = features
base.Projection = NewFeatureViewProjectionFromDefinition(base)
Expand All @@ -43,7 +43,7 @@ func (fv *BaseFeatureView) WithProjection(projection *FeatureViewProjection) (*B
}

func (fv *BaseFeatureView) ProjectWithFeatures(featureNames []string) *FeatureViewProjection {
features := make([]*Feature, 0)
features := make([]*Field, 0)
for _, feature := range fv.Features {
for _, allowedFeatureName := range featureNames {
if feature.Name == allowedFeatureName {
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,
}
}
32 changes: 19 additions & 13 deletions go/internal/feast/model/featureview.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,38 +13,44 @@ 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
EntityNames []string
EntityColumns []*Field
}

func NewFeatureViewFromProto(proto *core.FeatureView) *FeatureView {
featureView := &FeatureView{Base: NewBaseFeatureView(proto.Spec.Name, proto.Spec.Features),
Ttl: &(*proto.Spec.Ttl),
}
if len(proto.Spec.Entities) == 0 {
featureView.Entities = []string{DUMMY_ENTITY_NAME}
featureView.EntityNames = []string{DUMMY_ENTITY_NAME}
} else {
featureView.Entities = proto.Spec.Entities
featureView.EntityNames = proto.Spec.Entities
}
entityColumns := make([]*Field, len(proto.Spec.EntityColumns))
for i, entityColumn := range proto.Spec.EntityColumns {
entityColumns[i] = NewFieldFromProto(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,
Ttl: &ttl,
EntityNames: fv.EntityNames,
}
return featureView
}

func (fs *FeatureView) HasEntity(lookup string) bool {
for _, entityName := range fs.Entities {
if entityName == lookup {
func (fv *FeatureView) HasEntity(name string) bool {
for _, entityName := range fv.EntityNames {
if entityName == name {
return true
}
}
Expand Down
6 changes: 3 additions & 3 deletions go/internal/feast/model/featureviewprojection.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (
type FeatureViewProjection struct {
Name string
NameAlias string
Features []*Feature
Features []*Field
JoinKeyMap map[string]string
}

Expand All @@ -24,9 +24,9 @@ func NewFeatureViewProjectionFromProto(proto *core.FeatureViewProjection) *Featu
JoinKeyMap: proto.JoinKeyMap,
}

features := make([]*Feature, len(proto.FeatureColumns))
features := make([]*Field, len(proto.FeatureColumns))
for index, featureSpecV2 := range proto.FeatureColumns {
features[index] = NewFeatureFromProto(featureSpecV2)
features[index] = NewFieldFromProto(featureSpecV2)
}
featureProjection.Features = features
return featureProjection
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,14 @@ import (
"github.com/feast-dev/feast/go/protos/feast/types"
)

type Feature struct {
type Field struct {
Name string
Dtype types.ValueType_Enum
}

func NewFeatureFromProto(proto *core.FeatureSpecV2) *Feature {
return &Feature{Name: proto.Name,
func NewFieldFromProto(proto *core.FeatureSpecV2) *Field {
return &Field{
Name: proto.Name,
Dtype: proto.ValueType,
}
}
4 changes: 2 additions & 2 deletions go/internal/feast/onlineserving/serving.go
Original file line number Diff line number Diff line change
Expand Up @@ -251,7 +251,7 @@ func GetEntityMaps(requestedFeatureViews []*FeatureViewAndRefs, entities []*mode
joinKeyToAliasMap = map[string]string{}
}

for _, entityName := range featureView.Entities {
for _, entityName := range featureView.EntityNames {
joinKey := entitiesByName[entityName].JoinKey
entityNameToJoinKeyMap[entityName] = joinKey

Expand Down Expand Up @@ -518,7 +518,7 @@ func GroupFeatureRefs(requestedFeatureViews []*FeatureViewAndRefs,
joinKeys := make([]string, 0)
fv := featuresAndView.View
featureNames := featuresAndView.FeatureRefs
for _, entityName := range fv.Entities {
for _, entityName := range fv.EntityNames {
joinKeys = append(joinKeys, entityNameToJoinKeyMap[entityName])
}

Expand Down
22 changes: 11 additions & 11 deletions go/internal/feast/onlineserving/serving_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,19 +20,19 @@ func TestGroupingFeatureRefs(t *testing.T) {
NameAlias: "aliasViewA",
},
},
Entities: []string{"driver", "customer"},
EntityNames: []string{"driver", "customer"},
}
viewB := &model.FeatureView{
Base: &model.BaseFeatureView{Name: "viewB"},
Entities: []string{"driver", "customer"},
Base: &model.BaseFeatureView{Name: "viewB"},
EntityNames: []string{"driver", "customer"},
}
viewC := &model.FeatureView{
Base: &model.BaseFeatureView{Name: "viewC"},
Entities: []string{"driver"},
Base: &model.BaseFeatureView{Name: "viewC"},
EntityNames: []string{"driver"},
}
viewD := &model.FeatureView{
Base: &model.BaseFeatureView{Name: "viewD"},
Entities: []string{"customer"},
Base: &model.BaseFeatureView{Name: "viewD"},
EntityNames: []string{"customer"},
}
refGroups, _ := GroupFeatureRefs(
[]*FeatureViewAndRefs{
Expand Down Expand Up @@ -105,11 +105,11 @@ func TestGroupingFeatureRefsWithJoinKeyAliases(t *testing.T) {
JoinKeyMap: map[string]string{"location_id": "destination_id"},
},
},
Entities: []string{"location"},
EntityNames: []string{"location"},
}
viewB := &model.FeatureView{
Base: &model.BaseFeatureView{Name: "viewB"},
Entities: []string{"location"},
Base: &model.BaseFeatureView{Name: "viewB"},
EntityNames: []string{"location"},
}

refGroups, _ := GroupFeatureRefs(
Expand Down Expand Up @@ -164,7 +164,7 @@ func TestGroupingFeatureRefsWithMissingKey(t *testing.T) {
JoinKeyMap: map[string]string{"location_id": "destination_id"},
},
},
Entities: []string{"location"},
EntityNames: []string{"location"},
}

_, err := GroupFeatureRefs(
Expand Down
9 changes: 4 additions & 5 deletions go/internal/feast/server/logging/featureserviceschema.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,21 +52,20 @@ func generateSchema(featureService *model.FeatureService, entityMap map[string]*
features = append(features, fullFeatureName)
allFeatureTypes[fullFeatureName] = f.Dtype
}
for _, entityName := range fv.Entities {
entity := entityMap[entityName]
for _, entityColumn := range fv.EntityColumns {
var joinKey string
if joinKeyAlias, ok := featureProjection.JoinKeyMap[entity.JoinKey]; ok {
if joinKeyAlias, ok := featureProjection.JoinKeyMap[entityColumn.Name]; ok {
joinKey = joinKeyAlias
} else {
joinKey = entity.JoinKey
joinKey = entityColumn.Name
}

if _, ok := joinKeysSet[joinKey]; !ok {
joinKeys = append(joinKeys, joinKey)
}

joinKeysSet[joinKey] = nil
entityJoinKeyToType[joinKey] = entity.ValueType
entityJoinKeyToType[joinKey] = entityColumn.Dtype
}
} else if odFv, ok := odFvMap[featureViewName]; ok {
for _, f := range featureProjection.Features {
Expand Down
Loading

0 comments on commit 737c488

Please sign in to comment.