2323def build_unique_key_name (keys ):
2424 """
2525 Builds a unique key name for the given keys and window.
26- The key name is used to identify the Reduce task.
26+ The key name is used to identify the Accumulator task.
2727 The format is: start_time:end_time:key1:key2:...
2828 """
2929 return f"{ DELIMITER .join (keys )} "
@@ -32,21 +32,21 @@ def build_unique_key_name(keys):
3232def build_window_hash (window ):
3333 """
3434 Builds a hash for the given window.
35- The hash is used to identify the Reduce Window
35+ The hash is used to identify the Accumulator Window
3636 The format is: start_time:end_time
3737 """
3838 return f"{ window .start .ToMilliseconds ()} :{ window .end .ToMilliseconds ()} "
3939
4040
4141def create_window_eof_response (window ):
42- """Create a Reduce response with EOF=True for a given window"""
43- return accumulator_pb2 .ReduceResponse (window = window , EOF = True )
42+ """Create a Accumulator response with EOF=True for a given window"""
43+ return accumulator_pb2 .AccumulatorResponse (window = window , EOF = True )
4444
4545
4646class TaskManager :
4747 """
48- TaskManager is responsible for managing the Reduce tasks.
49- It is created whenever a new reduce operation is requested.
48+ TaskManager is responsible for managing the Accumulator tasks.
49+ It is created whenever a new accumulator operation is requested.
5050 """
5151
5252 def __init__ (self , handler : Union [AccumulatorAsyncCallable , _AccumulatorBuilderClass ]):
@@ -56,13 +56,13 @@ def __init__(self, handler: Union[AccumulatorAsyncCallable, _AccumulatorBuilderC
5656 # Event loop only keeps a weak reference, which can cause it to
5757 # get lost during execution.
5858 self .background_tasks = set ()
59- # Handler for the reduce operation
59+ # Handler for the accumulator operation
6060 self .__accumulator_handler = handler
61- # Queue to store the results of the reduce operation
61+ # Queue to store the results of the accumulator operation
6262 # This queue is used to send the results to the client
63- # once the reduce operation is completed.
63+ # once the accumulator operation is completed.
6464 # This queue is also used to send the error/exceptions to the client
65- # if the reduce operation fails.
65+ # if the accumulator operation fails.
6666 self .global_result_queue = NonBlockingIterator ()
6767 # EOF response counting to ensure proper termination
6868 self ._expected_eof_count = 0
@@ -87,14 +87,14 @@ def get_unique_windows(self):
8787
8888 def get_tasks (self ):
8989 """
90- Returns the list of reduce tasks that are
90+ Returns the list of accumulator tasks that are
9191 currently being processed
9292 """
9393 return list (self .tasks .values ())
9494
9595 async def stream_send_eof (self ):
9696 """
97- Sends EOF to input streams of all the Reduce
97+ Sends EOF to input streams of all the Accumulator
9898 tasks that are currently being processed.
9999 This is called when the input grpc stream is closed.
100100 """
@@ -136,7 +136,7 @@ async def create_task(self, req):
136136 riter = niter .read_iterator ()
137137 # Create a new result queue for the current task
138138 # We create a new result queue for each task, so that
139- # the results of the reduce operation can be sent to the
139+ # the results of the accumulator operation can be sent to the
140140 # the global result queue, which in turn sends the results
141141 # to the client.
142142 res_queue = NonBlockingIterator ()
@@ -153,7 +153,7 @@ async def create_task(self, req):
153153 consumer .add_done_callback (self .clean_background )
154154
155155 # Create a new task for the accumulator operation, this will invoke the
156- # Reduce handler with the given keys, request iterator, and window.
156+ # Accumulator handler with the given keys, request iterator, and window.
157157 task = asyncio .create_task (self .__invoke_accumulator (riter , res_queue ))
158158 # Save a reference to the result of this function, to avoid a
159159 # task disappearing mid-execution.
@@ -165,7 +165,7 @@ async def create_task(self, req):
165165 task , niter , keys , res_queue , consumer , datetime .fromtimestamp (- 1 )
166166 )
167167
168- # Save the result of the reduce operation to the task list
168+ # Save the result of the accumulator operation to the task list
169169 self .tasks [unified_key ] = curr_task
170170
171171 # Increment expected EOF count since we created a new task
@@ -195,23 +195,23 @@ async def __invoke_accumulator(
195195 output : NonBlockingIterator ,
196196 ):
197197 """
198- Invokes the UDF reduce handler with the given keys,
198+ Invokes the UDF accumulator handler with the given keys,
199199 request iterator, and window. Returns the result of the
200- reduce operation.
200+ accumulator operation.
201201 """
202202 new_instance = self .__accumulator_handler
203203
204204 # If the accumulator handler is a class instance, create a new instance of it.
205205 # It is required for a new key to be processed by a
206- # new instance of the reducer for a given window
206+ # new instance of the accumulator for a given window
207207 # Otherwise the function handler can be called directly
208208 if isinstance (self .__accumulator_handler , _AccumulatorBuilderClass ):
209209 new_instance = self .__accumulator_handler .create ()
210210 try :
211211 _ = await new_instance (request_iterator , output )
212212 # send EOF to the output stream
213213 await output .put (STREAM_EOF )
214- # If there is an error in the reduce operation, log and
214+ # If there is an error in the accumulator operation, log and
215215 # then send the error to the result queue
216216 except BaseException as err :
217217 _LOGGER .critical ("panic inside accumulator handle" , exc_info = True )
@@ -242,7 +242,7 @@ async def process_input_stream(
242242 else :
243243 _LOGGER .debug (f"No operation matched for request: { request } " , exc_info = True )
244244
245- # If there is an error in the reduce operation, log and
245+ # If there is an error in the accumulator operation, log and
246246 # then send the error to the result queue
247247 except BaseException as e :
248248 err_msg = f"Accumulator Error: { repr (e )} "
@@ -257,7 +257,7 @@ async def process_input_stream(
257257 # respective iterators.
258258 await self .stream_send_eof ()
259259
260- # get the list of reduce tasks that are currently being processed
260+ # get the list of accumulator tasks that are currently being processed
261261 # iterate through the tasks and wait for them to complete
262262 for task in self .get_tasks ():
263263 # Once this is done, we know that the task has written all the results
@@ -281,15 +281,15 @@ async def process_input_stream(
281281 # Now send STREAM_EOF to terminate the global result queue iterator
282282 await self .global_result_queue .put (STREAM_EOF )
283283 except BaseException as e :
284- err_msg = f"Reduce Streaming Error: { repr (e )} "
284+ err_msg = f"Accumulator Streaming Error: { repr (e )} "
285285 _LOGGER .critical (err_msg , exc_info = True )
286286 await self .global_result_queue .put (e )
287287
288288 async def write_to_global_queue (
289289 self , input_queue : NonBlockingIterator , output_queue : NonBlockingIterator , unified_key : str
290290 ):
291291 """
292- This task is for given Reduce task.
292+ This task is for given Accumulator task.
293293 This would from the local result queue for the task and then write
294294 to the global result queue
295295 """
0 commit comments