amaliujia commented on code in PR #38535:
URL: https://github.com/apache/spark/pull/38535#discussion_r1015876295
##########
python/pyspark/sql/connect/client.py:
##########
@@ -235,23 +260,30 @@ def fromProto(cls, pb: typing.Any) -> "AnalyzeResult":
class RemoteSparkSession(object):
"""Conceptually the remote spark session that communicates with the
server"""
- def __init__(self, user_id: str, connection_string: str =
"sc://localhost"):
+ def __init__(self, connection_string: str = "sc://localhost", user_id:
Optional[str] = None):
"""
Creates a new RemoteSparkSession for the Spark Connect interface.
Parameters
----------
- user_id : str
- Unique User ID that is used to differentiate multiple users and
- isolate their Spark Sessions.
- connection_string: str
+ connection_string: Optional[str]
Connection string that is used to extract the connection
parameters and configure
- the GRPC connection.
+ the GRPC connection. Defaults to `sc://localhos`
+ user_id : Optional[str]
+ Optional unique user ID that is used to differentiate multiple
users and
+ isolate their Spark Sessions. If the `user_id` is not set, will
default to
+ the $USER environment. Defining the user ID as part of the
connection string
+ takes precedence.
"""
-
# Parse the connection string.
self._builder = ChannelBuilder(connection_string)
- self._user_id = user_id
+ self._user_id = None
+ if self._builder.user_id is not None:
+ self._user_id = self._builder.user_id
+ elif user_id is not None:
+ self._user_id = user_id
+ else:
+ self._user_id = os.getenv("USER", None)
Review Comment:
ahh I am a bit conservative here:
Is it possible that two independent devices have the same "USER", which in
turn make two devices share the same SparkSession remotely without awareness?
##########
python/pyspark/sql/connect/client.py:
##########
@@ -235,23 +260,30 @@ def fromProto(cls, pb: typing.Any) -> "AnalyzeResult":
class RemoteSparkSession(object):
"""Conceptually the remote spark session that communicates with the
server"""
- def __init__(self, user_id: str, connection_string: str =
"sc://localhost"):
+ def __init__(self, connection_string: str = "sc://localhost", user_id:
Optional[str] = None):
"""
Creates a new RemoteSparkSession for the Spark Connect interface.
Parameters
----------
- user_id : str
- Unique User ID that is used to differentiate multiple users and
- isolate their Spark Sessions.
- connection_string: str
+ connection_string: Optional[str]
Connection string that is used to extract the connection
parameters and configure
- the GRPC connection.
+ the GRPC connection. Defaults to `sc://localhos`
Review Comment:
typo: `sc://localhost`
--
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]