-5

i'm learning spark for distributed systemes. i runned this code and it's worked. but i know that it's count word in input files but i have probleme undestanding how Methods are written and what the us of JavaRDD

public class JavaWordCount {

public static void main(String[] args) throws Exception {

    System.out.print("le programme commence");
    //String inputFile = "/mapr/demo.mapr.com/TestMapr/Input/alice.txt";
    String inputFile = args[0];
    String outputFile = args[1];
    // Create a Java Spark Context.
    System.out.print("le programme cree un java spark contect");

    SparkConf conf = new SparkConf().setAppName("JavaWordCount");
    JavaSparkContext sc = new JavaSparkContext(conf);
    // Load our input data.
    System.out.print("Context créeS");

    JavaRDD<String> input = sc.textFile(inputFile);



    // map/split each line to multiple words

    System.out.print("le programme divise le document en multiple line");

    JavaRDD<String> words = input.flatMap(
            new FlatMapFunction<String, String>() {
                @Override
                public Iterable<String> call(String x) {
                    return Arrays.asList(x.split(" "));
                }
            }
    );
    System.out.print("Turn the words into (word, 1) pairse");

    // Turn the words into (word, 1) pairs
    JavaPairRDD<String, Integer> wordOnePairs = words.mapToPair(
            new PairFunction<String, String, Integer>() {
                @Override
                public Tuple2<String, Integer> call(String x) {
                    return new Tuple2(x, 1);
                }
            }
    );

    System.out.print("        // reduce add the pairs by key to produce counts");

    // reduce add the pairs by key to produce counts
    JavaPairRDD<String, Integer> counts = wordOnePairs.reduceByKey(
            new Function2<Integer, Integer, Integer>() {
                @Override
                public Integer call(Integer x, Integer y) {
                    return x + y;
                }
            }
    );


    System.out.print(" Save the word count back out to a text file, causing evaluation.");

    // Save the word count back out to a text file, causing evaluation.
    counts.saveAsTextFile(outputFile);
    System.out.println(counts.collect());
    sc.close();
}

}

Naoufal Abde
  • 21
  • 1
  • 2
  • You should make your question more specific and provide more details about what you are trying to do otherwise you better read a Spark manual first. I don't want to be rude but this is the netiquette of this website. – PinoSan Mar 27 '16 at 18:18

1 Answers1

-1

As mentioned by PinoSan this question is probably too generic, and you should be able to find your answer in any Spark Getting Started, or Tutorial.

Let me point you to some interesting content:

Disclaimer: I am working for MapR this is why I put online resources on Spark from MapR site

Tug Grall
  • 3,410
  • 1
  • 14
  • 16