lostluck commented on a change in pull request #11976:
URL: https://github.com/apache/beam/pull/11976#discussion_r439765118
##########
File path: sdks/go/pkg/beam/pardo.go
##########
@@ -414,7 +414,45 @@ func ParDo6(s Scope, dofn interface{}, col PCollection,
opts ...Option) (PCollec
func ParDo7(s Scope, dofn interface{}, col PCollection, opts ...Option)
(PCollection, PCollection, PCollection, PCollection, PCollection, PCollection,
PCollection) {
ret := MustN(TryParDo(s, dofn, col, opts...))
if len(ret) != 7 {
- panic(fmt.Sprintf("expected 7 output. Found: %v", ret))
+ panic(ParDoErrorFormatter(dofn, ParDo7))
}
return ret[0], ret[1], ret[2], ret[3], ret[4], ret[5], ret[6]
}
+
+//ParDoErrorFormatter is a helper function to provide a more concise error
+// message to the users when a DoFn and its ParDo pairing is incorrect.
+func ParDoErrorFormatter(doFn interface{}, parDo interface{}) string {
+ doFnName := reflectx.FunctionName(doFn)
Review comment:
I see where the confusion is coming in. What I meant was to call
`graph.NewFn(doFn)` which will return the `graph.Fn` value which you can then
call `Name()` on.
https://github.com/apache/beam/blob/master/sdks/go/pkg/beam/core/graph/fn.go#L78
At the point you're calling it, you already know it's going to be valid
(since it was called by the TryParDo earlier). Go isn't magic, and won't
change the type of an interface{} value unless assigned explicitly (which won't
happen in this scope). interface{} values are passed by value, so even if you
change the type them they'll remain the same in the outer scope: See an example
here https://play.golang.org/p/A5QDrGyRwUu
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
[email protected]