Skip to content

Commit 11e2e42

Browse files
committed
[SPARK-44481][CONNECT][PYTHON] Make pyspark.sql.is_remote an API
### What changes were proposed in this pull request? This PR proposes to expose and document `pyspark.sql.is_remote` as an API. ### Why are the changes needed? For the end users to be able to do if-else, e.g., for dispatching the code path to the legacy mode or connect mode. ### Does this PR introduce _any_ user-facing change? Yes, it exposes a method as an API. ### How was this patch tested? Manually built and checked the documentation. Closes #42072 from HyukjinKwon/SPARK-44481. Authored-by: Hyukjin Kwon <[email protected]> Signed-off-by: Hyukjin Kwon <[email protected]>
1 parent fa9725f commit 11e2e42

File tree

3 files changed

+22
-1
lines changed

3 files changed

+22
-1
lines changed

python/docs/source/reference/pyspark.sql/spark_session.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ See also :class:`SparkSession`.
5050
SparkSession.udf
5151
SparkSession.udtf
5252
SparkSession.version
53-
53+
is_remote
5454

5555
Spark Connect Only
5656
------------------

python/pyspark/sql/__init__.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@
5050
from pyspark.sql.readwriter import DataFrameReader, DataFrameWriter, DataFrameWriterV2
5151
from pyspark.sql.window import Window, WindowSpec
5252
from pyspark.sql.pandas.group_ops import PandasCogroupedOps
53+
from pyspark.sql.utils import is_remote
5354

5455

5556
__all__ = [
@@ -72,4 +73,5 @@
7273
"DataFrameWriter",
7374
"DataFrameWriterV2",
7475
"PandasCogroupedOps",
76+
"is_remote",
7577
]

python/pyspark/sql/utils.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,25 @@ def is_timestamp_ntz_preferred() -> bool:
146146
def is_remote() -> bool:
147147
"""
148148
Returns if the current running environment is for Spark Connect.
149+
150+
.. versionadded:: 4.0.0
151+
152+
Notes
153+
-----
154+
This will only return ``True`` if there is a remote session running.
155+
Otherwise, it returns ``False``.
156+
157+
This API is unstable, and for developers.
158+
159+
Returns
160+
-------
161+
bool
162+
163+
Examples
164+
--------
165+
>>> from pyspark.sql import is_remote
166+
>>> is_remote()
167+
False
149168
"""
150169
return "SPARK_CONNECT_MODE_ENABLED" in os.environ
151170

0 commit comments

Comments
 (0)