bogao007 commented on code in PR #48290:
URL: https://github.com/apache/spark/pull/48290#discussion_r1793948755
##########
python/pyspark/sql/streaming/stateful_processor.py:
##########
@@ -121,6 +126,83 @@ def clear(self) -> None:
self._list_state_client.clear(self._state_name)
+class MapState:
+ """
+ Class used for arbitrary stateful operations with transformWithState to
capture single map
+ state.
+
+ .. versionadded:: 4.0.0
+ """
+
+ def __init__(
+ self,
+ map_state_client: MapStateClient,
+ state_name: str,
+ key_schema: Union[StructType, str],
+ value_schema: Union[StructType, str],
+ ) -> None:
+ self._map_state_client = map_state_client
+ self._state_name = state_name
+ self.key_schema = key_schema
+ self.value_schema = value_schema
+
+ def exists(self) -> bool:
+ """
+ Whether state exists or not.
+ """
+ return self._map_state_client.exists(self._state_name)
+
+ def get_value(self, key: Tuple) -> Optional[Tuple]:
Review Comment:
I'm hesitate to update the public facing API since I think we should keep
consistent with what we provide in
[Scala](https://github.com/apache/spark/blob/fed9a8da3d4187794161e0be325aa96be8487783/sql/api/src/main/scala/org/apache/spark/sql/streaming/MapState.scala).
Also user would only access the key when they use MapState, and we clearly
mentioned that it is `userKey` in the API doc, so I think it should be fine.
Let me know if you have any concerns on this.
--
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]