Proverbial Count

Proverbial count example

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
public class App
{
    public static void main( String[] args ) {
    // Local mode
    SparkConf sparkConf = new SparkConf().setAppName("HelloWorld").setMaster("local");
    JavaSparkContext ctx = new JavaSparkContext(sparkConf);
   
    JavaRDD<String> rdd = ctx.textFile("/home/Development/MarsWorkspace/third/resources/Forgiveness1.rtf");
    JavaRDD<String> words = rdd.flatMap(line -> Arrays.asList(line.split(" ")));
   
    JavaPairRDD<String, Integer> counts = words.mapToPair(w -> new Tuple2<String, Integer>(w, 1))
               .reduceByKey((x, y) -> x + y);
    counts.saveAsTextFile("/home/Development/MarsWorkspace/third/resources/out.txt");
    }
}

Leave a Reply

Your email address will not be published. Required fields are marked *