2016-03-25 12 views
-5

私は分散システムのためのスパークを学んでいます。私はこのコードを実行し、それは働いている。 PinoSanで述べたように、私は、それは入力ファイルの数語だということを知っているが、私はprobleme方法が書かれている方法undestanding、何JavaRDDBegenner at spark大規模なデータプログラミング(火花コード)

の私たち

パブリッククラス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

あなたの質問をより具体的にし、何をしようとしているかについての詳細を提供する必要があります。私は失礼ではありませんが、これはこのウェブサイトのネチケットです。 – PinoSan

答えて

-1

ていますこの質問はおそらくあまりにも一般的なので、Spark Getting Started、またはチュートリアルで回答を見つけることができます。

私はいくつかの興味深いコンテンツにあなたを指してみましょう:

免責事項:私はオンライン置く理由ですMAPRのために働いていますMapRサイトのSparkのリソース

関連する問題