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

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

                Author: ASF GitHub Bot
            Created on: 09/Aug/18 21:36
            Start Date: 09/Aug/18 21:36
    Worklog Time Spent: 10m 
      Work Description: lostluck commented on a change in pull request #6197: 
[BEAM-3286] Add preliminary Go support for side input
URL: https://github.com/apache/beam/pull/6197#discussion_r209083489
 
 

 ##########
 File path: sdks/go/pkg/beam/core/runtime/exec/sideinput.go
 ##########
 @@ -0,0 +1,149 @@
+// 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 (
+       "context"
+       "fmt"
+       "io"
+
+       "github.com/apache/beam/sdks/go/pkg/beam/core/graph/coder"
+       "github.com/apache/beam/sdks/go/pkg/beam/core/typex"
+)
+
+// This file contains support for side input.
+
+const IterableSideInputKey = ""
+
+// SideInputAdapter provides a concrete ReStream from a low-level side input 
reader. It
+// encapsulates StreamID and coding as needed.
+type SideInputAdapter interface {
+       NewIterable(ctx context.Context, reader SideInputReader, w 
typex.Window) (ReStream, error)
+}
+
+type sideInputAdapter struct {
+       sid StreamID
+       wc  WindowEncoder
+       kc  ElementEncoder
+       ec  ElementDecoder
+}
+
+// NewSideInputAdapter returns a side input adapter for the given StreamID and 
coder.
+// It expects a W<KV<K,V>> coder, because the protocol supports MultiSet 
access only.
+func NewSideInputAdapter(sid StreamID, c *coder.Coder) SideInputAdapter {
+       if !coder.IsW(c) || !coder.IsKV(coder.SkipW(c)) {
+               panic(fmt.Sprintf("expected WKV coder for side input: %v", c))
+       }
+
+       wc := MakeWindowEncoder(c.Window)
+       kc := MakeElementEncoder(coder.SkipW(c).Components[0])
+       ec := MakeElementDecoder(coder.SkipW(c).Components[1])
+       return &sideInputAdapter{sid: sid, wc: wc, kc: kc, ec: ec}
+}
+
+func (s *sideInputAdapter) NewIterable(ctx context.Context, reader 
SideInputReader, w typex.Window) (ReStream, error) {
+       key, err := EncodeElement(s.kc, []byte(IterableSideInputKey))
+       if err != nil {
+               return nil, err
+       }
+       win, err := EncodeWindow(s.wc, w)
+       if err != nil {
+               return nil, err
+       }
+       return &proxyReStream{
+               open: func() (Stream, error) {
+                       r, err := reader.Open(ctx, s.sid, key, win)
+                       if err != nil {
+                               return nil, err
+                       }
+                       return &elementStream{r: r, ec: s.ec}, nil
+               },
+       }, nil
+}
+
+func (s *sideInputAdapter) String() string {
+       return fmt.Sprintf("SideInputAdapter[%v]", s.sid)
+}
+
+// proxyReStream is a simple wrapper of an open function.
+type proxyReStream struct {
+       open func() (Stream, error)
+}
+
+func (p *proxyReStream) Open() (Stream, error) {
+       return p.open()
+}
+
+// elementStream exposes a Stream from decoding elements.
+type elementStream struct {
+       r  io.ReadCloser
+       ec ElementDecoder
+}
+
+func (s *elementStream) Close() error {
+       return s.r.Close()
+}
+
+func (s *elementStream) Read() (FullValue, error) {
+       // We should see a stream of unwindowed values -- no sizes, no key.
+       return s.ec.Decode(s.r)
+}
+
+// FixedKey transform any value into KV<K, V> for a fixed K.
+type FixedKey struct {
 
 Review comment:
   Consider not exporting this, unless necessary.

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on 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: 133292)
    Time Spent: 1h 20m  (was: 1h 10m)

> Go SDK support for portable side input
> --------------------------------------
>
>                 Key: BEAM-3286
>                 URL: https://issues.apache.org/jira/browse/BEAM-3286
>             Project: Beam
>          Issue Type: Sub-task
>          Components: sdk-go
>            Reporter: Henning Rohde
>            Assignee: Henning Rohde
>            Priority: Major
>              Labels: portability
>          Time Spent: 1h 20m
>  Remaining Estimate: 0h
>




--
This message was sent by Atlassian JIRA
(v7.6.3#76005)

Reply via email to