Skip to content

Commit

Permalink
extract extractEngineScalaBinaryVersion method
Browse files Browse the repository at this point in the history
  • Loading branch information
bowenliang123 committed Oct 9, 2023
1 parent 42f8e55 commit 8d57f91
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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") {
Expand Down

0 comments on commit 8d57f91

Please sign in to comment.