xinyuiscool commented on a change in pull request #14883:
URL: https://github.com/apache/beam/pull/14883#discussion_r640152071



##########
File path: 
runners/samza/src/main/java/org/apache/beam/runners/samza/translation/ParDoBoundMultiTranslator.java
##########
@@ -368,6 +405,80 @@ public void translatePortable(
     return Collections.emptyMap();
   }
 
+  @SuppressWarnings("unchecked")
+  private static final ViewFn<Iterable<WindowedValue<?>>, ?> VIEW_FN =
+      (ViewFn)
+          new PCollectionViews.MultimapViewFn<>(
+              
(PCollectionViews.TypeDescriptorSupplier<Iterable<WindowedValue<Void>>>)
+                  () -> TypeDescriptors.iterables(new 
TypeDescriptor<WindowedValue<Void>>() {}),
+              (PCollectionViews.TypeDescriptorSupplier<Void>) 
TypeDescriptors::voids);
+
+  // This method follows the same way in Flink to create a runner-side Java
+  // PCollectionView to represent a portable side input.
+  private static PCollectionView<?> createPCollectionView(
+      SideInputId sideInputId,
+      WindowedValue.WindowedValueCoder<?> coder,
+      WindowingStrategy<?, BoundedWindow> windowingStrategy) {
+
+    return new RunnerPCollectionView<>(
+        null,
+        new TupleTag<>(sideInputId.getLocalName()),
+        VIEW_FN,
+        // TODO: support custom mapping fn
+        windowingStrategy.getWindowFn().getDefaultWindowMappingFn(),
+        windowingStrategy,
+        coder.getValueCoder());
+  }
+
+  // Group the side input globally with a null key and then broadcast it
+  // to all tasks.
+  private static <SideInputT>
+      MessageStream<OpMessage<Iterable<SideInputT>>> 
groupAndBroadcastSideInput(
+          SideInputId sideInputId,
+          String sideInputCollectionId,
+          RunnerApi.PCollection sideInputPCollection,
+          WindowingStrategy<SideInputT, BoundedWindow> windowingStrategy,
+          WindowedValue.WindowedValueCoder<SideInputT> coder,
+          PortableTranslationContext ctx) {
+    final MessageStream<OpMessage<SideInputT>> sideInput =
+        ctx.getMessageStreamById(sideInputCollectionId);
+    final MessageStream<OpMessage<KV<Void, SideInputT>>> keyedSideInput =
+        sideInput.map(
+            opMessage -> {
+              WindowedValue<SideInputT> wv = opMessage.getElement();
+              return OpMessage.ofElement(wv.withValue(KV.of(null, 
wv.getValue())));

Review comment:
       Yup, null value is commonly used in beam to do global combine, as we do 
it in java translation too. It's the same as placeholder, but I guess it's more 
efficient (no key bytes).




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