Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Scala/Spark version compatibility

I am building my first spark application.

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

On the Scala site https://www.scala-lang.org/download/all.html I am seeing the versions from 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?

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?

like image 433
sanoraya Avatar asked May 10 '17 03:05

sanoraya


People also ask

Which Scala is compatible with Spark?

Spark runs on Java 8/11/17, Scala 2.12/2.13, Python 3.7+ and R 3.5+.

Does Scala 2.11 work with spark3?

Building Spark using Maven requires Maven 3.6. 2 and Java 8. Spark requires Scala 2.12; support for Scala 2.11 was removed in Spark 3.0.

Does Spark work with Scala 3?

We can already use Scala 3 to build Spark applications thanks to the compatibility between Scala 2.13 and Scala 3.

Is Scala 2.12 backwards compatible?

So Scala 2.11 => Scala 2.12 is a major release. It's not a minor release! Scala major releases are not backwards compatible. Java goes to extreme lengths to maintain backwards compatibility, so Java code that was built with Java 8 can be run with Java 14.


1 Answers

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).

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.

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)

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.

like image 110
puhlen Avatar answered Sep 30 '22 03:09

puhlen