[ 
https://issues.apache.org/jira/browse/BEAM-8292?focusedWorklogId=408532&page=com.atlassian.jira.plugin.system.issuetabpanels:worklog-tabpanel#worklog-408532
 ]

ASF GitHub Bot logged work on BEAM-8292:
----------------------------------------

                Author: ASF GitHub Bot
            Created on: 24/Mar/20 04:20
            Start Date: 24/Mar/20 04:20
    Worklog Time Spent: 10m 
      Work Description: youngoli commented on pull request #11197: [BEAM-8292] 
Portable Reshuffle for Go SDK
URL: https://github.com/apache/beam/pull/11197#discussion_r396853348
 
 

 ##########
 File path: sdks/go/pkg/beam/core/runtime/exec/reshuffle.go
 ##########
 @@ -0,0 +1,170 @@
+// Licensed to the Apache Software Foundation (ASF) under one or more
+// contributor license agreements.  See the NOTICE file distributed with
+// this work for additional information regarding copyright ownership.
+// The ASF licenses this file to You under the Apache License, Version 2.0
+// (the "License"); you may not use this file except in compliance with
+// the License.  You may obtain a copy of the License at
+//
+//    http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+package exec
+
+import (
+       "bytes"
+       "context"
+       "fmt"
+       "io"
+       "math/rand"
+
+       "github.com/apache/beam/sdks/go/pkg/beam/core/graph/coder"
+       "github.com/apache/beam/sdks/go/pkg/beam/internal/errors"
+)
+
+// ReshuffleInput is a Node.
+type ReshuffleInput struct {
+       UID   UnitID
+       SID   StreamID
+       Coder *coder.Coder // Coder for the input PCollection.
+       Seed  int64
+       Out   Node
+
+       r    *rand.Rand
+       enc  ElementEncoder
+       wEnc WindowEncoder
+       b    bytes.Buffer
+       // ret is a cached allocations for passing to the next Unit. Units 
never modify the passed in FullValue.
+       ret FullValue
+}
+
+// ID returns the unit debug id.
+func (n *ReshuffleInput) ID() UnitID {
+       return n.UID
+}
+
+// Up initializes the value and window encoders, and the random source.
+func (n *ReshuffleInput) Up(ctx context.Context) error {
+       n.enc = MakeElementEncoder(coder.SkipW(n.Coder))
+       n.wEnc = MakeWindowEncoder(n.Coder.Window)
+       n.r = rand.New(rand.NewSource(n.Seed))
+       return nil
+}
+
+// StartBundle is a no-op.
+func (n *ReshuffleInput) StartBundle(ctx context.Context, id string, data 
DataContext) error {
+       return MultiStartBundle(ctx, id, data, n.Out)
+}
+
+func (n *ReshuffleInput) ProcessElement(ctx context.Context, value *FullValue, 
values ...ReStream) error {
+       n.b.Reset()
+       if err := EncodeWindowedValueHeader(n.wEnc, value.Windows, 
value.Timestamp, &n.b); err != nil {
+               return err
+       }
+       if err := n.enc.Encode(value, &n.b); err != nil {
+               return errors.WithContextf(err, "encoding element %v with coder 
%v", value, n.Coder)
+       }
+       n.ret = FullValue{Elm: n.r.Int(), Elm2: n.b.Bytes(), Timestamp: 
value.Timestamp}
+       if err := n.Out.ProcessElement(ctx, &n.ret); err != nil {
+               return err
+       }
+       return nil
 
 Review comment:
   ```suggestion
        return n.Out.ProcessElement(ctx, &n.ret)
   ```
 
----------------------------------------------------------------
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:
us...@infra.apache.org


Issue Time Tracking
-------------------

    Worklog Id:     (was: 408532)
    Time Spent: 1h 50m  (was: 1h 40m)

> Add a Reshuffle PTransform preventing fusion of the surrounding transforms
> --------------------------------------------------------------------------
>
>                 Key: BEAM-8292
>                 URL: https://issues.apache.org/jira/browse/BEAM-8292
>             Project: Beam
>          Issue Type: New Feature
>          Components: sdk-go
>            Reporter: John Patoch
>            Assignee: Robert Burke
>            Priority: Minor
>          Time Spent: 1h 50m
>  Remaining Estimate: 0h
>
> Reshuffle is a PTransform that takes a PCollection<A> and shuffles the data 
> to help increase parallelism.
> Reshuffle adds a temporary random key to each element, performs a
>  GroupByKey, and finally removes the temporary key.



--
This message was sent by Atlassian Jira
(v8.3.4#803005)

Reply via email to