amaliujia commented on code in PR #39361:
URL: https://github.com/apache/spark/pull/39361#discussion_r1063655079


##########
connector/connect/client/jvm/src/main/scala/org/apache/spark/sql/connect/client/SparkConnectClient.scala:
##########
@@ -17,31 +17,147 @@
 
 package org.apache.spark.sql.connect.client
 
+import scala.language.existentials
+
+import io.grpc.{ManagedChannel, ManagedChannelBuilder}
+import java.net.URI
+
 import org.apache.spark.connect.proto
+import org.apache.spark.sql.connect.common.config.ConnectCommon
+
+/**
+ * Conceptually the remote spark session that communicates with the server.
+ */
+class SparkConnectClient(
+    private val userContext: proto.UserContext,
+    private val channel: ManagedChannel) {
 
-class SparkConnectClient(private val userContext: proto.UserContext) {
+  private[this] val stub = 
proto.SparkConnectServiceGrpc.newBlockingStub(channel)
 
   /**
    * Placeholder method.
    * @return
    *   User ID.
    */
   def userId: String = userContext.getUserId()
+
+  /**
+   * Dispatch the [[proto.AnalyzePlanRequest]] to the Spark Connect server.
+   * @return
+   *   A [[proto.AnalyzePlanResponse]] from the Spark Connect server.
+   */
+  def analyze(request: proto.AnalyzePlanRequest): proto.AnalyzePlanResponse =
+    stub.analyzePlan(request)
+
+  /**
+   * Shutdown the client's connection to the server.
+   */
+  def shutdown(): Unit = {
+    channel.shutdownNow()
+  }
 }
 
 object SparkConnectClient {
   def builder(): Builder = new Builder()
 
+  /**
+   * This is a helper class that is used to create a GRPC channel based on 
either a set host and
+   * port or a NameResolver-compliant URI connection string.
+   */
   class Builder() {
     private val userContextBuilder = proto.UserContext.newBuilder()
+    private var _host: String = "localhost"
+    private var _port: Int = ConnectCommon.CONNECT_GRPC_BINDING_PORT

Review Comment:
   I am not sure if this is a right style for Scala:
   
   I guess we don't need `_` to name private var? or is this style defined 
somewhere?



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

Reply via email to