gpt4 book ai didi

scala - Flink : No operators defined in streaming topology.无法执行

转载 作者:行者123 更新时间:2023-12-02 11:17:06 31 4
gpt4 key购买 nike

我正在尝试设置一个非常基本的flink作业。当我尝试运行时,出现以下错误:

Caused by: java.lang.IllegalStateException: No operators defined in streaming topology. Cannot execute.
at org.apache.flink.streaming.api.environment.StreamExecutionEnvironment.getStreamGraph(StreamExecutionEnvironment.java:1535)
at org.apache.flink.streaming.api.environment.StreamContextEnvironment.execute(StreamContextEnvironment.java:53)
at org.apache.flink.streaming.api.scala.StreamExecutionEnvironment.execute(StreamExecutionEnvironment.scala:654)
at com.test.flink.jobs.TestJobRunnable$.run(TestJob.scala:223)

该错误是由以下代码引起的:
val streamExecutionEnvironment = StreamExecutionEnvironment.getExecutionEnvironment
val messageStream = streamExecutionEnvironment.addSource(kafkaConsumer)
messageStream.keyBy(_ => "S")

streamExecutionEnvironment.execute("Test Job")

当我在流的末尾添加 print()调用时,错误消失了:
val streamExecutionEnvironment = StreamExecutionEnvironment.getExecutionEnvironment
val messageStream = streamExecutionEnvironment.addSource(kafkaConsumer)
messageStream.keyBy(_ => "S")
messageStream.print()

streamExecutionEnvironment.execute("Test Job")

我对 print()为什么可以解决此问题感到困惑。在引入接收器之前,流拓扑不会处理其任何运算符的想法吗? print()在这里充当接收器吗?任何帮助,将不胜感激。谢谢。

最佳答案

在编程语言理论中,惰性求值或按需调用是一种评估策略,它可以延迟对表达式的求值,直到需要其值为止,并且还避免了重复求值。懒惰评估的反义词是急切评估,有时也称为严格评估。
惰性评估的好处包括:

  • 将控制流(结构)定义为抽象的能力
    而不是原始。
  • 定义潜在无限数据结构的能力。这个
    允许更直接地实现某些算法。
  • 通过避免不必要的计算并避免不必要的计算来提高性能
    计算复合表达式时的错误条件。

  • 延迟评估可以减少内存占用,因为在需要时会创建值。但是,由于操作顺序变得不确定,因此惰性评估很难与诸如异常处理和输入/输出之类的命令性功能结合使用。

    通常,Flink将操作分为两类: 转换操作和 接收操作。就像您猜到的那样,Flink转换是惰性的,这意味着直到调用接收器操作才执行它们。

    Flink programs are regular programs that implement transformations on distributed collections (e.g., filtering, mapping, updating state, joining, grouping, defining windows, aggregating). Collections are initially created from sources (e.g., by reading from files, Kafka topics, or from local, in-memory collections). Results are returned via sinks, which may, for example, write the data to (distributed) files, or to standard output (for example, the command line terminal).

    关于scala - Flink : No operators defined in streaming topology.无法执行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54977290/

    31 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com