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


##########
common/workflow-core/src/main/scala/org/apache/texera/amber/core/state/package.scala:
##########
@@ -0,0 +1,24 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.texera.amber.core
+
+package object state {

Review Comment:
   I think this `package.scala` type alias makes the State API a little too 
subtle. Since `State` is now just an alias for `Map[String, Any]` while `object 
State` provides serialization helpers, readers have to remember that `State` 
means different things in type and term positions. It also leads to the 
unchecked `case map: State` warning because the alias is erased to `Map`.
   
   Could we either rename the helper object to something like 
`StateSerde`/`StateJson`, or make `State` a small real wrapper type around 
`Map[String, Any]`? I’d prefer the wrapper if we want State to remain a 
first-class engine concept with its own serialization rules.
   



##########
amber/src/main/python/core/runnables/test_main_loop.py:
##########
@@ -1139,6 +1139,63 @@ def send_resume(
             ),
         )
 
+    @pytest.mark.timeout(2)
+    def test_process_state_can_emit_multiple_states(

Review Comment:
   There is already a test case named 
`test_process_state_can_emit_multiple_states`.



##########
amber/src/main/python/core/runnables/test_main_loop.py:
##########
@@ -1139,6 +1139,63 @@ def send_resume(
             ),
         )
 
+    @pytest.mark.timeout(2)
+    def test_process_state_can_emit_multiple_states(
+        self,
+        main_loop,
+        output_queue,
+        mock_data_output_channel,
+        monkeypatch,
+    ):
+        class DummyExecutor:
+            @staticmethod
+            def process_state(state: State, port: int) -> State:
+                return {"value": state["value"] + 1, "port": port}
+
+        main_loop.context.executor_manager.executor = DummyExecutor()
+        monkeypatch.setattr(main_loop, "_check_and_process_control", lambda: 
None)
+        monkeypatch.setattr(
+            main_loop.context.output_manager,
+            "emit_state",
+            lambda state: [(mock_data_output_channel.to_worker_id, 
StateFrame(state))],
+        )
+
+        switch_count = {"value": 0}
+
+        def fake_switch_context():
+            switch_count["value"] += 1
+            # xinyuan-state-only still uses the original two-switch state 
handshake:

Review Comment:
   The branch name should not be part of a PR.



##########
amber/src/main/python/core/runnables/network_receiver.py:
##########
@@ -96,7 +97,17 @@ def data_handler(command: bytes, table: Table) -> int:
                 "Data",
                 lambda _: DataFrame(table),
                 "State",
-                lambda _: StateFrame(State(table)),
+                lambda _: StateFrame(
+                    deserialize_state(
+                        Tuple(
+                            {
+                                name: table[name][0].as_py()

Review Comment:
   Does this mean only one the first state will be read?



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