Skip to content

Chapter 28: MapReduce and Monoids

Programs of chapter 28 of the book Data Algorithms (O'Reilly, 2015), running on Spark 4.3.0.

Chapter notes: chap28 ยท chap28/scala

Sample input: data/chap28/numbers.txt

Run the commands from the repository folder after building the jar (Running the programs).

Spark (Java)

chap28.spark.SparkMeanMonoidized

Source: SparkMeanMonoidized.java

scripts/run_spark.sh org.dataalgorithms.chap28.spark.SparkMeanMonoidized data/chap28/numbers.txt
  • Writes to output/ in the current directory; delete it first if it exists: rm -r output

Spark (Java 8 lambdas)

chap28.sparkwithlambda.SparkMeanMonoidized

Source: SparkMeanMonoidized.java

scripts/run_spark.sh org.dataalgorithms.chap28.sparkwithlambda.SparkMeanMonoidized data/chap28/numbers.txt
  • Writes to output/ in the current directory; delete it first if it exists: rm -r output

Spark (Scala)

chap28.scala.MeanMonoidizedUsingCombineByKey

Source: MeanMonoidizedUsingCombineByKey.scala

scripts/run_spark.sh org.dataalgorithms.chap28.scala.MeanMonoidizedUsingCombineByKey data/chap28/numbers.txt /tmp/data-algorithms/chap28.scala.MeanMonoidizedUsingCombineByKey/output

chap28.scala.MeanMonoidizedUsingReduceByKey

Source: MeanMonoidizedUsingReduceByKey.scala

scripts/run_spark.sh org.dataalgorithms.chap28.scala.MeanMonoidizedUsingReduceByKey data/chap28/numbers.txt /tmp/data-algorithms/chap28.scala.MeanMonoidizedUsingReduceByKey/output

MapReduce (Hadoop)

chap28.mapreduce.MeanDriver

Source: MeanDriver.java

scripts/run_mapreduce.sh org.dataalgorithms.chap28.mapreduce.MeanDriver /tmp/data-algorithms/util.SequenceFileWriterDemo/numbers.seq /tmp/data-algorithms/chap28.mapreduce.MeanDriver/output
  • Run SequenceFileWriterDemo (on Utilities) first: it writes this program's input.