-
Notifications
You must be signed in to change notification settings - Fork 951
/
basefeatureview.go
59 lines (52 loc) · 1.8 KB
/
basefeatureview.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
52
53
54
55
56
57
58
59
package model
import (
"fmt"
"github.com/feast-dev/feast/go/protos/feast/core"
)
type BaseFeatureView struct {
Name string
Features []*Feature
Projection *FeatureViewProjection
}
func NewBaseFeatureView(name string, featureProtos []*core.FeatureSpecV2) *BaseFeatureView {
base := &BaseFeatureView{Name: name}
features := make([]*Feature, len(featureProtos))
for index, featureSpecV2 := range featureProtos {
features[index] = NewFeatureFromProto(featureSpecV2)
}
base.Features = features
base.Projection = NewFeatureViewProjectionFromDefinition(base)
return base
}
func (fv *BaseFeatureView) WithProjection(projection *FeatureViewProjection) (*BaseFeatureView, error) {
if projection.Name != fv.Name {
return nil, fmt.Errorf("the projection for the %s FeatureView cannot be applied because it differs "+
"in Name; the projection is named %s and the Name indicates which "+
"FeatureView the projection is for", fv.Name, projection.Name)
}
features := make(map[string]bool)
for _, feature := range fv.Features {
features[feature.Name] = true
}
for _, feature := range projection.Features {
if _, ok := features[feature.Name]; !ok {
return nil, fmt.Errorf("the projection for %s cannot be applied because it contains %s which the "+
"FeatureView doesn't have", projection.Name, feature.Name)
}
}
return &BaseFeatureView{Name: fv.Name, Features: fv.Features, Projection: projection}, nil
}
func (fv *BaseFeatureView) ProjectWithFeatures(featureNames []string) *FeatureViewProjection {
features := make([]*Feature, 0)
for _, feature := range fv.Features {
for _, allowedFeatureName := range featureNames {
if feature.Name == allowedFeatureName {
features = append(features, feature)
}
}
}
return &FeatureViewProjection{
Name: fv.Name,
Features: features,
}
}