This is an automated email from the ASF dual-hosted git repository. gurwls223 pushed a commit to branch branch-3.4 in repository https://gitbox.apache.org/repos/asf/spark.git
The following commit(s) were added to refs/heads/branch-3.4 by this push: new 268a96c715e [SPARK-42656][CONNECT] Adding SCALA REPL shell script for JVM client 268a96c715e is described below commit 268a96c715e03b2751e882583f148c053f476302 Author: Zhen Li <zhenli...@users.noreply.github.com> AuthorDate: Fri Mar 3 14:55:03 2023 +0900 [SPARK-42656][CONNECT] Adding SCALA REPL shell script for JVM client ### What changes were proposed in this pull request? Adding a simple script to start the Scala client in the Scala REPL. As well as a script to start the spark connect server for the client to connect to. ### Why are the changes needed? Make the JVM client more easy to be used. ### Does this PR introduce _any_ user-facing change? No ### How was this patch tested? Manually tested. Closes #40257 from zhenlineo/jshell. Lead-authored-by: Zhen Li <zhenli...@users.noreply.github.com> Co-authored-by: Herman van Hovell <her...@databricks.com> Signed-off-by: Hyukjin Kwon <gurwls...@apache.org> (cherry picked from commit 86e578ac49eff1b1ad3ca49f921a0f45a843da10) Signed-off-by: Hyukjin Kwon <gurwls...@apache.org> --- connector/connect/bin/spark-connect | 32 ++++++++++++++ connector/connect/bin/spark-connect-scala-client | 50 ++++++++++++++++++++++ .../connect/bin/spark-connect-scala-client.sc | 33 ++++++++++++++ 3 files changed, 115 insertions(+) diff --git a/connector/connect/bin/spark-connect b/connector/connect/bin/spark-connect new file mode 100755 index 00000000000..008209c8440 --- /dev/null +++ b/connector/connect/bin/spark-connect @@ -0,0 +1,32 @@ +#!/usr/bin/env bash + +# +# 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. +# + +# Go to the Spark project root directory +FWDIR="$(cd "`dirname "$0"`"/../../..; pwd)" +cd "$FWDIR" +export SPARK_HOME=$FWDIR + +# Build the jars needed for spark submit and spark connect +build/sbt package + +SCALA_BINARY_VER=`grep "scala.binary.version" "${SPARK_HOME}/pom.xml" | head -n1 | awk -F '[<>]' '{print $3}'` + +CONNECT_JAR=`ls "${SPARK_HOME}"/connector/connect/server/target/scala-"${SCALA_BINARY_VER}"/spark-connect-assembly*.jar | paste -sd ',' -` + +exec "${SPARK_HOME}"/bin/spark-submit --class org.apache.spark.sql.connect.SimpleSparkConnectService "$CONNECT_JAR" \ No newline at end of file diff --git a/connector/connect/bin/spark-connect-scala-client b/connector/connect/bin/spark-connect-scala-client new file mode 100755 index 00000000000..902091a74de --- /dev/null +++ b/connector/connect/bin/spark-connect-scala-client @@ -0,0 +1,50 @@ +#!/usr/bin/env bash + +# +# 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. +# + +# Use the spark connect JVM client to connect to a spark connect server. +# +# Start a local server: +# A local spark-connect server with default settings can be started using the following command: +# `connector/connect/bin/spark-connect` +# The client should be able to connect to this server directly with the default client settings. +# +# Connect to a remote server: +# To connect to a remote server, use env var `SPARK_REMOTE` to configure the client connection +# string. e.g. +# `export SPARK_REMOTE="sc://<URL>:<port>/;token=<auth token>;<param1>=<value1>"` + +# Go to the Spark project root directory +FWDIR="$(cd "`dirname "$0"`"/../../..; pwd)" +cd "$FWDIR" +export SPARK_HOME=$FWDIR + +# Build the jars needed for spark connect JVM client +build/sbt "sql/package;connect-client-jvm/assembly" + +CONNECT_CLASSPATH="$(build/sbt -DcopyDependencies=false "export connect-client-jvm/fullClasspath" | grep jar | tail -n1)" +SQL_CLASSPATH="$(build/sbt -DcopyDependencies=false "export sql/fullClasspath" | grep jar | tail -n1)" + +INIT_SCRIPT="${SPARK_HOME}"/connector/connect/bin/spark-connect-scala-client.sc + +# Determine the Scala version used in Spark +SCALA_BINARY_VER=`grep "scala.binary.version" "${SPARK_HOME}/pom.xml" | head -n1 | awk -F '[<>]' '{print $3}'` +SCALA_VER=`grep "scala.version" "${SPARK_HOME}/pom.xml" | grep ${SCALA_BINARY_VER} | head -n1 | awk -F '[<>]' '{print $3}'` +SCALA_BIN="${SPARK_HOME}/build/scala-${SCALA_VER}/bin/scala" + +exec "${SCALA_BIN}" -cp "$CONNECT_CLASSPATH:$SQL_CLASSPATH" -i $INIT_SCRIPT \ No newline at end of file diff --git a/connector/connect/bin/spark-connect-scala-client.sc b/connector/connect/bin/spark-connect-scala-client.sc new file mode 100644 index 00000000000..a8d1856498c --- /dev/null +++ b/connector/connect/bin/spark-connect-scala-client.sc @@ -0,0 +1,33 @@ +/* + * 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. + */ +import org.apache.spark.sql.functions._ +import org.apache.spark.sql.SparkSession + +val conStr = if (sys.env.contains("SPARK_REMOTE")) sys.env("SPARK_REMOTE") else "" +val sessionBuilder = SparkSession.builder() +val spark = if (conStr.isEmpty) sessionBuilder.build() else sessionBuilder.remote(conStr).build() +import spark.implicits._ +import spark.sql +println( + """ + | _____ __ ______ __ + | / ___/____ ____ ______/ /__ / ____/___ ____ ____ ___ _____/ /_ + | \__ \/ __ \/ __ `/ ___/ //_/ / / / __ \/ __ \/ __ \/ _ \/ ___/ __/ + | ___/ / /_/ / /_/ / / / ,< / /___/ /_/ / / / / / / / __/ /__/ /_ + |/____/ .___/\__,_/_/ /_/|_| \____/\____/_/ /_/_/ /_/\___/\___/\__/ + | /_/ + |""".stripMargin) \ No newline at end of file --------------------------------------------------------------------- To unsubscribe, e-mail: commits-unsubscr...@spark.apache.org For additional commands, e-mail: commits-h...@spark.apache.org