You are viewing a plain text version of this content. The canonical link for it is here.
Posted to reviews@spark.apache.org by GitBox <gi...@apache.org> on 2022/11/07 20:39:05 UTC

[GitHub] [spark] amaliujia commented on a diff in pull request #38535: [SPARK-41001] [CONNECT] Make `user_id` optional in SparkRemoteSession.

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: reviews-unsubscribe@spark.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org