2016-03-25 4 views
-5

ich lerne funken für verteilte systeme. Ich habe diesen Code ausgeführt und es hat funktioniert. , aber ich weiß, dass es Zählwort in Eingabedateien, aber ich habe Probleme undestanding wie Methoden geschrieben und was die uns von JavaRDDBegenner bei funken Große Datenprogrammierung (Funkencode)

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(); 
} 

}

+0

Sie sollten Ihre Frage genauer formulieren und weitere Einzelheiten darüber angeben, was Sie zu tun beabsichtigen. Andernfalls sollten Sie zuerst ein Spark-Handbuch lesen. Ich möchte nicht unhöflich sein, aber das ist die Netiquette dieser Website. – PinoSan

Antwort

-1

Wie bereits erwähnt von PinoSan Diese Frage ist wahrscheinlich zu allgemein gehalten und Sie sollten Ihre Antwort in jedem Spark-Lernprogramm oder Lernprogramm finden können.

Lassen Sie mich Ihnen einige interessante Inhalte verweisen:

Haftungsausschluss: Ich arbeite für MapR das ist, warum ich online gestellt Ressourcen auf Spark von MapR-Site