xintongsong commented on code in PR #631:
URL: https://github.com/apache/flink-agents/pull/631#discussion_r3195756966


##########
python/flink_agents/api/events/event.py:
##########
@@ -30,27 +30,62 @@
 from pyflink.common import Row
 
 
-class Event(BaseModel, ABC, extra="allow"):
+def _reconstruct_row_if_needed(data: Any) -> Any:
+    """Recursively reconstruct pyflink Row objects from their JSON-serialized 
dicts.
+
+    Row objects are serialized as ``{"type": "Row", "values": [...], "fields": 
[...]}``.
+    This helper walks dicts and lists to convert any such representation back
+    into a ``pyflink.common.Row``.
+    """
+    if isinstance(data, dict):
+        if data.get("type") == "Row" and "values" in data:
+            fields = data.get("fields")
+            values = data["values"]
+            if fields:
+                return Row(**dict(zip(fields, values, strict=False)))
+            return Row(*values)
+        return {k: _reconstruct_row_if_needed(v) for k, v in data.items()}
+    if isinstance(data, list):
+        return [_reconstruct_row_if_needed(item) for item in data]
+    return data
+
+
+class Event(BaseModel, extra="allow"):
     """Base class for all event types in the system.
 
+    This class serves dual purposes:
+
+    - **Unified events**: Instantiated directly with a user-defined ``type``
+      string and arbitrary key-value ``attributes``.  No subclassing required.
+    - **Subclassed events**: Concrete subclasses (e.g., :class:`InputEvent`)
+      set a fixed ``type`` string and store data in ``attributes``.
+
     Event allows extra properties, but these must be BaseModel instances or 
JSON
     serializable.
 
     Attributes:
     ----------
     id : UUID
         Unique identifier for the event, generated deterministically based on
-        event content. This ensures events with identical content have the same
-        ID, which is critical for ActionStateStore divergence detection.
+        event content.
+    type : str | None
+        Event type string used for routing.
+    attributes : Dict[str, Any]
+        Key-value properties for the event data.
     """
 
     id: UUID = Field(default=None)
+    type: str | None = Field(default=None)

Review Comment:
   Why do we allow `type` to be `None`?



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