Running the programs on Spark 4.3.0¶
All programs of the book (Java, Scala, MapReduce and PySpark) build and run on
Spark 4.3.0 (Scala 2.13, Java 17+). Every program is run by
tools/run_programs.py in CI, on Java 17 and 21,
with small inputs from data/.
Requirements¶
| Software | Version | Notes |
|---|---|---|
| Java | 17 or 21 | Spark 4.3.0 needs Java 17+ |
| Spark | 4.3.0 | a Spark download (SPARK_HOME, default ~/spark-4.3.0), or pip install -r requirements.txt |
| Maven | 3.9+ | or Gradle (the wrapper ./gradlew downloads Gradle 8.14.3), or Ant 1.10+ |
| Python | 3.11+ | only for tools/run_programs.py and the one PySpark program |
| Hadoop | not needed | MapReduce programs run in Hadoop's local mode with the Hadoop 3.5.0 jars of Spark 4.3.0 |
Build¶
Any one of the three builds gives the same classes:
| Build | Command | Output |
|---|---|---|
| Maven | scripts/build_with_maven.sh (mvn clean package) |
target/data-algorithms-book.jar, target/lib/ |
| Ant | scripts/build_with_ant.sh (ant test) |
dist/data_algorithms_book.jar, dist/lib/ |
| Gradle | ./gradlew build |
build/libs/data-algorithms-book.jar, copied to dist/ |
target/lib/ and dist/lib/ hold the two jars the programs need that are not part
of Spark (cloud9, commons-math). Ant downloads them (and the Scala 2.13 compiler)
from Maven Central; it compiles against the jars in $SPARK_HOME/jars.
Run one program¶
# Spark programs (Java and Scala): spark-submit in local mode
scripts/run_spark.sh org.dataalgorithms.chap03.spark.Top10 data/chap03/cats.txt
# MapReduce programs: Hadoop local mode, no Hadoop installation needed
scripts/run_mapreduce.sh org.dataalgorithms.chapB01.wordcount.mapreduce.WordCountDriver \
2 data/chapB01/words.txt /tmp/wordcount_output
Every program, with a ready-to-run command and its sample input, is listed on its
chapter page (for example chapter 3); the pages are
generated from tools/programs.json by tools/make_index.py. On a cluster, use spark-submit
--master yarn or hadoop jar with the same jar, as described in the book.
Run all programs¶
scripts/build_with_maven.sh
python3 tools/run_programs.py # every program (about 10 minutes)
python3 tools/run_programs.py chap03 chapB05 # programs whose name contains a word
python3 tools/run_programs.py --list # list programs and launchers
Outputs go to build/run_out/, logs of failed programs to build/run_logs/.
Five programs need a YARN or Spark standalone cluster (chapters B10 and B13) and
are skipped.
Changes since the book (Spark 4.3.0 refresh, 2026)¶
Program code was changed only to fix bugs and APIs removed from Spark, Scala or Hadoop:
- Builds:
pom.xml,build.gradleandbuild.xmluse Spark 4.3.0, Scala 2.13.18 and Java 17; the 244 jars inlib/were removed (Ant now compiles against$SPARK_HOME/jars); the Gradle wrapper is 8.14.3; sources are compiled as UTF-8. - Removed APIs:
new SQLContext(...)(chapter B07: from aSparkSession); the"yarn-cluster"master URL (chapters B04, B10); the staticLinearRegressionWithSGD.train()and the no-argumentLogisticRegressionWithSGD()(machine learning: the constructors with the same defaults); a Scala 2.13 overload (chapter 28); Python 2print(src/python/chap01). - Bugs fixed:
- chapter 3 Top-10: keys with equal values were lost (PR #43 by @willy-b);
- chapter 14 Naive Bayes (Java): the builder skipped the last attribute, so every query got the first class;
- machine learning: the car-price model was trained as a logistic classifier (it failed); the breast-cancer and spam models were trained for 1 iteration instead of 100 (the cancer model now classifies all 8 sample queries correctly);
ScalaKMeansread a 4th argument when only 3 were given;HadoopUtil.addJarsToDistributedCache()in Hadoop's local mode: failed when/lib/does not exist, and on Linux added every file of the system/libto each job; it now adds only.jarfiles, and nothing in local mode.- Absolute HDFS paths such as
saveAsTextFile("/output/1")(debug outputs in about 25 programs) are now relative ("output/1"): on HDFS they go to your home directory, locally to the current directory. Run a program again after deleting itsoutput/folder. - Two Java Naive Bayes builders (chapter 14) need the Kryo serializer:
SPARK_SUBMIT_OPTIONS="--conf spark.serializer=org.apache.spark.serializer.KryoSerializer". data/SP1.fq: removed a trailing empty line (it broke the chapter 17 Java k-mer programs).