taegeonum commented on a change in pull request #122: [NEMO-213] Use Beam's 
DoFnRunners to execute DoFn
URL: https://github.com/apache/incubator-nemo/pull/122#discussion_r223918209
 
 

 ##########
 File path: 
compiler/frontend/beam/src/main/java/org/apache/nemo/compiler/frontend/beam/transform/WindowDoFnTransform.java
 ##########
 @@ -0,0 +1,98 @@
+/*
+ * Copyright (C) 2018 Seoul National University
+ *
+ * Licensed 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.nemo.compiler.frontend.beam.transform;
+
+import com.google.common.collect.Iterables;
+import org.apache.beam.sdk.transforms.windowing.BoundedWindow;
+import org.apache.beam.sdk.transforms.windowing.PaneInfo;
+import org.apache.beam.sdk.util.WindowedValue;
+import org.apache.nemo.common.ir.OutputCollector;
+import org.apache.nemo.common.ir.vertex.transform.Transform;
+import org.apache.beam.sdk.transforms.windowing.WindowFn;
+import org.joda.time.Instant;
+
+import java.util.Collection;
+
+/**
+ * Windowing transform implementation.
+ * This transform simply windows the given elements into
+ * finite windows according to a user-specified WindowDoFnTransform.
+ * @param <T> input/output type.
+ * @param <W> window type
+ */
+public final class WindowDoFnTransform<T, W extends BoundedWindow>
+  implements Transform<WindowedValue<T>, WindowedValue<T>> {
+  private final WindowFn windowFn;
+  private OutputCollector<WindowedValue<T>> outputCollector;
+
+  /**
+   * Default Constructor.
+   * @param windowFn windowFn for the Transform.
+   */
+  public WindowDoFnTransform(final WindowFn windowFn) {
+    this.windowFn = windowFn;
+  }
+
+  @Override
+  public void prepare(final Context context, final 
OutputCollector<WindowedValue<T>> oc) {
+    this.outputCollector = oc;
+  }
+
+  @Override
+  public void onData(final WindowedValue<T> windowedValue) {
+    final BoundedWindow boundedWindow = 
Iterables.getOnlyElement(windowedValue.getWindows());
+    final T element = windowedValue.getValue();
+    final Instant timestamp = windowedValue.getTimestamp();
+
+    try {
+      final Collection<W> windows =
+        ((WindowFn<T, W>) windowFn)
+          .assignWindows(
+            ((WindowFn<T, W>) windowFn).new AssignContext() {
+              @Override
+              public T element() {
+                return element;
+              }
+
+              @Override
+              public Instant timestamp() {
+                return timestamp;
+              }
+
+              @Override
+              public BoundedWindow window() {
+                return boundedWindow;
+              }
+            });
+
+      // Emit compressed windows for efficiency
+      outputCollector.emit(WindowedValue.of(element, timestamp, windows, 
PaneInfo.NO_FIRING));
 
 Review comment:
   `WindowFnTransform` just assigns the windows and the firing should be 
implemented when we actually window the elements (e.g., in `GroupByKeyWindow` 
transform) 

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


With regards,
Apache Git Services

Reply via email to