Skip to content

Commit

Permalink
cleanup: get historical-feature doesn't neeed group
Browse files Browse the repository at this point in the history
  • Loading branch information
t0t07 committed Nov 15, 2021
1 parent 284e660 commit 2b6c416
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 29 deletions.
18 changes: 2 additions & 16 deletions featctl/cmd/get_historical_feature.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,7 @@ import (
"github.com/spf13/cobra"
)

type getHistoricalFeatureOption struct {
types.ExportFeatureValuesOpt
groupName string
}

var getHistoricalFeatureOpt getHistoricalFeatureOption
var getHistoricalFeatureOpt types.ExportFeatureValuesOpt

var getHistoricalFeatureCmd = &cobra.Command{
Use: "historical-feature",
Expand All @@ -28,13 +23,7 @@ var getHistoricalFeatureCmd = &cobra.Command{
oomStore := mustOpenOomStore(ctx, oomStoreCfg)
defer oomStore.Close()

if group, err := oomStore.GetFeatureGroupByName(ctx, getHistoricalFeatureOpt.groupName); err != nil {
log.Fatalf("failed to get feature group name=%s: %v", getHistoricalFeatureOpt.groupName, err)
} else {
getHistoricalFeatureOpt.GroupID = group.ID
}

if err := getHistoricalFeature(ctx, oomStore, getHistoricalFeatureOpt.ExportFeatureValuesOpt, *getOutput); err != nil {
if err := getHistoricalFeature(ctx, oomStore, getHistoricalFeatureOpt, *getOutput); err != nil {
log.Fatalf("failed exporting features: %v\n", err)
}
},
Expand All @@ -47,9 +36,6 @@ func init() {

flags.StringSliceVar(&getHistoricalFeatureOpt.FeatureNames, "feature", nil, "select feature names")

flags.StringVarP(&getHistoricalFeatureOpt.groupName, "group", "g", "", "feature group name")
_ = getHistoricalFeatureCmd.MarkFlagRequired("group")

flags.Int32VarP(&getHistoricalFeatureOpt.RevisionID, "revision-id", "r", 0, "group revision id")
_ = getHistoricalFeatureCmd.MarkFlagRequired("revision-id")

Expand Down
4 changes: 2 additions & 2 deletions featctl/test/test_get_historical_feature.sh
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ expected='device,price
8,6500
9,4500
'
actual=$(featctl get historical-feature --group phone --feature price --revision-id 1 -o csv)
actual=$(featctl get historical-feature --feature price --revision-id 1 -o csv)
assert_eq "$case" "$expected" "$actual"

case='get with limit'
Expand All @@ -29,5 +29,5 @@ expected='device,price
4,1999
5,999
'
actual=$(featctl get historical-feature --group phone --feature price --revision-id 1 --limit 5 -o csv)
actual=$(featctl get historical-feature --feature price --revision-id 1 --limit 5 -o csv)
assert_eq "$case" "$expected" "$actual"
16 changes: 6 additions & 10 deletions pkg/oomstore/export.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,18 +10,13 @@ import (
)

func (s *OomStore) ExportFeatureValues(ctx context.Context, opt types.ExportFeatureValuesOpt) ([]string, <-chan *types.RawFeatureValueRecord, error) {
group, err := s.metadata.GetFeatureGroup(ctx, opt.GroupID)
if err != nil {
return nil, nil, err
}

revision, err := s.GetRevision(ctx, opt.RevisionID)
if err != nil {
return nil, nil, err
}

featureNames := opt.FeatureNames
allFeatures := s.ListFeature(ctx, metadata.ListFeatureOpt{GroupID: &opt.GroupID})
allFeatures := s.ListFeature(ctx, metadata.ListFeatureOpt{GroupID: &revision.GroupID})
if err != nil {
return nil, nil, err
}
Expand All @@ -37,18 +32,19 @@ func (s *OomStore) ExportFeatureValues(ctx context.Context, opt types.ExportFeat
}
}

if group.Entity == nil {
return nil, nil, fmt.Errorf("failed to get entity id='%d'", group.ID)
entity := revision.Group.Entity
if entity == nil {
return nil, nil, fmt.Errorf("failed to get entity id='%d'", revision.GroupID)
}

stream, err := s.offline.Export(ctx, offline.ExportOpt{
DataTable: revision.DataTable,
EntityName: group.Entity.Name,
EntityName: entity.Name,
FeatureNames: featureNames,
Limit: opt.Limit,
})

fields := append([]string{group.Entity.Name}, featureNames...)
fields := append([]string{entity.Name}, featureNames...)
return fields, stream, err
}

Expand Down
1 change: 0 additions & 1 deletion pkg/oomstore/types/options.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ type CreateFeatureGroupOpt struct {
}

type ExportFeatureValuesOpt struct {
GroupID int16
RevisionID int32
FeatureNames []string
Limit *uint64
Expand Down

0 comments on commit 2b6c416

Please sign in to comment.