Flink学习笔记(一):No new data sinks have been defined since the last execution.

问题描述:

初学flink,在IDEA中写离线批处理的wordcount后,运行报了以下异常:

Exception in thread "main" java.lang.RuntimeException: No new data sinks have been defined since the last execution. The last execution refers to the latest call to 'execute()', 'count()', 'collect()', or 'print()'.
    at org.apache.flink.api.java.ExecutionEnvironment.createProgramPlan(ExecutionEnvironment.java:944)
    at org.apache.flink.api.java.ExecutionEnvironment.createProgramPlan(ExecutionEnvironment.java:926)
    at org.apache.flink.api.java.LocalEnvironment.execute(LocalEnvironment.java:85)
    at org.apache.flink.api.java.ExecutionEnvironment.execute(ExecutionEnvironment.java:820)
    at org.apache.flink.api.scala.ExecutionEnvironment.execute(ExecutionEnvironment.scala:525)
    at com.yxf.wordcount.BatchWordCount$.main(BatchWordCount.scala:15)
    at com.yxf.wordcount.BatchWordCount.main(BatchWordCount.scala)

我的代码如下:

object BatchWordCount {

    def main(args: Array[String]): Unit = {
        val env: ExecutionEnvironment = ExecutionEnvironment.getExecutionEnvironment
        val line: DataSet[String] = env.readTextFile("input")
        val result: AggregateDataSet[(String, Int)] = line.flatMap(_.split(" ")).map((_, 1)).groupBy(0).sum(1)
        result.print()
        env.execute()
    }
}

 问题解决:

异常的原因就是说,自上次执行以来,没有定义新的数据接收器。对于离线批处理的算子,如:“count()”、“collect()”或“print()”等既有sink功能,还有触发的功能。我们上面调用了print()方法,会自动触发execute,所以最后面的一行执行器没有数据可以执行。

对于学过sparkstreaming后初学flink的小伙伴来说,这里要注意一下,有点小区别。

  • 6
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值