[
https://issues.apache.org/jira/browse/BEAM-6857?focusedWorklogId=369415&page=com.atlassian.jira.plugin.system.issuetabpanels:worklog-tabpanel#worklog-369415
]
ASF GitHub Bot logged work on BEAM-6857:
----------------------------------------
Author: ASF GitHub Bot
Created on: 09/Jan/20 22:21
Start Date: 09/Jan/20 22:21
Worklog Time Spent: 10m
Work Description: reuvenlax commented on pull request #10316: [BEAM-6857]
Support Dynamic Timers
URL: https://github.com/apache/beam/pull/10316#discussion_r364930284
##########
File path:
sdks/java/core/src/test/java/org/apache/beam/sdk/transforms/ParDoTest.java
##########
@@ -4288,4 +4289,51 @@ public void onTimer(OutputReceiver<String> r,
@TimerId("timer") Timer timer) {
r.output("It works");
}
}
+
+ /** Tests to validate ParDo timerFamily. */
+ @RunWith(JUnit4.class)
+ public static class TimerFamilyTests extends SharedTestBase implements
Serializable {
+
+ @Test
+ @Category({NeedsRunner.class, UsesTimersInParDo.class,
UsesTestStream.class})
+ public void testTimerFamilyEventTime() throws Exception {
+ final String timerFamilyId = "foo";
+
+ DoFn<KV<String, Integer>, String> fn =
+ new DoFn<KV<String, Integer>, String>() {
+
+ @TimerFamily(timerFamilyId)
+ private final TimerSpec spec =
TimerSpecs.timerMap(TimeDomain.EVENT_TIME);
+
+ @ProcessElement
+ public void processElement(
+ @TimerFamily(timerFamilyId) TimerMap timers,
OutputReceiver<String> r) {
+ timers.set("timer1", new Instant(1));
Review comment:
Test setting two timers with the same id but different timer families.
Test processing time timers.
----------------------------------------------------------------
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]
Issue Time Tracking
-------------------
Worklog Id: (was: 369415)
Time Spent: 12h 10m (was: 12h)
> Support dynamic timers
> ----------------------
>
> Key: BEAM-6857
> URL: https://issues.apache.org/jira/browse/BEAM-6857
> Project: Beam
> Issue Type: Bug
> Components: sdk-java-core
> Reporter: Reuven Lax
> Assignee: Shehzaad Nakhoda
> Priority: Major
> Time Spent: 12h 10m
> Remaining Estimate: 0h
>
> The Beam timers API currently requires each timer to be statically specified
> in the DoFn. The user must provide a separate callback method per timer. For
> example:
>
> {code:java}
> DoFn<String, String>()
> {
> @TimerId("timer1")
> private final TimerSpec timer1 = TimerSpecs.timer(...);
> @TimerId("timer2")
> private final TimerSpec timer2 = TimerSpecs.timer(...);
> ...... set timers in processElement
> @OnTimer("timer1")
> public void onTimer1() { .....}
> @OnTimer("timer2")
> public void onTimer2() {....}
> }
> {code}
>
> However there are many cases where the user does not know the set of timers
> statically when writing their code. This happens when the timer tag should be
> based on the data. It also happens when writing a DSL on top of Beam, where
> the DSL author has to create DoFns but does not know statically which timers
> their users will want to set (e.g. Scio).
>
> The goal is to support dynamic timers. Something as follows;
>
> {code:java}
> DoFn<String, String>()
> {
> @TimerId("timer")
> private final TimerSpec timer1 = TimerSpecs.dynamicTimer(...);
> @ProcessElement process(@TimerId("timer") DynamicTimer timer)
> {
> timer.set("tag1'", ts);
> timer.set("tag2", ts);
> }
> @OnTimer("timer")
> public void onTimer1(@TimerTag String tag) { .....}
> }
> {code}
>
--
This message was sent by Atlassian Jira
(v8.3.4#803005)