import org.apache.spark.SparkConf;
import org.apache.spark.api.java.JavaRDD;
import org.apache.spark.api.java.JavaSparkContext;

/**
 * Demonstrates the basics of accessing hadoop files from spark.
 * 
 * @author Peter Ansell p_ansell@yahoo.com
 */
public class SimpleHadoopApp {
	public static void main(String[] args) {
		String hadoopURL = "hdfs://localhost:9000";
		String hadoopFile = "/user/peter/input";
		SparkConf conf = new SparkConf().setAppName("Simple Application");
		try (JavaSparkContext sc = new JavaSparkContext(conf);) {
			JavaRDD<String> logData = sc.textFile(hadoopURL + hadoopFile).cache();
			long numAs = logData.filter(s -> s.contains("a")).count();
			long numBs = logData.filter(s -> s.contains("b")).count();
			System.out.println(
					"\n\n-------------------------------------\nLines with a: " + numAs + ", lines with b: " + numBs);
		}
	}
}

@@ -120,16 +120,62 @@
 Context;
+%0Aimport org.apache.spark.storage.StorageLevel;
 %0A%0A/**%0A *
@@ -904,16 +904,322 @@
 numBs);%0A
+%09%09%09JavaRDD%3CInteger%3E lineLengths = logData.map(s -%3E s.length()).persist(StorageLevel.MEMORY_ONLY());%0A%09%09%09int totalLength = lineLengths.reduce((a, b) -%3E a + b);%0A%09%09%09System.out.println(%22Total length: %22 + totalLength);%0A%09%09%09long lineCount = lineLengths.count();%0A%09%09%09System.out.println(%22Total lines: %22 + lineCount);%0A
 %09%09%7D%0A%09%7D%0A%7D

Add some more operations