Hi Guys,

I'm not very good like java programmer, so anybody could me help with this
code piece from JavaNetworkWordcount:

JavaPairDStream<String, Integer> wordCounts = words.map(
        new PairFunction<String, String, Integer>() {
     @Override
          public Tuple2<String, Integer> call(String s) throws Exception {
            return new Tuple2<String, Integer>(s, 1);
          }
        }).reduceByKey(new Function2<Integer, Integer, Integer>() {
          @Override
          public Integer call(Integer i1, Integer i2) throws Exception {
            return i1 + i2;
          }
        });

      JavaPairDStream<String, Integer> counts =
wordCounts.reduceByKeyAndWindow(
        new Function2<Integer, Integer, Integer>() {
          public Integer call(Integer i1, Integer i2) { return i1 + i2; }
        },
        new Function2<Integer, Integer, Integer>() {
          public Integer call(Integer i1, Integer i2) { return i1 - i2; }
        },
        new Duration(60 * 5 * 1000),
        new Duration(1 * 1000)
      );

I would like to think a manner of counting and after summing  and getting a
total from words counted in a single file, for example a book in txt
extension Don Quixote. The counts function give me the resulted from each
word has found and not a total of words from the file.
Tathagata has sent me a piece from scala code, Thanks Tathagata by your
attention with my posts I am very thankfully,

  yourDStream.foreachRDD(rdd => {

   // Get and print first n elements
   val firstN = rdd.take(n)
   println("First N elements = " + firstN)

  // Count the number of elements in each batch
  println("RDD has " + rdd.count() + " elements")

})

yourDStream.count.print()

Could anybody help me?


Thanks Guys

-- 
INFORMATIVA SUL TRATTAMENTO DEI DATI PERSONALI

I dati utilizzati per l'invio del presente messaggio sono trattati 
dall'Università degli Studi di Brescia esclusivamente per finalità 
istituzionali. Informazioni più dettagliate anche in ordine ai diritti 
dell'interessato sono riposte nell'informativa generale e nelle notizie 
pubblicate sul sito web dell'Ateneo nella sezione "Privacy".

Il contenuto di questo messaggio è rivolto unicamente alle persona cui 
è indirizzato e può contenere informazioni la cui riservatezza è 
tutelata legalmente. Ne sono vietati la riproduzione, la diffusione e l'uso 
in mancanza di autorizzazione del destinatario. Qualora il messaggio 
fosse pervenuto per errore, preghiamo di eliminarlo.

Reply via email to