-
Notifications
You must be signed in to change notification settings - Fork 951
/
featureview.go
51 lines (44 loc) · 1.26 KB
/
featureview.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
package model
import (
"github.com/feast-dev/feast/go/protos/feast/core"
"github.com/feast-dev/feast/go/protos/feast/types"
durationpb "google.golang.org/protobuf/types/known/durationpb"
)
const (
DUMMY_ENTITY_ID = "__dummy_id"
DUMMY_ENTITY_NAME = "__dummy"
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
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.Entities = []string{DUMMY_ENTITY_NAME}
} else {
featureView.Entities = proto.Spec.Entities
}
return featureView
}
func (fs *FeatureView) NewFeatureViewFromBase(base *BaseFeatureView) *FeatureView {
ttl := durationpb.Duration{Seconds: fs.Ttl.Seconds, Nanos: fs.Ttl.Nanos}
featureView := &FeatureView{Base: base,
Ttl: &ttl,
Entities: fs.Entities,
}
return featureView
}
func (fs *FeatureView) HasEntity(lookup string) bool {
for _, entityName := range fs.Entities {
if entityName == lookup {
return true
}
}
return false
}