diff --git a/kyuubi-server/src/main/scala/org/apache/kyuubi/engine/spark/SparkProcessBuilder.scala b/kyuubi-server/src/main/scala/org/apache/kyuubi/engine/spark/SparkProcessBuilder.scala index 9d7f46eec22..6743a9ad299 100644 --- a/kyuubi-server/src/main/scala/org/apache/kyuubi/engine/spark/SparkProcessBuilder.scala +++ b/kyuubi-server/src/main/scala/org/apache/kyuubi/engine/spark/SparkProcessBuilder.scala @@ -102,10 +102,14 @@ class SparkProcessBuilder( } } - override protected val engineScalaBinaryVersion: String = { - val sparkCoreScalaVersion: String = Paths.get(sparkHome, "jars").toFile.list() - .collectFirst { case sparkCoreScalaVersionRegex(scalaVersion) => scalaVersion } + private[kyuubi] def extractEngineScalaBinaryVersion(fileNames: Iterable[String]): String = { + fileNames.collectFirst { case sparkCoreScalaVersionRegex(scalaVersion) => scalaVersion } .getOrElse(throw new KyuubiException("Failed to extract Scala version from spark-core jar")) + } + + override protected val engineScalaBinaryVersion: String = { + val sparkCoreScalaVersion = + extractEngineScalaBinaryVersion(Paths.get(sparkHome, "jars").toFile.list()) StringUtils.defaultIfBlank(System.getenv("SPARK_SCALA_VERSION"), sparkCoreScalaVersion) } diff --git a/kyuubi-server/src/test/scala/org/apache/kyuubi/engine/spark/SparkProcessBuilderSuite.scala b/kyuubi-server/src/test/scala/org/apache/kyuubi/engine/spark/SparkProcessBuilderSuite.scala index b83cdee4240..55d0aeecfba 100644 --- a/kyuubi-server/src/test/scala/org/apache/kyuubi/engine/spark/SparkProcessBuilderSuite.scala +++ b/kyuubi-server/src/test/scala/org/apache/kyuubi/engine/spark/SparkProcessBuilderSuite.scala @@ -26,7 +26,7 @@ import java.util.concurrent.{Executors, TimeUnit} import org.scalatest.time.SpanSugar._ import org.scalatestplus.mockito.MockitoSugar -import org.apache.kyuubi.{KerberizedTestHelper, KyuubiSQLException, SCALA_COMPILE_VERSION, Utils} +import org.apache.kyuubi._ import org.apache.kyuubi.config.KyuubiConf import org.apache.kyuubi.config.KyuubiConf.{ENGINE_LOG_TIMEOUT, ENGINE_SPARK_MAIN_RESOURCE} import org.apache.kyuubi.engine.ProcBuilder.KYUUBI_ENGINE_LOG_PATH_KEY @@ -366,21 +366,22 @@ class SparkProcessBuilderSuite extends KerberizedTestHelper with MockitoSugar { } test("extract spark core scala version") { + val builder = new SparkProcessBuilder("kentyao", KyuubiConf(false)) Seq( "spark-core_2.13-3.4.1.jar", "spark-core_2.13-3.5.0-abc-20230921.jar", "spark-core_2.13-3.5.0-xyz-1.2.3.jar", "spark-core_2.13-3.5.0.1.jar", - "spark-core_2.13.2-3.5.0.jar") - .foreach { f => - assertResult("2.13")(sparkCoreScalaVersionRegex.findFirstMatchIn(f).get.group(1)) - } + "spark-core_2.13.2-3.5.0.jar").foreach { f => + assertResult("2.13")(builder.extractEngineScalaBinaryVersion(Seq(f))) + } Seq( "spark-dummy_2.13-3.5.0.jar", "spark-core_2.13-3.5.0.1.zip", - "yummy-spark-core_2.13-3.5.0.jar") - .foreach { f => assertNotMatches(f, sparkCoreScalaVersionRegex) } + "yummy-spark-core_2.13-3.5.0.jar").foreach { f => + assertThrows[KyuubiException](builder.extractEngineScalaBinaryVersion(Seq(f))) + } } test("match scala version of spark home") {