|
Spark Applications are the combination
of two things: a Spark cluster and your code.
Following shows a sample application in
different languages.
|
||||
|
Scala Based App:
Scala is Spark’s “native” language and
naturally makes for a great way to write applications. It’s really no
different than writing a Scala application.
You can build applications using sbt or
Apache Maven, two Java Virtual Machine (JVM)–based build tools.
To configure an sbt build for our Scala
application, we specify a build.sbt file to manage the package information. Inside
the build.sbt file, there are a few key things to include:
Following is how a sample build.sbt file
would look like. Notice how we must specify the Scala version as well as the
Spark version:
Once we have defined the build file, we can
start adding code to our project.
The Sbt directory structure is same as that
for maven projects.
We put the source code in the Scala and Java
directories. Following shows an example of Scala-Spark code that initializes
the SparkSession, runs the application, and then exits.
The main class would be used when we
use spark-submit to submit it to our cluster for execution.
For compilation we have following options:
After compilation target folder contains Jar,
which can be used as argument to spark-submit.
Example:
|
Search This Blog
Tuesday, 23 April 2019
CH16.1 Developing Spark Applications
Subscribe to:
Comments (Atom)