forked from apache/spark
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[SPARK-43084][SS] Add applyInPandasWithState support for spark connect
### What changes were proposed in this pull request? This change adds applyInPandasWithState support for Spark connect. Example (try with local mode `./bin/pyspark --remote "local[*]"`): ``` >>> from pyspark.sql.streaming.state import GroupStateTimeout, GroupState >>> from pyspark.sql.types import ( ... LongType, ... StringType, ... StructType, ... StructField, ... Row, ... ) >>> import pandas as pd >>> output_type = StructType( ... [StructField("key", StringType()), StructField("countAsString", StringType())] ... ) >>> state_type = StructType([StructField("c", LongType())]) >>> def func(key, pdf_iter, state): ... total_len = 0 ... for pdf in pdf_iter: ... total_len += len(pdf) ... state.update((total_len,)) ... yield pd.DataFrame({"key": [key[0]], "countAsString": [str(total_len)]}) ... >>> >>> input_path = "/Users/peng.zhong/tmp/applyInPandasWithState" >>> df = spark.readStream.format("text").load(input_path) >>> q = ( ... df.groupBy(df["value"]) ... .applyInPandasWithState( ... func, output_type, state_type, "Update", GroupStateTimeout.NoTimeout ... ) ... .writeStream.queryName("this_query") ... .format("memory") ... .outputMode("update") ... .start() ... ) >>> >>> q.status {'message': 'Processing new data', 'isDataAvailable': True, 'isTriggerActive': True} >>> >>> spark.sql("select * from this_query").show() +-----+-------------+ | key|countAsString| +-----+-------------+ |hello| 1| | this| 1| +-----+-------------+ ``` ### Why are the changes needed? This change adds an API support for spark connect. ### Does this PR introduce _any_ user-facing change? This change adds an API support for spark connect. ### How was this patch tested? Manually tested. Closes apache#40736 from pengzhon-db/connect_applyInPandasWithState. Authored-by: pengzhon-db <[email protected]> Signed-off-by: Hyukjin Kwon <[email protected]>
- Loading branch information
1 parent
3941369
commit cbe94a1
Showing
12 changed files
with
408 additions
and
132 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.