Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to write the content of a Flink var to screen in Zeppelin?

I try to run the followin simple commands in Apache Zeppelin.

%flink

var rabbit = env.fromElements(
"ARTHUR:  What, behind the rabbit?",
"TIM:  It is the rabbit!", 
"ARTHUR:  You silly sod!  You got us all worked up!",
"TIM:  Well, that's no ordinary rabbit.  That's the most foul, cruel, and bad-tempered rodent you ever set eyes on.",
"ROBIN:  You tit!  I soiled my armor I was so scared!", 
"TIM:  Look, that rabbit's got a vicious streak a mile wide, it's a killer!")

var counts = rabbit.flatMap { _.toLowerCase.split("\\W+")}.map{ (_,1)}.groupBy(0).sum(1) 

counts.print()

I try to print out the results in the notebook. But unfortunately, I only get the following output.

rabbit: org.apache.flink.api.scala.DataSet[String] = org.apache.flink.api.scala.DataSet@37fdb65c
counts: org.apache.flink.api.scala.AggregateDataSet[(String, Int)] = org.apache.flink.api.scala.AggregateDataSet@1efc7158
res103: org.apache.flink.api.java.operators.DataSink[(String, Int)] = DataSink '<unnamed>' (Print to System.out)

How can I spill the content of counts to the notebook in Zeppelin?

like image 916
Stefan Papp Avatar asked Sep 04 '15 15:09

Stefan Papp


1 Answers

The way to print the result of such computation in Zeppelin is:

%flink
counts.collect().foreach(println(_))

//or one might prefer
//counts.collect foreach println 

Output:

(a,3)
(all,1)
(and,1)
(armor,1)
...
like image 68
bzz Avatar answered Sep 23 '22 07:09

bzz