Skip to content

Commit

Permalink
Revert "chore: Deprecate value type (feast-dev#2611)"
Browse files Browse the repository at this point in the history
This reverts commit 737c488.

Signed-off-by: Achal Shah <[email protected]>
  • Loading branch information
achals committed May 5, 2022
1 parent f22430a commit 98249ac
Show file tree
Hide file tree
Showing 55 changed files with 540 additions and 583 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
from feast import Entity, Feature, BatchFeatureView, FileSource, ValueType

driver_hourly_stats = FileSource(
path="data/driver_stats_with_string.parquet",
timestamp_field="event_timestamp",
created_timestamp_column="created",
)
driver = Entity(name="driver_id", description="driver id",)
driver = Entity(name="driver_id", value_type=ValueType.INT64, description="driver id",)
driver_hourly_stats_view = BatchFeatureView(
name="driver_hourly_stats",
entities=["driver_id"],
Expand Down
22 changes: 18 additions & 4 deletions go/embedded/online_features.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,12 @@ 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 @@ -88,8 +94,9 @@ func (s *OnlineFeatureService) GetEntityTypesMap(featureRefs []string) (map[stri
// skip on demand feature views
continue
}
for _, entityColumn := range view.EntityColumns {
joinKeyTypes[entityColumn.Name] = int32(entityColumn.Dtype.Number())
for _, entityName := range view.Entities {
entity := entitiesByName[entityName]
joinKeyTypes[entity.JoinKey] = int32(entity.ValueType.Number())
}
}

Expand All @@ -104,14 +111,21 @@ 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 _, entityColumn := range view.EntityColumns {
joinKeyTypes[entityColumn.Name] = int32(entityColumn.Dtype.Number())
for _, entityName := range view.Entities {
entity := entitiesByName[entityName]
joinKeyTypes[entity.JoinKey] = int32(entity.ValueType.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_VALUE
dummyEntityColumn.Val[index] = &model.DUMMY_ENTITY
}
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.EntityNames = []string{}
fv.Entities = []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 []*Field
Features []*Feature
Projection *FeatureViewProjection
}

func NewBaseFeatureView(name string, featureProtos []*core.FeatureSpecV2) *BaseFeatureView {
base := &BaseFeatureView{Name: name}
features := make([]*Field, len(featureProtos))
features := make([]*Feature, len(featureProtos))
for index, featureSpecV2 := range featureProtos {
features[index] = NewFieldFromProto(featureSpecV2)
features[index] = NewFeatureFromProto(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([]*Field, 0)
features := make([]*Feature, 0)
for _, feature := range fv.Features {
for _, allowedFeatureName := range featureNames {
if feature.Name == allowedFeatureName {
Expand Down
12 changes: 7 additions & 5 deletions go/internal/feast/model/entity.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,18 @@ 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
JoinKey string
Name string
ValueType types.ValueType_Enum
JoinKey string
}

func NewEntityFromProto(proto *core.Entity) *Entity {
return &Entity{
Name: proto.Spec.Name,
JoinKey: proto.Spec.JoinKey,
return &Entity{Name: proto.Spec.Name,
ValueType: proto.Spec.ValueType,
JoinKey: proto.Spec.JoinKey,
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,13 @@ import (
"github.com/feast-dev/feast/go/protos/feast/types"
)

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

func NewFieldFromProto(proto *core.FeatureSpecV2) *Field {
return &Field{
Name: proto.Name,
func NewFeatureFromProto(proto *core.FeatureSpecV2) *Feature {
return &Feature{Name: proto.Name,
Dtype: proto.ValueType,
}
}
32 changes: 13 additions & 19 deletions go/internal/feast/model/featureview.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,44 +13,38 @@ const (
DUMMY_ENTITY_VAL = ""
)

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

type FeatureView struct {
Base *BaseFeatureView
Ttl *durationpb.Duration
EntityNames []string
EntityColumns []*Field
Base *BaseFeatureView
Ttl *durationpb.Duration
Entities []string
}

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.EntityNames = []string{DUMMY_ENTITY_NAME}
featureView.Entities = []string{DUMMY_ENTITY_NAME}
} else {
featureView.EntityNames = proto.Spec.Entities
featureView.Entities = 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 (fv *FeatureView) NewFeatureViewFromBase(base *BaseFeatureView) *FeatureView {
ttl := durationpb.Duration{Seconds: fv.Ttl.Seconds, Nanos: fv.Ttl.Nanos}
func (fs *FeatureView) NewFeatureViewFromBase(base *BaseFeatureView) *FeatureView {
ttl := durationpb.Duration{Seconds: fs.Ttl.Seconds, Nanos: fs.Ttl.Nanos}
featureView := &FeatureView{Base: base,
Ttl: &ttl,
EntityNames: fv.EntityNames,
Ttl: &ttl,
Entities: fs.Entities,
}
return featureView
}

func (fv *FeatureView) HasEntity(name string) bool {
for _, entityName := range fv.EntityNames {
if entityName == name {
func (fs *FeatureView) HasEntity(lookup string) bool {
for _, entityName := range fs.Entities {
if entityName == lookup {
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 []*Field
Features []*Feature
JoinKeyMap map[string]string
}

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

features := make([]*Field, len(proto.FeatureColumns))
features := make([]*Feature, len(proto.FeatureColumns))
for index, featureSpecV2 := range proto.FeatureColumns {
features[index] = NewFieldFromProto(featureSpecV2)
features[index] = NewFeatureFromProto(featureSpecV2)
}
featureProjection.Features = features
return featureProjection
Expand Down
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.EntityNames {
for _, entityName := range featureView.Entities {
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.EntityNames {
for _, entityName := range fv.Entities {
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",
},
},
EntityNames: []string{"driver", "customer"},
Entities: []string{"driver", "customer"},
}
viewB := &model.FeatureView{
Base: &model.BaseFeatureView{Name: "viewB"},
EntityNames: []string{"driver", "customer"},
Base: &model.BaseFeatureView{Name: "viewB"},
Entities: []string{"driver", "customer"},
}
viewC := &model.FeatureView{
Base: &model.BaseFeatureView{Name: "viewC"},
EntityNames: []string{"driver"},
Base: &model.BaseFeatureView{Name: "viewC"},
Entities: []string{"driver"},
}
viewD := &model.FeatureView{
Base: &model.BaseFeatureView{Name: "viewD"},
EntityNames: []string{"customer"},
Base: &model.BaseFeatureView{Name: "viewD"},
Entities: []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"},
},
},
EntityNames: []string{"location"},
Entities: []string{"location"},
}
viewB := &model.FeatureView{
Base: &model.BaseFeatureView{Name: "viewB"},
EntityNames: []string{"location"},
Base: &model.BaseFeatureView{Name: "viewB"},
Entities: []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"},
},
},
EntityNames: []string{"location"},
Entities: []string{"location"},
}

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

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

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

0 comments on commit 98249ac

Please sign in to comment.