@@ -253,7 +253,7 @@ def from_runner_api(proto, context):
253253 'after_end_of_window' : AfterWatermark ,
254254 'after_processing_time' : AfterProcessingTime ,
255255 # after_processing_time, after_synchronized_processing_time
256- # always
256+ ' always' : Always ,
257257 'default' : DefaultTrigger ,
258258 'element_count' : AfterCount ,
259259 # never
@@ -367,6 +367,47 @@ def has_ontime_pane(self):
367367 return False
368368
369369
370+ class Always (TriggerFn ):
371+ """Repeatedly invoke the given trigger, never finishing."""
372+ def __init__ (self ):
373+ pass
374+
375+ def __repr__ (self ):
376+ return 'Always'
377+
378+ def __eq__ (self , other ):
379+ return type (self ) == type (other )
380+
381+ def __hash__ (self ):
382+ return 1
383+
384+ def on_element (self , element , window , context ):
385+ pass
386+
387+ def on_merge (self , to_be_merged , merge_result , context ):
388+ pass
389+
390+ def has_ontime_pane (self ):
391+ False
392+
393+ def reset (self , window , context ):
394+ pass
395+
396+ def should_fire (self , time_domain , watermark , window , context ):
397+ return True
398+
399+ def on_fire (self , watermark , window , context ):
400+ return False
401+
402+ @staticmethod
403+ def from_runner_api (proto , context ):
404+ return Always ()
405+
406+ def to_runner_api (self , context ):
407+ return beam_runner_api_pb2 .Trigger (
408+ always = beam_runner_api_pb2 .Trigger .Always ())
409+
410+
370411class AfterWatermark (TriggerFn ):
371412 """Fire exactly once when the watermark passes the end of the window.
372413
@@ -985,7 +1026,7 @@ def create_trigger_driver(
9851026 if windowing .is_default () and is_batch :
9861027 driver = BatchGlobalTriggerDriver ()
9871028 elif (windowing .windowfn == GlobalWindows () and
988- windowing .triggerfn == AfterCount (1 ) and is_batch ):
1029+ ( windowing .triggerfn in [ AfterCount (1 ), Always ()] ) and is_batch ):
9891030 # Here we also just pass through all the values exactly once.
9901031 driver = BatchGlobalTriggerDriver ()
9911032 else :
0 commit comments