Xiao-zhen-Liu commented on code in PR #8642:
URL: https://github.com/apache/texera/pull/8642#discussion_r4498370753


##########
amber/src/main/python/core/runnables/data_processor.py:
##########
@@ -84,6 +84,9 @@ def process_state(self, state: State) -> None:
         or tuple generation based on the marker type.
         """
         with self._executor_session() as (executor, port_id):
+            # Register the state message before the callback runs, so
+            # process_state (and every call after it) can consult self.state.
+            executor.state = state

Review Comment:
   If I read the order right, in a loop where one Python UDF returns its own 
state from `produce_state_on_finish` and a second Python UDF after it reads 
`self.state["i"]` in `process_table`, the second fails with KeyError 'i': the 
first UDF's state replaced the loop's here. A Filter with `$i` in the second 
UDF's place still gets the loop's value. A UDF should still be able to read the 
loop's variables after such a state arrives.



##########
amber/src/main/python/core/models/operator.py:
##########
@@ -76,6 +76,15 @@ def decode_python_template(self, data: Union[str, bytes]) -> 
str:
 
     __internal_is_source: bool = False
 
+    # The state message most recently handed to this operator -- inside a
+    # control block, the iteration's loop variables. The runtime registers it
+    # right before ``process_state`` runs (see 
``DataProcessor.process_state``),
+    # so the callback and every call after it can consult it. A class-level
+    # default rather than an ``__init__`` assignment: a subclass ``__init__``
+    # that skips ``super()`` still reads ``None`` until a state arrives. The
+    # loop operators keep their own loop variables apart, on ``variables``.
+    state: Optional[State] = None

Review Comment:
   Calling the incoming state message `state` here reads as the operator's own 
state, and forces LoopStart and LoopEnd to rename their `self.state` to 
`self.variables` in this PR. A name that says it is the incoming state message 
(or the loop variables received from upstream) would be clearer and leave 
LoopStart and LoopEnd untouched.



-- 
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.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to