[ https://issues.apache.org/jira/browse/BEAM-4681?focusedWorklogId=165342&page=com.atlassian.jira.plugin.system.issuetabpanels:worklog-tabpanel#worklog-165342 ]
ASF GitHub Bot logged work on BEAM-4681: ---------------------------------------- Author: ASF GitHub Bot Created on: 13/Nov/18 09:57 Start Date: 13/Nov/18 09:57 Worklog Time Spent: 10m Work Description: mxm commented on a change in pull request #7008: [BEAM-4681] Add support for portable timers in Flink batch mode URL: https://github.com/apache/beam/pull/7008#discussion_r232967092 ########## File path: runners/flink/src/main/java/org/apache/beam/runners/flink/translation/functions/FlinkExecutableStageFunction.java ########## @@ -230,23 +329,103 @@ public void close() throws Exception { private final Collector<RawUnionValue> collector; private final Map<String, Integer> outputMap; + @Nullable private final TimerReceiverFactory timerReceiverFactory; ReceiverFactory(Collector<RawUnionValue> collector, Map<String, Integer> outputMap) { + this(collector, outputMap, null); + } + + ReceiverFactory( + Collector<RawUnionValue> collector, + Map<String, Integer> outputMap, + @Nullable TimerReceiverFactory timerReceiverFactory) { this.collector = collector; this.outputMap = outputMap; + this.timerReceiverFactory = timerReceiverFactory; } @Override public <OutputT> FnDataReceiver<OutputT> create(String collectionId) { Integer unionTag = outputMap.get(collectionId); - checkArgument(unionTag != null, "Unknown PCollection id: %s", collectionId); - int tagInt = unionTag; + if (unionTag != null) { + int tagInt = unionTag; + return receivedElement -> { + synchronized (collectorLock) { + collector.collect(new RawUnionValue(tagInt, receivedElement)); + } + }; + } else if (timerReceiverFactory != null) { + // Delegate to TimerReceiverFactory + return timerReceiverFactory.create(collectionId); + } else { + throw new IllegalStateException( + String.format(Locale.ENGLISH, "Unknown PCollectionId %s", collectionId)); + } + } + } + + private static class TimerReceiverFactory implements OutputReceiverFactory { + + /** Timer PCollection id => TimerReference. */ + private final HashMap<String, TimerReference> timerReferenceMap; + /** Timer PCollection id => timer name => TimerSpec. */ + private final Map<String, Map<String, ProcessBundleDescriptors.TimerSpec>> timerSpecMap; + + private final BiConsumer<WindowedValue, TimerInternals.TimerData> timerDataConsumer; + private final Coder windowCoder; + + TimerReceiverFactory( + Collection<TimerReference> timerReferenceCollection, + Map<String, Map<String, ProcessBundleDescriptors.TimerSpec>> timerSpecMap, + BiConsumer<WindowedValue, TimerInternals.TimerData> timerDataConsumer, + Coder windowCoder) { + this.timerReferenceMap = new HashMap<>(); + for (TimerReference timerReference : timerReferenceCollection) { + timerReferenceMap.put(timerReference.collection().getId(), timerReference); + } + this.timerSpecMap = timerSpecMap; + this.timerDataConsumer = timerDataConsumer; + this.windowCoder = windowCoder; + } + + @Override + public <OutputT> FnDataReceiver<OutputT> create(String pCollectionId) { + // TODO This is ugly. There should be an easier way to retrieve the timer collectionid + String timerPCollectionId = + pCollectionId.substring(0, pCollectionId.length() - ".out:0".length()); Review comment: If it happens, it is definitely a bug. I suppose we could add a length-check to see if we can safely substring. The Precondition check afterwards should be sufficient to print a good error message. ---------------------------------------------------------------- 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: 165342) Time Spent: 9h (was: 8h 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: 9h > 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)