bogao007 commented on code in PR #47933:
URL: https://github.com/apache/spark/pull/47933#discussion_r1746370362


##########
python/pyspark/sql/streaming/stateful_processor.py:
##########
@@ -77,6 +78,58 @@ def clear(self) -> None:
         self._value_state_client.clear(self._state_name)
 
 
+class ListState:
+    """
+    Class used for arbitrary stateful operations with transformWithState to 
capture single value
+    state.
+
+    .. versionadded:: 4.0.0
+    """
+
+    def __init__(
+        self, list_state_client: ListStateClient, state_name: str, schema: 
Union[StructType, str]
+    ) -> None:
+        self._list_state_client = list_state_client
+        self._state_name = state_name
+        self.schema = schema
+
+    def exists(self) -> bool:
+        """
+        Whether list state exists or not.
+        """
+        return self._list_state_client.exists(self._state_name)
+
+    def get(self) -> Iterator["PandasDataFrameLike"]:

Review Comment:
   I circled back with `Iterator["PandasDataFrameLike"]` mainly because we 
provide the same parameter in `handleInputRows` where users can directly use 
`rows: Iterator["PandasDataFrameLike"]` to construct list state for `put()` and 
`appendList()`. 
   ```
   def handleInputRows(
           self, key: Any, rows: Iterator["PandasDataFrameLike"]
       ) -> Iterator["PandasDataFrameLike"]:
   ```
   If we only support `Iterator[Row]` for `put()` and `appendList()`, users 
might need extra transformation to achieve the same. @anishshri-db do you know 
if that's a common use case?



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


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to