codeBehindMe commented on a change in pull request #11976:
URL: https://github.com/apache/beam/pull/11976#discussion_r439726602
##########
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)
+ doFnOutSize := reflectx.FunctionOutputSize(doFn)
+
+ parDoName := reflectx.FunctionName(parDo)
+ parDoOutSize := reflectx.FunctionOutputSize(parDo)
+
+ useParDo := reflectx.FunctionName(RecommendParDo(doFnOutSize))
+ return fmt.Sprintf("DoFn %v has %v outptus, but %v requires %v outputs,
Use %v instead.", doFnName, doFnOutSize, parDoName, parDoOutSize, useParDo)
+
+}
+
+// recommendParDo takes a in a DoFns emit dimension and recommends the correct
+// ParDo to use.
+func RecommendParDo(emitDim int) interface{} {
+ switch {
+ case emitDim == 0:
+ return ParDo0
+ case emitDim == 1:
+ return ParDo
+ case emitDim == 2:
+ return ParDo2
+ case emitDim == 3:
+ return ParDo3
+ case emitDim == 4:
+ return ParDo4
+ case emitDim == 5:
+ return ParDo5
+ case emitDim == 6:
+ return ParDo6
+ case emitDim == 7:
+ return ParDo7
+ }
+ return ParDoN
+}
Review comment:
db99bf446a
----------------------------------------------------------------
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]