Ste*_*app 5 apache-zeppelin apache-flink
我尝试在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()
Run Code Online (Sandbox Code Playgroud)
我尝试在笔记本中打印出结果.但不幸的是,我只得到以下输出.
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)
Run Code Online (Sandbox Code Playgroud)
如何在Zeppelin中将计数内容泄漏到笔记本中?
小智 5
在Zeppelin中打印此类计算结果的方法是:
%flink
counts.collect().foreach(println(_))
//or one might prefer
//counts.collect foreach println
Run Code Online (Sandbox Code Playgroud)
输出:
(a,3)
(all,1)
(and,1)
(armor,1)
...
Run Code Online (Sandbox Code Playgroud)
观察到的行为的原因在于 Apache Zeppelin 和 Apache Flink 之间的相互作用。Zeppelin 捕获Console. 然而,Flink 也会将输出打印到System.out,这正是您调用counts.print(). bzz 的解决方案之所以有效,是因为它使用 打印结果Console。
我打开了 JIRA 问题 [1] 并打开了拉取请求 [2] 来纠正此行为,以便您也可以使用counts.print().
| 归档时间: |
|
| 查看次数: |
803 次 |
| 最近记录: |