-
Notifications
You must be signed in to change notification settings - Fork 11
refactor(oomstore/join): return the result instead of writing directly to the file #1177
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -9,8 +9,6 @@ import ( | |
| "sort" | ||
| "strconv" | ||
|
|
||
| "github.com/spf13/cast" | ||
|
|
||
| "github.com/oom-ai/oomstore/internal/database/offline" | ||
| "github.com/oom-ai/oomstore/pkg/errdefs" | ||
| "github.com/oom-ai/oomstore/pkg/oomstore/types" | ||
|
|
@@ -73,31 +71,24 @@ func (s *OomStore) ChannelJoin(ctx context.Context, opt types.ChannelJoinOpt) (* | |
| } | ||
|
|
||
| // Join gets point-in-time correct feature values for each entity row. | ||
| // The method is similar to Join, except that both input and output are files on disk. | ||
| // The method is similar to ChannelJoin, except a input files on disk. | ||
| // Input File should contain header, the first two columns of Input File should be | ||
| // entity_key, unix_milli, then followed by other real-time feature values. | ||
| func (s *OomStore) Join(ctx context.Context, opt types.JoinOpt) error { | ||
| ctx, cancel := context.WithCancel(ctx) | ||
| defer cancel() | ||
|
|
||
| func (s *OomStore) Join(ctx context.Context, opt types.JoinOpt) (*types.JoinResult, error) { | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. In this way, Go SDK will behave differently from other SDKs, is that expected?
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This makes go SDK more flexible. Because other SDKs need to go through the oomagent layer of wrappers. |
||
| if err := util.ValidateFullFeatureNames(opt.FeatureNames...); err != nil { | ||
| return err | ||
| return nil, err | ||
| } | ||
|
|
||
| entityRows, header, err := GetEntityRowsFromInputFile(ctx, opt.InputFilePath) | ||
| entityRows, header, err := getEntityRowsFromInputFile(ctx, opt.InputFilePath) | ||
| if err != nil { | ||
| return err | ||
| return nil, err | ||
| } | ||
|
|
||
| joinResult, err := s.ChannelJoin(ctx, types.ChannelJoinOpt{ | ||
| return s.ChannelJoin(ctx, types.ChannelJoinOpt{ | ||
| JoinFeatureNames: opt.FeatureNames, | ||
| EntityRows: entityRows, | ||
| ExistedFeatureNames: header[2:], | ||
| }) | ||
| if err != nil { | ||
| return err | ||
| } | ||
| return writeJoinResultToFile(opt.OutputFilePath, joinResult) | ||
| } | ||
|
|
||
| func (s *OomStore) buildRevisionRanges(ctx context.Context, group *types.Group) ([]*offline.RevisionRange, error) { | ||
|
|
@@ -142,7 +133,7 @@ func (s *OomStore) buildRevisionRanges(ctx context.Context, group *types.Group) | |
| return ranges, nil | ||
| } | ||
|
|
||
| func GetEntityRowsFromInputFile(ctx context.Context, inputFilePath string) (<-chan types.EntityRow, []string, error) { | ||
| func getEntityRowsFromInputFile(ctx context.Context, inputFilePath string) (<-chan types.EntityRow, []string, error) { | ||
| input, err := os.Open(inputFilePath) | ||
| if err != nil { | ||
| return nil, nil, errdefs.WithStack(err) | ||
|
|
@@ -207,34 +198,3 @@ func GetEntityRowsFromInputFile(ctx context.Context, inputFilePath string) (<-ch | |
| }() | ||
| return entityRows, header, nil | ||
| } | ||
|
|
||
| func writeJoinResultToFile(outputFilePath string, joinResult *types.JoinResult) error { | ||
| file, err := os.Create(outputFilePath) | ||
| if err != nil { | ||
| return err | ||
| } | ||
| defer file.Close() | ||
| w := csv.NewWriter(file) | ||
| defer w.Flush() | ||
|
|
||
| if err := w.Write(joinResult.Header); err != nil { | ||
| return err | ||
| } | ||
| for row := range joinResult.Data { | ||
| if row.Error != nil { | ||
| return row.Error | ||
| } | ||
| if err := w.Write(joinRecord(row.Record)); err != nil { | ||
| return err | ||
| } | ||
| } | ||
| return nil | ||
| } | ||
|
|
||
| func joinRecord(row []interface{}) []string { | ||
| record := make([]string, 0, len(row)) | ||
| for _, value := range row { | ||
| record = append(record, cast.ToString(value)) | ||
| } | ||
| return record | ||
| } | ||
Uh oh!
There was an error while loading. Please reload this page.