Scala/Spark 版本兼容性

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/43883325/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-22 09:14:27  来源:igfitidea点击:

Scala/Spark version compatibility

scalaapache-spark

提问by sanoraya

I am building my first spark application.

我正在构建我的第一个 Spark 应用程序。

http://spark.apache.org/downloads.htmltells me that Spark 2.x is built against Scala 2.11.

http://spark.apache.org/downloads.html告诉我 Spark 2.x 是针对 Scala 2.11 构建的。

On the Scala site https://www.scala-lang.org/download/all.htmlI am seeing the versions from 2.11.0 - 2.11.11

在 Scala 网站https://www.scala-lang.org/download/all.html我看到了 2.11.0 - 2.11.11 的版本

So here is my question: what exactly does the 2.11 on the Spark site mean. Is it any Scala version in the 2.11.0 - 2.11.11 range?

所以这是我的问题:Spark 站点上的 2.11 到底是什么意思。它是 2.11.0 - 2.11.11 范围内的任何 Scala 版本吗?

Another question: Can I build my Spark apps using the latest Scala 2.12.2? I assume that Scala is backward compatible, so Spark libraries built with Scala say 2.11.x can be used/called in Scala 2.12.1 applications. Am I correct?

另一个问题:我可以使用最新的 Scala 2.12.2 构建我的 Spark 应用程序吗?我假设 Scala 是向后兼容的,所以用 Scala 构建的 Spark 库说 2.11.x 可以在 Scala 2.12.1 应用程序中使用/调用。我对么?

回答by puhlen

Scala is not backwards compatible, as you assume. You must use scala 2.11 with spark unless you rebuild spark under scala 2.12 (which is an option if you want to use the latest Scala version, but requires more work to get everything working).

正如您所假设的,Scala 不向后兼容。您必须将 scala 2.11 与 spark 一起使用,除非您在 scala 2.12 下重建 spark(如果您想使用最新的 Scala 版本,这是一个选项,但需要更多的工作才能使一切正常工作)。

When considering compatibility, you need to consider both source compatibility and binary compatibility. Scala does tend to be source backwards compatible, so you can rebuild your jar under a newer version, but it is not binary backward compatible, so you can't use a jar built with an old version with code from a new version.

在考虑兼容性时,您需要同时考虑源代码兼容性和二进制兼容性。Scala 确实倾向于向后兼容源代码,因此您可以在较新版本下重建 jar,但它不是二进制向后兼容的,因此您不能将旧版本构建的 jar 与新版本的代码一起使用。

This is just major versions, so scala 2.10, 2.11, 2.12 etc. are all major versions and are not binary compatible (even if they are source compatible). Within a major version though compatibility is maintained, so Scala 2.11 is compatible with all versions 2.11.0 - 2.11.11(plus any future 2.11 revisions will also be compatible)

这只是主要版本,因此 scala 2.10、2.11、2.12 等都是主要版本,并且不是二进制兼容的(即使它们是源兼容的)。在一个主要版本中,虽然保持了兼容性,因此Scala 2.11 与所有版本 2.11.0 - 2.11.11 兼容(加上任何未来的 2.11 修订版也将兼容)

It is for this reason that you will see most Scala libraries have separate releases for each major Scala version. You have to make sure that any library you use provides a jar for the version you are using, and that you use that jar and not one for a different version. If you use SBT %% will handle selecting the correct version for you but with maven you need to make sure to use the correct artifact name. The versions are typically prepended with _2.10, _2.11, and _2.12 referring to the scala version the jar is built for.

正是出于这个原因,您会看到大多数 Scala 库针对每个主要 Scala 版本都有单独的版本。您必须确保您使用的任何库都为您正在使用的版本提供了一个 jar,并且您使用该 jar 而不是不同版本的 jar。如果您使用 SBT %% 将处理为您选择正确的版本,但使用 maven 您需要确保使用正确的工件名称。这些版本通常以 _2.10、_2.11 和 _2.12 为前缀,指的是构建 jar 的 Scala 版本。

回答by the775

For anyone who wants to get jump started, this is the versioning pair I've used.

对于任何想要快速入门的人,这是我使用过的版本控制对。

scalaVersion := "2.11.12"

libraryDependencies ++= Seq(
  "org.apache.spark" %% "spark-core" % "2.3.2",
  "org.apache.spark" %% "spark-sql" % "2.3.2"
)

回答by Catalina Chircu

I used these versions of Scala and Spark and it worked OK for my need:

我使用了这些版本的 Scala 和 Spark,它可以满足我的需要:

scalaVersion := "2.12.8"
libraryDependencies += "org.apache.spark" %% "spark-hive" % "2.4.0"
libraryDependencies += "org.apache.spark" %% "spark-core" % "2.4.0"

Some libraries need 2.11 version of Scala, and in this case one should use the versions mentioned by @the775.

一些库需要 2.11 版本的 Scala,在这种情况下,应该使用@the775 提到的版本。