Something like maybe. From this example -
https://github.com/tdas/incubator-spark/blob/recoverable-example-fix/examples/src/main/java/org/apache/spark/streaming/examples/JavaRecoverableWordCount.java


      wordCounts.foreachRDD(new Function2<JavaPairRDD<String,
Integer>, Time, Void>() {

        @Override public Void call(JavaPairRDD<String, Integer>
pairRDD, Time time) throws Exception {

          String counts = "Counts at time " + time + " [" +
Joiner.on(", ").join(pairRDD.collect())  + "]";

          System.out.println(counts);

          System.out.println("Appending to " + outputFile.getAbsolutePath());

          Files.append(counts + "\n", outputFile, Charset.defaultCharset());

          return null;

        }
      });

Note that Joiner is a class from Google Commons library. Not integral
to what you want to do.


TD


2014/1/28 Eduardo Costa Alfaia <e.costaalf...@unibs.it>

> Hi Tathagata, doesn't worry I am looking for a manner in the source code of
> JavaNetworkWordcount print me in console the sum of the total of words in a
> file, not one word by line.
>
> Thanks
>
>
> Il giorno 28 gennaio 2014 22:36, Tathagata Das
> <tathagata.das1...@gmail.com>ha scritto:
>
> > Yes, it was my intention to write scala code. But I may have failed to
> > write a correct one that compiles. Apologies.
> >
> > Also, something to keep in mind. This is the dev mailing for Spark
> > developers. Questions related to using Spark should be sent to
> > u...@spark.incubator.apache.org
> >
> > TD
> >
> >
> >
> > 2014/1/28 Eduardo Costa Alfaia <e.costaalf...@unibs.it>
> >
> > > Hi Tathagata,
> > >
> > > This code that you have sent me is it a scala code?
> > >
> > > 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")
> > >
> > > })
> > >
> > > Thanks
> > >
> > >
> > >
> > > Il giorno 20 gennaio 2014 19:11, Tathagata Das
> > > <tathagata.das1...@gmail.com>ha scritto:
> > >
> > > > Hi Eduardo,
> > > >
> > > > You can do arbitrary stuff with the data in a DStream using the
> > operation
> > > > foreachRDD.
> > > >
> > > > 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")
> > > >
> > > > })
> > > >
> > > >
> > > > Alternatively, just for printing the counts, you can also do
> > > >
> > > > yourDStream.count.print()
> > > >
> > > > Hope this helps!
> > > >
> > > > TD
> > > >
> > > >
> > > >
> > > > 2014/1/20 Eduardo Costa Alfaia <e.costaalf...@studenti.unibs.it>
> > > >
> > > > > Hi guys,
> > > > >
> > > > > Somebody help me, Where do I get change the print() function to
> print
> > > > more
> > > > > than 10 lines in screen? Is there a manner to print the count total
> > of
> > > > all
> > > > > words in a batch?
> > > > >
> > > > > Best Regards
> > > > > --
> > > > > ---
> > > > > 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.
> > > > >
> > > >
> > >
> > > --
> > > ---
> > > 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.
> > >
> >
>
> --
> ---
> 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