WweiL commented on code in PR #40736:
URL: https://github.com/apache/spark/pull/40736#discussion_r1163209147


##########
python/pyspark/sql/connect/group.py:
##########
@@ -262,8 +264,44 @@ def applyInPandas(
 
     applyInPandas.__doc__ = PySparkGroupedData.applyInPandas.__doc__
 
-    def applyInPandasWithState(self, *args: Any, **kwargs: Any) -> None:
-        raise NotImplementedError("applyInPandasWithState() is not 
implemented.")
+    def applyInPandasWithState(
+            self,
+            func: "PandasGroupedMapFunctionWithState",
+            outputStructType: Union[StructType, str],
+            stateStructType: Union[StructType, str],
+            outputMode: str,
+            timeoutConf: str
+    ) -> "DataFrame":
+        from pyspark.sql.connect.udf import UserDefinedFunction
+        from pyspark.sql.connect.dataframe import DataFrame
+
+        udf_obj = UserDefinedFunction(
+            func,
+            returnType=outputStructType,
+            evalType=PythonEvalType.SQL_GROUPED_MAP_PANDAS_UDF_WITH_STATE,
+        )
+
+        output_schema: str = outputStructType.json() if 
isinstance(outputStructType, StructType)\

Review Comment:
   I'm not very sure if we could do like this? Above in `UserDefinedFunction`, 
it takes the same `outputStructType `, but handles it differently 
   
https://github.com/apache/spark/blob/007a42b8511b005aabdf45955e504d1f71eb1d25/python/pyspark/sql/connect/udf.py#L101
   and then
   
https://github.com/apache/spark/blob/007a42b8511b005aabdf45955e504d1f71eb1d25/python/pyspark/sql/connect/expressions.py#L595-L598
   Should we also follow this pattern? 
   
   Maybe @ueshin has more context?



##########
python/pyspark/sql/connect/group.py:
##########
@@ -262,8 +264,44 @@ def applyInPandas(
 
     applyInPandas.__doc__ = PySparkGroupedData.applyInPandas.__doc__
 
-    def applyInPandasWithState(self, *args: Any, **kwargs: Any) -> None:
-        raise NotImplementedError("applyInPandasWithState() is not 
implemented.")
+    def applyInPandasWithState(
+            self,
+            func: "PandasGroupedMapFunctionWithState",
+            outputStructType: Union[StructType, str],
+            stateStructType: Union[StructType, str],
+            outputMode: str,
+            timeoutConf: str
+    ) -> "DataFrame":
+        from pyspark.sql.connect.udf import UserDefinedFunction
+        from pyspark.sql.connect.dataframe import DataFrame
+
+        udf_obj = UserDefinedFunction(
+            func,
+            returnType=outputStructType,
+            evalType=PythonEvalType.SQL_GROUPED_MAP_PANDAS_UDF_WITH_STATE,
+        )
+
+        output_schema: str = outputStructType.json() if 
isinstance(outputStructType, StructType)\

Review Comment:
   I'm not very sure if we could do like this? Above in `UserDefinedFunction`, 
it takes the same `outputStructType`, but handles it differently 
   
https://github.com/apache/spark/blob/007a42b8511b005aabdf45955e504d1f71eb1d25/python/pyspark/sql/connect/udf.py#L101
   and then
   
https://github.com/apache/spark/blob/007a42b8511b005aabdf45955e504d1f71eb1d25/python/pyspark/sql/connect/expressions.py#L595-L598
   Should we also follow this pattern? 
   
   Maybe @ueshin has more context?



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