Skip to content

Conversation

@lostluck
Copy link
Contributor

@lostluck lostluck commented Apr 6, 2019

  • Makes the error messages for CombineFns much clearer
    • Add significant testing around various "bad" and "good" CombineFns
    • Start returning better errors than just string errors, which can then be used to improve upstream errors.
  • Fixes an incorrect combiner implementation of stats.Mean
  • Make the funcx signature utilites accept arbitrary funcs, funcx.Fns, and reflectx.Funcs.

The errors now more clearly outline what went wrong, with what, and what is expected. Improvements could be made, but this is a good step forward.

Now messages are more like:
"graph.AsCombineFn: <fully qualfied func/method path> must be a binary merge of accumulators to be a CombineFn. It is of type , but it must be of type func(context.Context?, A, A) (A, error?) where A is the accumulator type"

or graph.AsCombineFn invalid <method in question, like AddInput>: <fully qualified func/method path> has type , but expected "" to be the accumulator type ""; expected a signature like <general signature for the method in question, with the accumulator properly substituted in>"


Thank you for your contribution! Follow this checklist to help us incorporate your contribution quickly and easily:

  • Choose reviewer(s) and mention them in a comment (R: @username).
  • Format the pull request title like [BEAM-XXX] Fixes bug in ApproximateQuantiles, where you replace BEAM-XXX with the appropriate JIRA issue, if applicable. This will automatically link the pull request to the issue.
  • If this contribution is large, please file an Apache Individual Contributor License Agreement.

Post-Commit Tests Status (on master branch)

Lang SDK Apex Dataflow Flink Gearpump Samza Spark
Go Build Status --- --- --- --- --- ---
Java Build Status Build Status Build Status Build Status
Build Status
Build Status
Build Status Build Status Build Status
Python Build Status
Build Status
--- Build Status
Build Status
Build Status --- --- ---

Pre-Commit Tests Status (on master branch)

--- Java Python Go Website
Non-portable Build Status Build Status Build Status Build Status
Portable --- Build Status --- ---

See .test-infra/jenkins/README for trigger phrase, status and link of all Jenkins jobs.

@lostluck
Copy link
Contributor Author

lostluck commented Apr 6, 2019

R: @youngoli Please review and ask all the questions.

Copy link
Contributor

@youngoli youngoli left a comment

Choose a reason for hiding this comment

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

Looks good, only a few comments for readability improvements.

e.fnKind, e.methodName, name, typ, err.Got, e.accumType, e.sig)
}
}
return fmt.Sprintf("%s invalid %v %v: \"%v\" for %v; expected a signature like %v",
Copy link
Contributor

Choose a reason for hiding this comment

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

This error is much harder for me to parse than the other ones in this method. I think it could be improved by a few more descriptive words and structuring it more like other errors in this codebase, where the original error is appended to the end. Here's an example I think works better:

{e.fnKind} invalid {e.methodName} {name}: got type {typ} but expected a signature like {e.sig}, original error: {e.err}

// ExtractOutput func(A) (O, error?)
// This means that the other signatures *must* match the type used in MergeAccumulators.
if len(mergeFn.Ret) <= 0 {
return nil, fmt.Errorf("%v: %v requires at least 1 return value. : %v", fnKind, mergeAccumulatorsName, mergeFn)
Copy link
Contributor

Choose a reason for hiding this comment

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

This whole section below is really repetitive, with a few small differences in the calls to funcx.Replace. Finding a way to cut down on the repetitive parts would make this way easier to read and reason about.

Potential idea: Wrap everything within the "if fx, ok := ..." blocks in a function that includes a lambda, where the funcx.Replace calls are made. That way the parts that actually vary (the Replace calls and any inputs for those) are more obvious, and the boilerplate of checking funcx.Satisfy is pared down.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done. This adds lines technically, but being able to more clearly avoid mismatches for name+signature pairs is probably worth it.
I threw it into a loop too.

// They are not working examples.
type MyAccum struct{}

type GoodCombineFn struct{}
Copy link
Contributor

Choose a reason for hiding this comment

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

Nitpick, but all these structs blend together, making reading through this a pain for anyone that edits this file in the future. A way to break up the flow would be nice.

Thing is, the only way I can think of though is to add comments above each struct declaration, but the comments wouldn't really add any actual info, and it feels odd to suggest adding useless comments just to improve the formatting. Are there better alternatives?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I added a comment here and there to break up the sections, but it doesn't add much or remove much. go fmt removes extra blank lines, and having empty // **** lines isn't common in Go.

@lostluck
Copy link
Contributor Author

lostluck commented Apr 9, 2019

Thanks for the comments! PTAL @youngoli

Copy link
Contributor

@youngoli youngoli left a comment

Choose a reason for hiding this comment

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

Looks good to me

@lostluck
Copy link
Contributor Author

lostluck commented Apr 9, 2019

R: @aaltay Please review and merge. Thank you!

@aaltay aaltay merged commit 83fe192 into apache:master Apr 9, 2019
ajamato pushed a commit to ajamato/beam that referenced this pull request Apr 10, 2019
* [BEAM-6825] Improve Combine error messages.

* !fixup Address style nits, and error readability.
ibzib pushed a commit to ibzib/beam that referenced this pull request Apr 22, 2019
* [BEAM-6825] Improve Combine error messages.

* !fixup Address style nits, and error readability.
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