Skip to content

Commit

Permalink
fix: make it compile
Browse files Browse the repository at this point in the history
  • Loading branch information
wfxr committed Nov 12, 2021
1 parent 19b6868 commit e030fcc
Show file tree
Hide file tree
Showing 8 changed files with 27 additions and 48 deletions.
4 changes: 2 additions & 2 deletions featctl/cmd/get_historical_feature.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ var getHistoricalFeatureCmd = &cobra.Command{
Short: "get historical features in a group",
PreRun: func(cmd *cobra.Command, args []string) {
if !cmd.Flags().Changed("revision") {
getHistoricalFeatureOpt.GroupRevision = nil
getHistoricalFeatureOpt.Revision = nil
}
if !cmd.Flags().Changed("limit") {
getHistoricalFeatureOpt.Limit = nil
Expand Down Expand Up @@ -54,5 +54,5 @@ func init() {
_ = getHistoricalFeatureCmd.MarkFlagRequired("group")

getHistoricalFeatureOpt.Limit = flags.Uint64P("limit", "l", 0, "max records to export")
getHistoricalFeatureOpt.GroupRevision = flags.Int64P("revision", "r", 0, "feature group revision")
getHistoricalFeatureOpt.Revision = flags.Int64P("revision", "r", 0, "feature group revision")
}
8 changes: 0 additions & 8 deletions featctl/cmd/sync.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,6 @@ var syncCmd = &cobra.Command{
oomStore := mustOpenOomStore(ctx, oomStoreCfg)
defer oomStore.Close()

groupName := args[0]

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

log.Println("syncing features ...")
if err := oomStore.Sync(ctx, syncOpt); err != nil {
log.Fatalf("failed sync features: %v\n", err)
Expand Down
7 changes: 2 additions & 5 deletions pkg/oomstore/export.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,8 @@ func (s *OomStore) ExportFeatureValues(ctx context.Context, opt types.ExportFeat
}

var dataTable string
if opt.GroupRevision == nil {
revision, err := s.GetRevision(ctx, metadatav2.GetRevisionOpt{
GroupID: &opt.GroupID,
Revision: opt.GroupRevision,
})
if opt.Revision == nil {
revision, err := s.GetRevisionBy(ctx, opt.GroupID, *opt.Revision)
if err != nil {
return nil, nil, err
}
Expand Down
10 changes: 5 additions & 5 deletions pkg/oomstore/export_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,9 +64,9 @@ func TestExportFeatureValues(t *testing.T) {
{
description: "provide revision",
opt: types.ExportFeatureValuesOpt{
GroupID: 1,
FeatureNames: []string{"price"},
GroupRevision: &prevRevision,
GroupID: 1,
FeatureNames: []string{"price"},
Revision: &prevRevision,
},
stream: prepareTwoFeatureStream(),
expected: [][]interface{}{{"1234", "xiaomi", int64(100)}, {"1235", "apple", int64(200)}, {"1236", "huawei", int64(300)}, {"1237", "oneplus", int64(240)}},
Expand All @@ -83,11 +83,11 @@ func TestExportFeatureValues(t *testing.T) {
metadatav2Store.EXPECT().ListFeature(gomock.Any(), metadatav2.ListFeatureOpt{GroupID: &tc.opt.GroupID}).Return(features)

dt := dataTable
if tc.opt.GroupRevision != nil {
if tc.opt.Revision != nil {
dt = prevDataTable
metadatav2Store.EXPECT().GetRevision(gomock.Any(), metadatav2.GetRevisionOpt{
GroupID: &tc.opt.GroupID,
Revision: tc.opt.GroupRevision,
Revision: tc.opt.Revision,
}).Return(&typesv2.Revision{
DataTable: prevDataTable,
}, nil)
Expand Down
16 changes: 8 additions & 8 deletions pkg/oomstore/revision.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,14 @@ import (
"github.com/oom-ai/oomstore/pkg/oomstore/typesv2"
)

func (s *OomStore) ListRevision(ctx context.Context, id *int16) typesv2.RevisionList {
return s.metadatav2.ListRevision(ctx, metadatav2.ListRevisionOpt{GroupID: id})
func (s *OomStore) ListRevision(ctx context.Context, groupID *int16) typesv2.RevisionList {
return s.metadatav2.ListRevision(ctx, metadatav2.ListRevisionOpt{GroupID: groupID})
}

func (s *OomStore) GetRevision(ctx context.Context, opt metadatav2.GetRevisionOpt) (*typesv2.Revision, error) {
return s.metadatav2.GetRevision(ctx, metadatav2.GetRevisionOpt{
GroupID: opt.GroupID,
Revision: opt.Revision,
RevisionID: opt.RevisionID,
})
func (s *OomStore) GetRevision(ctx context.Context, id int32) (*typesv2.Revision, error) {
return s.metadatav2.GetRevision(ctx, id)
}

func (s *OomStore) GetRevisionBy(ctx context.Context, groupID int16, revision int64) (*typesv2.Revision, error) {
return s.metadatav2.GetRevisionBy(ctx, groupID, revision)
}
17 changes: 4 additions & 13 deletions pkg/oomstore/sync.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,19 +13,12 @@ import (
)

func (s *OomStore) Sync(ctx context.Context, opt types.SyncOpt) error {
revision, err := s.GetRevision(ctx, metadatav2.GetRevisionOpt{
GroupID: &opt.GroupID,
RevisionID: &opt.RevisionId,
})
if err != nil {
return err
}

group, err := s.GetFeatureGroup(ctx, opt.GroupID)
revision, err := s.GetRevision(ctx, opt.RevisionId)
if err != nil {
return err
}

group := revision.Group
if group.OnlineRevisionID != nil && *group.OnlineRevisionID == revision.ID {
return fmt.Errorf("online store already in the latest revision")
}
Expand All @@ -35,7 +28,7 @@ func (s *OomStore) Sync(ctx context.Context, opt types.SyncOpt) error {
return err
}

features := s.ListFeature(ctx, metadatav2.ListFeatureOpt{GroupID: &opt.GroupID})
features := s.ListFeature(ctx, metadatav2.ListFeatureOpt{GroupID: &group.ID})
if err != nil {
return err
}
Expand All @@ -60,9 +53,7 @@ func (s *OomStore) Sync(ctx context.Context, opt types.SyncOpt) error {

var previousRevision *typesv2.Revision
if group.OnlineRevisionID != nil {
previousRevision, err = s.metadatav2.GetRevision(ctx, metadatav2.GetRevisionOpt{
RevisionID: group.OnlineRevisionID,
})
previousRevision, err = s.metadatav2.GetRevision(ctx, *group.OnlineRevisionID)
if err != nil {
return err
}
Expand Down
4 changes: 2 additions & 2 deletions pkg/oomstore/sync_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ func TestSync(t *testing.T) {
description: "user-defined revision, succeed",
opt: types.SyncOpt{
GroupID: 1,
RevisionId: 10,
RevisionID: 10,
},
group: prepareGroup(int32Ptr(2)),
revision: revision1,
Expand Down Expand Up @@ -94,7 +94,7 @@ func TestSync(t *testing.T) {

metadatav2Store.EXPECT().GetRevision(ctx, metadatav2.GetRevisionOpt{
GroupID: &tc.opt.GroupID,
RevisionID: &tc.opt.RevisionId,
RevisionID: &tc.opt.RevisionID,
}).Return(&tc.revision, nil)
if tc.expectedError == nil {
offlineStore.EXPECT().Export(ctx, offline.ExportOpt{
Expand Down
9 changes: 4 additions & 5 deletions pkg/oomstore/types/options.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,10 @@ type CreateFeatureGroupOpt struct {
}

type ExportFeatureValuesOpt struct {
GroupID int16
GroupRevision *int64
FeatureNames []string
Limit *uint64
GroupID int16
Revision *int64
FeatureNames []string
Limit *uint64
}

type ImportBatchFeaturesOpt struct {
Expand Down Expand Up @@ -80,7 +80,6 @@ type UpdateFeatureGroupOpt struct {
}

type SyncOpt struct {
GroupID int16
RevisionId int32
}

Expand Down

0 comments on commit e030fcc

Please sign in to comment.