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

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

                Author: ASF GitHub Bot
            Created on: 13/Nov/18 10:32
            Start Date: 13/Nov/18 10:32
    Worklog Time Spent: 10m 
      Work Description: mxm commented on a change in pull request #6981: 
[BEAM-4681] Add support for portable timers in Flink streaming mode 
URL: https://github.com/apache/beam/pull/6981#discussion_r232980441
 
 

 ##########
 File path: 
runners/flink/src/main/java/org/apache/beam/runners/flink/translation/wrappers/streaming/ExecutableStageDoFnOperator.java
 ##########
 @@ -359,16 +534,86 @@ public void finishBundle() {
         emitResults();
       } catch (Exception e) {
         throw new RuntimeException("Failed to finish remote bundle", e);
+      } finally {
+        remoteBundle = null;
+      }
+      if (bundleFinishedCallback != null) {
+        bundleFinishedCallback.run();
+        bundleFinishedCallback = null;
       }
     }
 
+    void setTimerKey(Object key) {
+      this.beforeFireTimerKey = key;
+    }
+
+    boolean isBundleInProgress() {
+      return remoteBundle != null;
+    }
+
+    void setBundleFinishedCallback(Runnable callback) {
+      this.bundleFinishedCallback = callback;
+    }
+
     private void emitResults() {
       KV<String, OutputT> result;
       while ((result = outputQueue.poll()) != null) {
-        outputManager.output(outputMap.get(result.getKey()), (WindowedValue) 
result.getValue());
+        final String inputCollectionId = result.getKey();
+        TupleTag<?> tag = outputMap.get(inputCollectionId);
+        WindowedValue windowedValue =
+            Preconditions.checkNotNull(
+                (WindowedValue) result.getValue(),
+                "Received a null value from the SDK harness for %s",
+                inputCollectionId);
+        if (tag != null) {
+          // process regular elements
+          outputManager.output(tag, windowedValue);
+        } else {
+          // process timer elements
+          // TODO This is ugly. There should be an easier way to retrieve the
+          String timerPCollectionId =
+              inputCollectionId.substring(0, inputCollectionId.length() - 
".out:0".length());
+          TimerReference timerReference = 
timerReferenceMap.get(timerPCollectionId);
+          if (timerReference != null) {
+            Timer timer =
+                Preconditions.checkNotNull(
+                    (Timer) ((KV) windowedValue.getValue()).getValue(),
+                    "Received null Timer from SDK harness: %s",
+                    windowedValue);
+            LOG.debug("Timer received: {} {}", inputCollectionId, timer);
+            for (Object window : windowedValue.getWindows()) {
+              StateNamespace namespace =
+                  StateNamespaces.window(windowCoder, (BoundedWindow) window);
+              TimerSpec timerSpec = extractTimerSpec(timerReference);
+              TimerInternals.TimerData timerData =
+                  TimerInternals.TimerData.of(
+                      timerPCollectionId,
+                      namespace,
+                      timer.getTimestamp(),
+                      timerSpec.getTimeDomain());
+              timerDataConsumer.accept(windowedValue, timerData);
 
 Review comment:
   I agree it can be confusing. On the other hand, this decouples the timer 
generation code and the timer consumer code.

----------------------------------------------------------------
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: 165354)
    Time Spent: 10h  (was: 9h 50m)

> Integrate support for timers using the portability APIs into Flink
> ------------------------------------------------------------------
>
>                 Key: BEAM-4681
>                 URL: https://issues.apache.org/jira/browse/BEAM-4681
>             Project: Beam
>          Issue Type: Sub-task
>          Components: runner-flink
>            Reporter: Luke Cwik
>            Assignee: Maximilian Michels
>            Priority: Major
>              Labels: portability, portability-flink
>          Time Spent: 10h
>  Remaining Estimate: 0h
>
> Consider using the code produced in BEAM-4658 to support timers.



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

Reply via email to