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

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

                Author: ASF GitHub Bot
            Created on: 24/Aug/18 15:58
            Start Date: 24/Aug/18 15:58
    Worklog Time Spent: 10m 
      Work Description: tweise commented on a change in pull request #6208: 
[BEAM-2930] Side input support for Flink portable streaming.
URL: https://github.com/apache/beam/pull/6208#discussion_r212675593
 
 

 ##########
 File path: 
runners/flink/src/main/java/org/apache/beam/runners/flink/translation/functions/FlinkStreamingSideInputHandlerFactory.java
 ##########
 @@ -0,0 +1,167 @@
+/*
+ * 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 org.apache.beam.runners.flink.translation.functions;
+
+import static com.google.common.base.Preconditions.checkArgument;
+import static com.google.common.base.Preconditions.checkNotNull;
+
+import com.google.common.collect.ImmutableMap;
+import java.io.ByteArrayOutputStream;
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Map;
+import org.apache.beam.model.pipeline.v1.RunnerApi;
+import 
org.apache.beam.model.pipeline.v1.RunnerApi.ExecutableStagePayload.SideInputId;
+import org.apache.beam.runners.core.construction.PTransformTranslation;
+import org.apache.beam.runners.core.construction.graph.ExecutableStage;
+import org.apache.beam.runners.core.construction.graph.SideInputReference;
+import org.apache.beam.runners.fnexecution.state.StateRequestHandler;
+import 
org.apache.beam.runners.fnexecution.state.StateRequestHandlers.SideInputHandler;
+import 
org.apache.beam.runners.fnexecution.state.StateRequestHandlers.SideInputHandlerFactory;
+import org.apache.beam.sdk.coders.Coder;
+import org.apache.beam.sdk.coders.KvCoder;
+import org.apache.beam.sdk.transforms.Materializations;
+import org.apache.beam.sdk.transforms.windowing.BoundedWindow;
+import org.apache.beam.sdk.values.KV;
+import org.apache.beam.sdk.values.PCollectionView;
+
+/**
+ * {@link StateRequestHandler} that uses {@link 
org.apache.beam.runners.core.SideInputHandler} to
+ * access the Flink broadcast state that represents side inputs.
+ */
+public class FlinkStreamingSideInputHandlerFactory implements 
SideInputHandlerFactory {
+
+  // Map from side input id to global PCollection id.
+  private final Map<SideInputId, PCollectionView<?>> sideInputToCollection;
+  private final org.apache.beam.runners.core.SideInputHandler runnerHandler;
+
+  /**
+   * Creates a new state handler for the given stage. Note that this requires 
a traversal of the
+   * stage itself, so this should only be called once per stage rather than 
once per bundle.
+   */
+  public static FlinkStreamingSideInputHandlerFactory forStage(
+      ExecutableStage stage,
+      Map<SideInputId, PCollectionView<?>> viewMapping,
+      org.apache.beam.runners.core.SideInputHandler runnerHandler) {
+    ImmutableMap.Builder<SideInputId, PCollectionView<?>> sideInputBuilder = 
ImmutableMap.builder();
+    for (SideInputReference sideInput : stage.getSideInputs()) {
+      SideInputId sideInputId =
+          SideInputId.newBuilder()
+              .setTransformId(sideInput.transform().getId())
+              .setLocalName(sideInput.localName())
+              .build();
+      sideInputBuilder.put(
+          sideInputId,
+          checkNotNull(
+              viewMapping.get(sideInputId),
+              "No side input for %s/%s",
+              sideInputId.getTransformId(),
+              sideInputId.getLocalName()));
+    }
+
+    FlinkStreamingSideInputHandlerFactory factory =
+        new FlinkStreamingSideInputHandlerFactory(sideInputBuilder.build(), 
runnerHandler);
+    return factory;
+  }
+
+  private FlinkStreamingSideInputHandlerFactory(
+      Map<SideInputId, PCollectionView<?>> sideInputToCollection,
+      org.apache.beam.runners.core.SideInputHandler runnerHandler) {
+    this.sideInputToCollection = sideInputToCollection;
+    this.runnerHandler = runnerHandler;
+  }
+
+  @Override
+  public <T, V, W extends BoundedWindow> SideInputHandler<V, W> forSideInput(
+      String transformId,
+      String sideInputId,
+      RunnerApi.FunctionSpec accessPattern,
+      Coder<T> elementCoder,
+      Coder<W> windowCoder) {
+
+    PCollectionView collectionNode =
+        sideInputToCollection.get(
+            
SideInputId.newBuilder().setTransformId(transformId).setLocalName(sideInputId).build());
+    checkArgument(collectionNode != null, "No side input for %s/%s", 
transformId, sideInputId);
+
+    if 
(PTransformTranslation.ITERABLE_SIDE_INPUT.equals(accessPattern.getUrn())) {
+      @SuppressWarnings("unchecked") // T == V
+      Coder<V> outputCoder = (Coder<V>) elementCoder;
+      return forIterableSideInput(collectionNode, outputCoder, windowCoder);
+    } else if 
(PTransformTranslation.MULTIMAP_SIDE_INPUT.equals(accessPattern.getUrn())
+        || 
Materializations.MULTIMAP_MATERIALIZATION_URN.equals(accessPattern.getUrn())) {
+      // TODO: Remove non standard URN.
+      // Using non standard version of multimap urn as dataflow uses the non 
standard urn.
+      @SuppressWarnings("unchecked") // T == KV<?, V>
+      KvCoder<?, V> kvCoder = (KvCoder<?, V>) elementCoder;
+      return forMultimapSideInput(
+          collectionNode, kvCoder.getKeyCoder(), kvCoder.getValueCoder(), 
windowCoder);
+    } else {
+      throw new IllegalArgumentException(
+          String.format("Unknown side input access pattern: %s", 
accessPattern));
+    }
+  }
+
+  private <T, W extends BoundedWindow> SideInputHandler<T, W> 
forIterableSideInput(
+      PCollectionView<?> collection, Coder<T> elementCoder, Coder<W> 
windowCoder) {
 
 Review comment:
   removed

----------------------------------------------------------------
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:
[email protected]


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

    Worklog Id:     (was: 137867)
    Time Spent: 6h 50m  (was: 6h 40m)

> Flink support for portable side input
> -------------------------------------
>
>                 Key: BEAM-2930
>                 URL: https://issues.apache.org/jira/browse/BEAM-2930
>             Project: Beam
>          Issue Type: Sub-task
>          Components: runner-flink
>            Reporter: Henning Rohde
>            Assignee: Thomas Weise
>            Priority: Major
>              Labels: portability
>          Time Spent: 6h 50m
>  Remaining Estimate: 0h
>




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

Reply via email to