Skip to content

Comments

[SPARK-43574][PYTHON][SQL] Support to set Python executable for UDF and pandas function APIs in workers during runtime#41215

Closed
HyukjinKwon wants to merge 1 commit intoapache:masterfrom
HyukjinKwon:SPARK-43574
Closed

[SPARK-43574][PYTHON][SQL] Support to set Python executable for UDF and pandas function APIs in workers during runtime#41215
HyukjinKwon wants to merge 1 commit intoapache:masterfrom
HyukjinKwon:SPARK-43574

Conversation

@HyukjinKwon
Copy link
Member

@HyukjinKwon HyukjinKwon commented May 18, 2023

What changes were proposed in this pull request?

This PR proposes a new configuration spark.sql.execution.pyspark.python that sets the Python executable on worker nodes.

Note that, if the Python executable is different from the one previously ran, it will creates a new Python worker processes because we reuse Python workers but they are unique by both executable path and env variables as a key:

val key = (pythonExec, envVars)
pythonWorkers.getOrElseUpdate(key, new PythonWorkerFactory(pythonExec, envVars)).create()

This PR is also a basework for Spark Connect to support a different set of dependencies.

Why are the changes needed?

This can be useful especially when you want to run your Python with a different set of dependencies during runtime (see also https://www.databricks.com/blog/2020/12/22/how-to-manage-python-dependencies-in-pyspark.html)

Does this PR introduce any user-facing change?

No, this PR adds a configuration but that's internal for now.

How was this patch tested?

Manually tested as below:

import sys
from pyspark.sql.functions import udf
spark.range(1).select(udf(lambda x: sys.executable)("id")).show(truncate=False)
spark.conf.set("spark.sql.execution.pyspark.python", "/.../miniconda3/envs/another-python/bin/python")
spark.range(1).select(udf(lambda x: sys.executable)("id")).show(truncate=False)
+------------------------------------------+
|<lambda>(id)                              |
+------------------------------------------+
|/.../miniconda3/envs/python3.9/bin/python3|
+------------------------------------------+

+----------------------------------------------+
|<lambda>(id)                                  |
+----------------------------------------------+
|/.../miniconda3/envs/another-python/bin/python|
+----------------------------------------------+

@dongjoon-hyun dongjoon-hyun changed the title [SPARK-43574][PYTHON] Support to set Python executable in workers during runtime [SPARK-43574][PYTHON][SQL] Support to set Python executable for UDF and pandas function APIs in workers during runtime May 18, 2023
Copy link
Member

@dongjoon-hyun dongjoon-hyun left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

+1, LGTM.
Merged to master for Apache Spark 3.5.0.

@HyukjinKwon HyukjinKwon deleted the SPARK-43574 branch January 15, 2024 00:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants