hvanhovell commented on code in PR #41097:
URL: https://github.com/apache/spark/pull/41097#discussion_r1188812765
##########
connector/connect/client/jvm/src/main/scala/org/apache/spark/sql/SparkSession.scala:
##########
@@ -586,23 +610,56 @@ 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 always return a newly created session.
+ */
+ @deprecated(message = "Please use create() instead.", since = "3.5.0")
+ def build(): SparkSession = create()
+
+ /**
+ * Create a new [[SparkSession]].
+ *
+ * This will always return a newly created session.
+ *
+ * @since 3.5.0
+ */
+ def create(): SparkSession = {
+
tryCreateSessionFromClient().getOrElse(SparkSession.this.create(builder.configuration))
Review Comment:
It does. It returns a new session.
--
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]