You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@spark.apache.org by gu...@apache.org on 2025/02/04 07:16:26 UTC
(spark) branch branch-4.0 updated: [SPARK-51055][SS][CONNECT] Streaming foreachBatch should call init logic inside a try
This is an automated email from the ASF dual-hosted git repository.
gurwls223 pushed a commit to branch branch-4.0
in repository https://gitbox.apache.org/repos/asf/spark.git
The following commit(s) were added to refs/heads/branch-4.0 by this push:
new f32e3a043a6c [SPARK-51055][SS][CONNECT] Streaming foreachBatch should call init logic inside a try
f32e3a043a6c is described below
commit f32e3a043a6c7c1827328f7952ad1ddf45a4bc57
Author: Wei Liu <we...@databricks.com>
AuthorDate: Tue Feb 4 16:16:07 2025 +0900
[SPARK-51055][SS][CONNECT] Streaming foreachBatch should call init logic inside a try
### What changes were proposed in this pull request?
So that any error can be propagated to the jvm. Especially the python version issue.
`handle_worker_exception` would write out a special int to the jvm, and wil be caught here:
https://github.com/apache/spark/blob/c92021091502b15b6020e6e4cc9b148009450ba5/core/src/main/scala/org/apache/spark/api/python/StreamingPythonRunner.scala#L99-L103
### Why are the changes needed?
Spark Connect improvements
### Does this PR introduce _any_ user-facing change?
No
### How was this patch tested?
Existing unit test
### Was this patch authored or co-authored using generative AI tooling?
No
Closes #49757 from WweiL/feb-worker-init-error-propagate.
Authored-by: Wei Liu <we...@databricks.com>
Signed-off-by: Hyukjin Kwon <gu...@apache.org>
(cherry picked from commit 505c644b40f4c51c3ae78d5869c5f60dc97b9de1)
Signed-off-by: Hyukjin Kwon <gu...@apache.org>
---
.../streaming/worker/foreach_batch_worker.py | 34 ++++++++++------------
1 file changed, 16 insertions(+), 18 deletions(-)
diff --git a/python/pyspark/sql/connect/streaming/worker/foreach_batch_worker.py b/python/pyspark/sql/connect/streaming/worker/foreach_batch_worker.py
index 0c92de6372b6..f144ac49e5bb 100644
--- a/python/pyspark/sql/connect/streaming/worker/foreach_batch_worker.py
+++ b/python/pyspark/sql/connect/streaming/worker/foreach_batch_worker.py
@@ -43,24 +43,6 @@ spark = None
def main(infile: IO, outfile: IO) -> None:
global spark
- check_python_version(infile)
-
- # Enable Spark Connect Mode
- os.environ["SPARK_CONNECT_MODE_ENABLED"] = "1"
-
- connect_url = os.environ["SPARK_CONNECT_LOCAL_URL"]
- session_id = utf8_deserializer.loads(infile)
-
- print(
- "Streaming foreachBatch worker is starting with "
- f"url {connect_url} and sessionId {session_id}."
- )
-
- # To attach to the existing SparkSession, we're setting the session_id in the URL.
- connect_url = connect_url + ";session_id=" + session_id
- spark_connect_session = SparkSession.builder.remote(connect_url).getOrCreate()
- assert spark_connect_session.session_id == session_id
- spark = spark_connect_session
log_name = "Streaming ForeachBatch worker"
@@ -72,6 +54,22 @@ def main(infile: IO, outfile: IO) -> None:
print(f"{log_name} Completed batch {batch_id} with DF id {df_id}")
try:
+ check_python_version(infile)
+
+ # Enable Spark Connect Mode
+ os.environ["SPARK_CONNECT_MODE_ENABLED"] = "1"
+
+ connect_url = os.environ["SPARK_CONNECT_LOCAL_URL"]
+ session_id = utf8_deserializer.loads(infile)
+
+ print(f"{log_name} is starting with " f"url {connect_url} and sessionId {session_id}.")
+
+ # To attach to the existing SparkSession, we're setting the session_id in the URL.
+ connect_url = connect_url + ";session_id=" + session_id
+ spark_connect_session = SparkSession.builder.remote(connect_url).getOrCreate()
+ assert spark_connect_session.session_id == session_id
+ spark = spark_connect_session
+
func = worker.read_command(pickle_ser, infile)
write_int(0, outfile)
outfile.flush()
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@spark.apache.org
For additional commands, e-mail: commits-help@spark.apache.org