Skip to content
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

Add flatten on eval #104

Merged
merged 6 commits into from
Feb 3, 2023
Merged

Add flatten on eval #104

merged 6 commits into from
Feb 3, 2023

Conversation

garvinp-stripe
Copy link
Collaborator

@garvinp-stripe garvinp-stripe commented Jan 30, 2023

Add ability to flatten nested list on evaluations with WithFlattenLists option.
Fix build due to deprecated zlib 1.2.11
bazelbuild/rules_proto#117

msg, ok := AsProtoMessage(maybeMsg)
if !ok {
return nil, fmt.Errorf("%q returned something that's not a protobuf (a %s)", parsedOpts.funcName, maybeMsg.Type())
// Only flatten but not flatten deep. This will flatten out, in order, lists within main list and append the
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To avoid breaking any other existing uses of skycfg... would you be against making an ExecOption to turn on list flattening? I imagine just add a flattenLists bool to the execOptions struct, and then a:

// WithFlattenLists flattens lists one layer deep ([1, [2,3]] -> [1, 2, 3])
func WithFlattenLists() ExecOption {
	return fnExecOption(func(opts *execOptions) {
		opts.flattenLists = true
	})
}

Then you can case the logic below on parsedOpts.flattenLists

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

updated

caseName: "flatten nested list",
fileToLoad: "test13.sky",
expProtos: []proto.Message{
&pb.MessageV2{
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

then add a flattenLists field to endToEndTestCase which passes WithFlattenLists() as an argument to config.Main() and set it to true here

@garvinp-stripe garvinp-stripe requested review from jwog-stripe and dl-stripe and removed request for jwog-stripe February 2, 2023 18:30
jwog-stripe
jwog-stripe previously approved these changes Feb 2, 2023
Copy link
Contributor

@jwog-stripe jwog-stripe left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm

skycfg_test.go Outdated
Comment on lines 392 to 397
if testCase.flattenLists {
return config.Main(context.Background(), skycfg.WithVars(testCase.vars), skycfg.WithFlattenLists())
} else {
return config.Main(context.Background(), skycfg.WithVars(testCase.vars))
}

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we make the flattenLists property in the test cases an execOptions slice. We can then provide skycfg.WithFlattenLists() as a value in the test case and pass in the testCase.execOptions... in the call and forego the if/else statement.

type endToEndTestCase struct {
        ...
	execOptions []skycfg.ExecOption
}


testCases := []endToEndTestCase{
	...
	endToEndTestCase{
			caseName:   "flatten nested list",
			...
			execOptions: []skycfg.ExecOption{skycfg.WithFlattenLists()},
	},
}


return config.Main(context.Background(), skycfg.WithVars(testCase.vars), testCase.execOptions...)

@garvinp-stripe garvinp-stripe merged commit 35ad986 into stripe:trunk Feb 3, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants