You are viewing a plain text version of this content. The canonical link for it is here.
Posted to reviews@spark.apache.org by "hvanhovell (via GitHub)" <gi...@apache.org> on 2023/05/09 12:28:33 UTC

[GitHub] [spark] hvanhovell commented on a diff in pull request #41097: [SPARK-43418][CONNECT] Add SparkSession.Builder.getOrCreate

hvanhovell commented on code in PR #41097:
URL: https://github.com/apache/spark/pull/41097#discussion_r1188520629


##########
connector/connect/client/jvm/src/main/scala/org/apache/spark/sql/SparkSession.scala:
##########
@@ -586,24 +610,50 @@ object SparkSession extends Logging {
   }
 
   class Builder() extends Logging {
-    private var _client: SparkConnectClient = _
+    private val builder = SparkConnectClient.builder()
+    private var client: SparkConnectClient = _
 
     def remote(connectionString: String): Builder = {
-      client(SparkConnectClient.builder().connectionString(connectionString).build())
+      builder.connectionString(connectionString)
       this
     }
 
     private[sql] def client(client: SparkConnectClient): Builder = {
-      _client = client
+      this.client = client
       this
     }
 
-    def build(): SparkSession = {
-      if (_client == null) {
-        _client = SparkConnectClient.builder().build()
+    private def tryCreateSessionFromClient(): Option[SparkSession] = {
+      if (client != null) {
+        Option(new SparkSession(client, cleaner, planIdGenerator))
+      } else {
+        None
       }
-      new SparkSession(_client, cleaner, planIdGenerator)
     }
+
+    /**
+     * Build the [[SparkSession]].
+     *
+     * This will try to reuse an existing session if has the same configuration.
+     */
+    def build(): SparkSession = {

Review Comment:
   It is below this method right?



-- 
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