diff --git a/featctl/cmd/get_historical_feature.go b/featctl/cmd/get_historical_feature.go index dff901aa3..94f3adad5 100644 --- a/featctl/cmd/get_historical_feature.go +++ b/featctl/cmd/get_historical_feature.go @@ -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", @@ -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) } }, @@ -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") diff --git a/featctl/test/test_get_historical_feature.sh b/featctl/test/test_get_historical_feature.sh index 4b4ad3caf..1a69022bc 100755 --- a/featctl/test/test_get_historical_feature.sh +++ b/featctl/test/test_get_historical_feature.sh @@ -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' @@ -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" diff --git a/pkg/oomstore/export.go b/pkg/oomstore/export.go index 8af495d4f..2a644deee 100644 --- a/pkg/oomstore/export.go +++ b/pkg/oomstore/export.go @@ -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 } @@ -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 } diff --git a/pkg/oomstore/types/options.go b/pkg/oomstore/types/options.go index 7b1adada0..49c081fb4 100644 --- a/pkg/oomstore/types/options.go +++ b/pkg/oomstore/types/options.go @@ -35,7 +35,6 @@ type CreateFeatureGroupOpt struct { } type ExportFeatureValuesOpt struct { - GroupID int16 RevisionID int32 FeatureNames []string Limit *uint64