lostluck commented on a change in pull request #11474:
URL: https://github.com/apache/beam/pull/11474#discussion_r412316843



##########
File path: sdks/go/pkg/beam/core/runtime/exec/sdf.go
##########
@@ -263,20 +266,33 @@ func (n *ProcessSizedElementsAndRestrictions) 
ProcessElement(ctx context.Context
                return errors.Errorf("invalid status for ParDo %v: %v, want 
Active", n.PDo.UID, n.PDo.status)
        }
 
-       userElm := elm.Elm.(*FullValue).Elm.(*FullValue)
        rest := elm.Elm.(*FullValue).Elm2
        rt := n.inv.Invoke(rest)
+       var mainIn = &MainInput{

Review comment:
       The idiomatic form for this would be to do the following:
   
   ```suggestion
    mainIn := &MainInput{
   ```
   var declarations are usually for uninitialized variables.

##########
File path: sdks/go/pkg/beam/core/runtime/exec/sdf.go
##########
@@ -263,20 +266,33 @@ func (n *ProcessSizedElementsAndRestrictions) 
ProcessElement(ctx context.Context
                return errors.Errorf("invalid status for ParDo %v: %v, want 
Active", n.PDo.UID, n.PDo.status)
        }
 
-       userElm := elm.Elm.(*FullValue).Elm.(*FullValue)
        rest := elm.Elm.(*FullValue).Elm2
        rt := n.inv.Invoke(rest)
+       var mainIn = &MainInput{
+               Values:   values,
+               RTracker: rt,
+       }
 
-       return n.PDo.processMainInput(&MainInput{
-               Key: FullValue{ // User userElm's values but the top-level 
windows and timestamp.
+       // For the key, the way we fill it out depends on whether the input 
element
+       // is a KV or single-element. Single-elements might have been lifted 
out of
+       // their FullValue if they were decoded, so we need to have a case for 
that.
+       // Also, we use the the top-level windows and timestamp.
+       if userElm, ok := elm.Elm.(*FullValue).Elm.(*FullValue); ok {

Review comment:
       Note for the performance pass: We can know KV vs not KV from the input 
PCollection coderat exec/translate.go time, so we can avoid doing this if 
branch per element. 

##########
File path: sdks/go/pkg/beam/core/runtime/exec/translate.go
##########
@@ -372,32 +386,43 @@ func (b *builder) makeLink(from string, id linkID) (Node, 
error) {
 
                        switch op {
                        case graph.ParDo:
-                               n := &ParDo{UID: b.idgen.New(), Inbound: in, 
Out: out}
-                               n.Fn, err = graph.AsDoFn(fn, graph.MainUnknown)
+                               dofn, err := graph.AsDoFn(fn, graph.MainUnknown)
                                if err != nil {
                                        return nil, err
                                }
-                               n.PID = transform.GetUniqueName()
-
-                               input := 
unmarshalKeyedValues(transform.GetInputs())
-                               for i := 1; i < len(input); i++ {
-                                       // TODO(herohde) 8/8/2018: handle 
different windows, view_fn and window_mapping_fn.
-                                       // For now, assume we don't need any 
information in the pardo payload.
-
-                                       ec, wc, err := 
b.makeCoderForPCollection(input[i])
-                                       if err != nil {
-                                               return nil, err
+                               switch urn {
+                               case urnPairWithRestriction:
+                                       u = &PairWithRestriction{UID: 
b.idgen.New(), Fn: dofn, Out: out[0]}
+                               case urnSplitAndSizeRestrictions:
+                                       u = &SplitAndSizeRestrictions{UID: 
b.idgen.New(), Fn: dofn, Out: out[0]}
+                               default:
+                                       n := &ParDo{UID: b.idgen.New(), Fn: 
dofn, Inbound: in, Out: out}
+                                       n.PID = transform.GetUniqueName()
+
+                                       input := 
unmarshalKeyedValues(transform.GetInputs())
+                                       for i := 1; i < len(input); i++ {
+                                               // TODO(herohde) 8/8/2018: 
handle different windows, view_fn and window_mapping_fn.

Review comment:
       NoActionRequiredNit: I don't like that this gets to 6 indentations deep, 
which is a bit of a readability concern, but I'm not certain that moving this 
to a helper function would be that helpful. We'd probably need to break it into 
two helpers, one from handling the graphx.URNDoFn, and then this graph.ParDo 
block. 
   
    These are a changes for another PR though.

##########
File path: sdks/go/pkg/beam/core/runtime/exec/translate.go
##########
@@ -372,32 +386,43 @@ func (b *builder) makeLink(from string, id linkID) (Node, 
error) {
 
                        switch op {
                        case graph.ParDo:
-                               n := &ParDo{UID: b.idgen.New(), Inbound: in, 
Out: out}
-                               n.Fn, err = graph.AsDoFn(fn, graph.MainUnknown)
+                               dofn, err := graph.AsDoFn(fn, graph.MainUnknown)
                                if err != nil {
                                        return nil, err
                                }
-                               n.PID = transform.GetUniqueName()
-
-                               input := 
unmarshalKeyedValues(transform.GetInputs())
-                               for i := 1; i < len(input); i++ {
-                                       // TODO(herohde) 8/8/2018: handle 
different windows, view_fn and window_mapping_fn.
-                                       // For now, assume we don't need any 
information in the pardo payload.
-
-                                       ec, wc, err := 
b.makeCoderForPCollection(input[i])
-                                       if err != nil {
-                                               return nil, err
+                               switch urn {
+                               case urnPairWithRestriction:
+                                       u = &PairWithRestriction{UID: 
b.idgen.New(), Fn: dofn, Out: out[0]}
+                               case urnSplitAndSizeRestrictions:
+                                       u = &SplitAndSizeRestrictions{UID: 
b.idgen.New(), Fn: dofn, Out: out[0]}
+                               default:
+                                       n := &ParDo{UID: b.idgen.New(), Fn: 
dofn, Inbound: in, Out: out}
+                                       n.PID = transform.GetUniqueName()
+
+                                       input := 
unmarshalKeyedValues(transform.GetInputs())
+                                       for i := 1; i < len(input); i++ {
+                                               // TODO(herohde) 8/8/2018: 
handle different windows, view_fn and window_mapping_fn.
+                                               // For now, assume we don't 
need any information in the pardo payload.
+
+                                               ec, wc, err := 
b.makeCoderForPCollection(input[i])
+                                               if err != nil {
+                                                       return nil, err
+                                               }
+
+                                               sid := StreamID{
+                                                       Port:         Port{URL: 
b.desc.GetStateApiServiceDescriptor().GetUrl()},
+                                                       PtransformID: id.to,
+                                               }
+                                               sideInputID := 
fmt.Sprintf("i%v", i) // SideInputID (= local id, "iN")
+                                               side := 
NewSideInputAdapter(sid, sideInputID, coder.NewW(ec, wc))
+                                               n.Side = append(n.Side, side)
                                        }
-
-                                       sid := StreamID{
-                                               Port:         Port{URL: 
b.desc.GetStateApiServiceDescriptor().GetUrl()},
-                                               PtransformID: id.to,
+                                       if urn == 
urnProcessSizedElementsAndRestrictions {
+                                               u = 
&ProcessSizedElementsAndRestrictions{PDo: n}
+                                       } else {
+                                               u = n
                                        }

Review comment:
       Consider moving the common case to always be used, and then corrected 
afterwards.
   ```suggestion
                                        u = n
                                        if urn == 
urnProcessSizedElementsAndRestrictions {
                                                u = 
&ProcessSizedElementsAndRestrictions{PDo: n}
                                        }
   ```
   
   This idiom avoids the else block, and indicates that if there were a ?: 
operator in Go, that's what would happen. The compiler will optimize this 
appropriately.




----------------------------------------------------------------
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]


Reply via email to