Skip to content

Commit

Permalink
trying to compile
Browse files Browse the repository at this point in the history
  • Loading branch information
t0t07 committed Nov 11, 2021
1 parent 084444f commit fc2570c
Show file tree
Hide file tree
Showing 49 changed files with 483 additions and 338 deletions.
2 changes: 1 addition & 1 deletion featctl/cmd/describe_entity.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ var describeEntityCmd = &cobra.Command{
defer oomStore.Close()

entityName := args[0]
entity, err := oomStore.GetEntity(ctx, entityName)
entity, err := oomStore.GetEntityByName(ctx, entityName)
if err != nil {
log.Fatalf("failed getting entity %s, err %v\n", entityName, err)
}
Expand Down
2 changes: 1 addition & 1 deletion featctl/cmd/describe_feature.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ var describeFeatureCmd = &cobra.Command{
defer oomStore.Close()

featureName := args[0]
feature, err := oomStore.GetFeature(ctx, featureName)
feature, err := oomStore.GetFeatureByName(ctx, featureName)
if err != nil {
log.Fatalf("failed getting feature %s, err %v\n", featureName, err)
}
Expand Down
2 changes: 1 addition & 1 deletion featctl/cmd/describe_group.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ var describeGroupCmd = &cobra.Command{
defer oomStore.Close()

groupName := args[0]
group, err := oomStore.GetFeatureGroup(ctx, groupName)
group, err := oomStore.GetFeatureGroupByName(ctx, groupName)
if err != nil {
log.Fatalf("failed getting group %s, err %v\n", groupName, err)
}
Expand Down
17 changes: 14 additions & 3 deletions featctl/cmd/get_historical_feature.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,12 @@ import (
"github.com/spf13/cobra"
)

var getHistoricalFeatureOpt types.ExportFeatureValuesOpt
type getHistoricalFeatureOption struct {
types.ExportFeatureValuesOpt
groupName string
}

var getHistoricalFeatureOpt getHistoricalFeatureOption

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

if err := getHistoricalFeature(ctx, oomStore, getHistoricalFeatureOpt, *getOutput); err != nil {
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 {
log.Fatalf("failed exporting features: %v\n", err)
}
},
Expand All @@ -39,7 +50,7 @@ func init() {

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

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

getHistoricalFeatureOpt.Limit = flags.Uint64P("limit", "l", 0, "max records to export")
Expand Down
13 changes: 10 additions & 3 deletions featctl/cmd/get_online_feature.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,12 @@ import (
"github.com/oom-ai/oomstore/pkg/oomstore/types"
)

var getOnlineFeatureOpt types.GetOnlineFeatureValuesOpt
type getOnlineFeatureOption struct {
types.GetOnlineFeatureValuesOpt
featureNames []string
}

var getOnlineFeatureOpt getOnlineFeatureOption

var getOnlineFeatureCmd = &cobra.Command{
Use: "online-feature",
Expand All @@ -25,7 +30,9 @@ var getOnlineFeatureCmd = &cobra.Command{
oomStore := mustOpenOomStore(ctx, oomStoreCfg)
defer oomStore.Close()

featureValueMap, err := oomStore.GetOnlineFeatureValues(ctx, getOnlineFeatureOpt)
// TODO: convert feature names into feature ids

featureValueMap, err := oomStore.GetOnlineFeatureValues(ctx, getOnlineFeatureOpt.GetOnlineFeatureValuesOpt)
if err != nil {
log.Fatalf("failed getting online features: %v", err)
}
Expand All @@ -44,7 +51,7 @@ func init() {
flags.StringVarP(&getOnlineFeatureOpt.EntityKey, "entity-key", "k", "", "entity keys")
_ = getOnlineFeatureCmd.MarkFlagRequired("entity")

flags.StringSliceVar(&getOnlineFeatureOpt.FeatureNames, "feature", nil, "feature names")
flags.StringSliceVar(&getOnlineFeatureOpt.featureNames, "feature", nil, "feature names")
_ = getOnlineFeatureCmd.MarkFlagRequired("feature")
}

Expand Down
11 changes: 9 additions & 2 deletions featctl/cmd/import.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@ import (

type importOption struct {
types.ImportBatchFeaturesOpt
FilePath string
FilePath string
groupName string
}

var importOpt importOption
Expand All @@ -30,6 +31,12 @@ var importCmd = &cobra.Command{
oomStore := mustOpenOomStore(ctx, oomStoreCfg)
defer oomStore.Close()

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

file, err := os.Open(importOpt.FilePath)
if err != nil {
log.Fatalf("read file %s failed: %v", importOpt.FilePath, err)
Expand All @@ -53,7 +60,7 @@ func init() {

flags := importCmd.Flags()

flags.StringVarP(&importOpt.GroupName, "group", "g", "", "feature group")
flags.StringVarP(&importOpt.groupName, "group", "g", "", "feature group")
_ = importCmd.MarkFlagRequired("group")

flags.StringVar(&importOpt.Description, "description", "", "revision description")
Expand Down
7 changes: 5 additions & 2 deletions featctl/cmd/join_historical_feature_helper.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,12 @@ func joinHistoricalFeatures(ctx context.Context, store *oomstore.OomStore, opt J
return err
}

// TODO: convert feature names into feature IDs
var featureIDs []int16

joinResult, err := store.GetHistoricalFeatureValues(ctx, types.GetHistoricalFeatureValuesOpt{
FeatureNames: opt.FeatureNames,
EntityRows: entityRows,
FeatureIDs: featureIDs,
EntityRows: entityRows,
})
if err != nil {
return err
Expand Down
15 changes: 6 additions & 9 deletions featctl/cmd/list_entity.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import (
"time"

"github.com/olekukonko/tablewriter"
"github.com/oom-ai/oomstore/pkg/oomstore/types"
"github.com/oom-ai/oomstore/pkg/oomstore/typesv2"
"github.com/spf13/cobra"
)

Expand All @@ -27,10 +27,7 @@ var listEntityCmd = &cobra.Command{
oomStore := mustOpenOomStore(ctx, oomStoreCfg)
defer oomStore.Close()

entities, err := oomStore.ListEntity(ctx)
if err != nil {
log.Fatalf("failed listing entities, error %v\n", err)
}
entities := oomStore.ListEntity(ctx)

// print entities to stdout
if err := printEntities(entities, *listOutput); err != nil {
Expand All @@ -43,7 +40,7 @@ func init() {
listCmd.AddCommand(listEntityCmd)
}

func printEntities(entities []*types.Entity, output string) error {
func printEntities(entities typesv2.EntityList, output string) error {
switch output {
case CSV:
return printEntitiesInCSV(entities)
Expand All @@ -54,7 +51,7 @@ func printEntities(entities []*types.Entity, output string) error {
}
}

func printEntitiesInCSV(entities []*types.Entity) error {
func printEntitiesInCSV(entities typesv2.EntityList) error {
w := csv.NewWriter(os.Stdout)
if err := w.Write(entityHeader()); err != nil {
return err
Expand All @@ -69,7 +66,7 @@ func printEntitiesInCSV(entities []*types.Entity) error {
return nil
}

func printEntitiesInASCIITable(entities []*types.Entity) error {
func printEntitiesInASCIITable(entities typesv2.EntityList) error {
table := tablewriter.NewWriter(os.Stdout)
table.SetHeader(entityHeader())
table.SetAutoFormatHeaders(false)
Expand All @@ -81,7 +78,7 @@ func printEntitiesInASCIITable(entities []*types.Entity) error {
return nil
}

func entityRecord(entity *types.Entity) []string {
func entityRecord(entity *typesv2.Entity) []string {
return []string{entity.Name, strconv.Itoa(entity.Length), entity.Description, entity.CreateTime.Format(time.RFC3339),
entity.ModifyTime.Format(time.RFC3339)}
}
Expand Down
61 changes: 36 additions & 25 deletions featctl/cmd/list_feature.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,33 +9,53 @@ import (
"time"

"github.com/olekukonko/tablewriter"
"github.com/oom-ai/oomstore/pkg/oomstore/types"
"github.com/oom-ai/oomstore/internal/database/metadatav2"
"github.com/oom-ai/oomstore/pkg/oomstore/typesv2"
"github.com/spf13/cobra"
)

var listFeatureOpt types.ListFeatureOpt
type listFeatureOption struct {
metadatav2.ListFeatureOpt
entityName *string
groupName *string
}

var listFeatureOpt listFeatureOption

var listFeatureCmd = &cobra.Command{
Use: "feature",
Short: "list all existing features given a specific group",
PreRun: func(cmd *cobra.Command, args []string) {
if !cmd.Flags().Changed("entity") {
listFeatureOpt.EntityName = nil
listFeatureOpt.EntityID = nil
}
if !cmd.Flags().Changed("group") {
listFeatureOpt.GroupName = nil
listFeatureOpt.GroupID = nil
}
},
Run: func(cmd *cobra.Command, args []string) {
ctx := context.Background()
oomStore := mustOpenOomStore(ctx, oomStoreCfg)
defer oomStore.Close()

features, err := oomStore.ListFeature(ctx, listFeatureOpt)
if err != nil {
log.Fatalf("failed listing features given option %v, error %v\n", listFeatureOpt, err)
if listFeatureOpt.entityName != nil {
entity, err := oomStore.GetEntityByName(ctx, *listFeatureOpt.entityName)
if err != nil {
log.Fatalf("failed to get entity name=%s: %v", *listFeatureOpt.entityName, err)
}
listFeatureOpt.EntityID = &entity.ID
}

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

features := oomStore.ListFeature(ctx, listFeatureOpt.ListFeatureOpt)

// print features to stdout
if err := printFeatures(features, *listOutput); err != nil {
log.Fatalf("failed printing features, error %v\n", err)
Expand All @@ -47,12 +67,11 @@ func init() {
listCmd.AddCommand(listFeatureCmd)

flags := listFeatureCmd.Flags()

listFeatureOpt.EntityName = flags.StringP("entity", "e", "", "entity")
listFeatureOpt.GroupName = flags.StringP("group", "g", "", "feature group")
listFeatureOpt.entityName = flags.StringP("entity", "e", "", "entity")
listFeatureOpt.groupName = flags.StringP("group", "g", "", "feature group")
}

func printFeatures(features types.FeatureList, output string) error {
func printFeatures(features typesv2.FeatureList, output string) error {
switch output {
case CSV:
return printFeaturesInCSV(features)
Expand All @@ -63,7 +82,7 @@ func printFeatures(features types.FeatureList, output string) error {
}
}

func printFeaturesInCSV(features types.FeatureList) error {
func printFeaturesInCSV(features typesv2.FeatureList) error {
w := csv.NewWriter(os.Stdout)
if err := w.Write(featureHeader()); err != nil {
return err
Expand All @@ -78,7 +97,7 @@ func printFeaturesInCSV(features types.FeatureList) error {
return nil
}

func printFeaturesInASCIITable(features types.FeatureList) error {
func printFeaturesInASCIITable(features typesv2.FeatureList) error {
table := tablewriter.NewWriter(os.Stdout)
table.SetHeader(featureHeader())
table.SetAutoFormatHeaders(false)
Expand All @@ -91,23 +110,15 @@ func printFeaturesInASCIITable(features types.FeatureList) error {
}

func featureHeader() []string {
return []string{"Name", "Group", "Entity", "Category", "DBValueType", "ValueType", "Description", "OnlineRevision", "OfflineLatestRevision", "OfflineLatestDataTable", "CreateTime", "ModifyTime"}
return []string{"Name", "GroupID", "EntityID", "DBValueType", "ValueType", "Description", "OnlineRevision", "CreateTime", "ModifyTime"}
}

func featureRecord(f *types.Feature) []string {
func featureRecord(f *typesv2.Feature) []string {
onlineRevision := "<NULL>"
offlineRevision := "<NULL>"
offlineDataTable := "<NULL>"

if f.OnlineRevision != nil {
onlineRevision = fmt.Sprint(*f.OnlineRevision)
}
if f.OfflineRevision != nil {
offlineRevision = fmt.Sprint(*f.OfflineRevision)
}
if f.OfflineDataTable != nil {
offlineDataTable = *f.OfflineDataTable
onlineRevision = fmt.Sprint(*f.OnlineRevision())
}

return []string{f.Name, f.GroupName, f.EntityName, f.Category, f.DBValueType, f.ValueType, f.Description, onlineRevision, offlineRevision, offlineDataTable, f.CreateTime.Format(time.RFC3339), f.ModifyTime.Format(time.RFC3339)}
return []string{f.Name, serializeInt16(f.GroupID), serializeInt16(f.Entity().ID), f.DBValueType, f.ValueType, f.Description, onlineRevision, f.CreateTime.Format(time.RFC3339), f.ModifyTime.Format(time.RFC3339)}
}
Loading

0 comments on commit fc2570c

Please sign in to comment.