You are viewing a plain text version of this content. The canonical link for it is here.
Posted to reviews@spark.apache.org by "gerashegalov (via GitHub)" <gi...@apache.org> on 2023/03/23 00:59:54 UTC
[GitHub] [spark] gerashegalov commented on a diff in pull request #40515: [SPARK-42884][CONNECT] Add Ammonite REPL integration
gerashegalov commented on code in PR #40515:
URL: https://github.com/apache/spark/pull/40515#discussion_r1145546706
##########
connector/connect/client/jvm/src/test/scala/org/apache/spark/sql/connect/client/SparkConnectClientBuilderParseTestSuite.scala:
##########
@@ -0,0 +1,131 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.spark.sql.connect.client
+
+import org.apache.spark.sql.connect.client.util.ConnectFunSuite
+
+/**
+ * Test suite for [[SparkConnectClient.Builder]] parsing and configuration.
+ */
+class SparkConnectClientBuilderParseTestSuite extends ConnectFunSuite {
+ private def build(args: String*): SparkConnectClient.Builder = {
+ SparkConnectClient.builder().parse(args.toArray)
+ }
+
+ private def argumentTest(
+ name: String,
+ value: String,
+ extractor: SparkConnectClient.Builder => String): Unit = {
+ test("Argument - " + name) {
+ val builder = build("--" + name, value)
+ assert(value === extractor(builder))
+ val e = intercept[IllegalArgumentException] {
+ build("--" + name)
+ }
+ assert(e.getMessage.contains("option requires a value"))
+ }
+ }
+
+ argumentTest("host", "www.apache.org", _.host)
+ argumentTest("port", "1506", _.port.toString)
+ argumentTest("token", "azbycxdwev1234567890", _.token.get)
+ argumentTest("user_id", "U1238", _.userId.get)
+ argumentTest("user_name", "alice", _.userName.get)
+ argumentTest("user_agent", "MY APP", _.userAgent)
+
+ test("Argument - remote") {
+ val builder =
+ build("--remote", "sc://srv.apache.org/;user_id=x127;user_name=Q;token=nahnah;param1=x")
+ assert(builder.host == "srv.apache.org")
Review Comment:
here and elsewhere probably should use `===` consistently like on L35 for more illustrative exception messages?
##########
connector/connect/client/jvm/src/main/scala/org/apache/spark/sql/application/ConnectRepl.scala:
##########
@@ -0,0 +1,89 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.spark.sql.application
+
+import scala.util.control.NonFatal
+
+import ammonite.compiler.CodeClassWrapper
+import ammonite.util.Bind
+
+import org.apache.spark.annotation.DeveloperApi
+import org.apache.spark.sql.SparkSession
+import org.apache.spark.sql.connect.client.{SparkConnectClient, SparkConnectClientParser}
+
+/**
+ * REPL for spark connect.
+ */
+@DeveloperApi
+object ConnectRepl {
+ private val name = "Spark Connect REPL"
+
+ private val splash =
+ """
+ |Spark session available as 'spark'.
+ | _____ __ ______ __
+ | / ___/____ ____ ______/ /__ / ____/___ ____ ____ ___ _____/ /_
+ | \__ \/ __ \/ __ `/ ___/ //_/ / / / __ \/ __ \/ __ \/ _ \/ ___/ __/
+ | ___/ / /_/ / /_/ / / / ,< / /___/ /_/ / / / / / / / __/ /__/ /_
+ |/____/ .___/\__,_/_/ /_/|_| \____/\____/_/ /_/_/ /_/\___/\___/\__/
+ | /_/
+ |""".stripMargin
+
+ def main(args: Array[String]): Unit = {
+ // Build the client.
+ val client =
+ try {
+ SparkConnectClient
+ .builder()
+ .loadFromEnvironment()
+ .userAgent(name)
+ .parse(args)
+ .build()
+ } catch {
+ case NonFatal(e) =>
+ // scalastyle:off println
+ println(s"""
+ |$name
+ |${e.getMessage}
+ |${SparkConnectClientParser.usage()}
+ |""".stripMargin)
+ // scalastyle:on println
+ System.exit(1)
+ return
Review Comment:
```suggestion
sys.exit(1)
```
--
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