2016-03-25 11 views
-5

Dağıtık sistemler için kıvılcım öğreniyorum. Bu kodu çalıştırdım ve işe yaradı. ama ben girdi dosyalarındaki sayım kelimesi olduğunu biliyorum ama JavaRDD ait bizeKıvılcımla ilgili Begenner Büyük veri programlama (kıvılcım kodu)

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

Sorunuzu daha açık hale getirmeli ve ne yapmaya çalıştığınız hakkında daha fazla ayrıntı vermelisiniz, aksi halde öncelikle bir Spark kılavuzunu daha iyi okursunuz. Kaba olmak istemiyorum ama bu sitenin netiquette. – PinoSan

cevap

-1

PinoSan tarafından belirtildiği gibi nasıl Yöntemler yazılır ve hangi undestanding probleme sahip Bu soru muhtemelen çok geneldir ve cevabınızı Başlangıçta Başlarken veya Öğretici bölümünde bulabilmeniz gerekir.

bana bazı ilginç içeriğe işaret edelim:

Yasal Uyarı: Ben çevrimiçi koymak bu yüzden MapR için çalışıyorum Kaynak: MapR sitesinden Spark

İlgili konular